|
| 1 | +jest.mock('path'); |
| 2 | +const path = require('path'); |
1 | 3 | const { getActionMetadataFromDirname, getRunMetadata } = require('../utils');
|
2 | 4 |
|
3 |
| -describe('GetActionMetadataFromDirname Tests', () => { |
| 5 | +describe('GetActionMetadataFromDirname Tests Ubuntu', () => { |
4 | 6 | test('it can get the right info from a action with a version', () => {
|
| 7 | + process.env.RUNNER_OS = 'Linux'; |
| 8 | + path.sep = '/'; |
| 9 | + |
5 | 10 | const dirname = `/home/runner/work/_actions/michmich112/version-bumper/v1.0.0/node_modules/gh-action-stats`;
|
6 | 11 | const actionMetadata = getActionMetadataFromDirname(dirname);
|
7 | 12 | expect(actionMetadata).toEqual({
|
@@ -42,6 +47,94 @@ describe('GetActionMetadataFromDirname Tests', () => {
|
42 | 47 | });
|
43 | 48 | });
|
44 | 49 |
|
| 50 | +describe('GetActionMetadataFromDirname Tests MacOs', () => { |
| 51 | + test('it can get the right info from a action with a version', () => { |
| 52 | + process.env.RUNNER_OS = 'macOS'; |
| 53 | + path.sep = '/'; |
| 54 | + const dirname = `/Users/runner/work/_actions/michmich112/version-bumper/v1.0.0/node_modules/gh-action-stats`; |
| 55 | + const actionMetadata = getActionMetadataFromDirname(dirname); |
| 56 | + expect(actionMetadata).toEqual({ |
| 57 | + creator: 'michmich112', |
| 58 | + name: 'version-bumper', |
| 59 | + version: 'v1.0.0' |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + test('it can get the right info from an action with a commit hash', () => { |
| 64 | + const dirname = `/Users/runner/work/_actions/michmich112/version-bumper/8fc6e82c93abcdaae3fbb8239d101efc6b63b606/node_modules/gh-action-stats` |
| 65 | + const actionMetadata = getActionMetadataFromDirname(dirname); |
| 66 | + expect(actionMetadata).toEqual({ |
| 67 | + creator: 'michmich112', |
| 68 | + name: 'version-bumper', |
| 69 | + version: '8fc6e82c93abcdaae3fbb8239d101efc6b63b606' |
| 70 | + }); |
| 71 | + }); |
| 72 | + |
| 73 | + test('it can get the right info from an action with a branch', () => { |
| 74 | + const dirname = `/Users/runner/work/_actions/michmich112/version-bumper/master/node_modules/gh-action-stats` |
| 75 | + const actionMetadata = getActionMetadataFromDirname(dirname); |
| 76 | + expect(actionMetadata).toEqual({ |
| 77 | + creator: 'michmich112', |
| 78 | + name: 'version-bumper', |
| 79 | + version: 'master' |
| 80 | + }); |
| 81 | + }); |
| 82 | + |
| 83 | + test('it can get the righ info from an action with a branch with the / character', () => { |
| 84 | + const dirname = `/Users/runner/work/_actions/michmich112/version-bumper/fix/bug-fix-important/node_modules/gh-action-stats` |
| 85 | + const actionMetadata = getActionMetadataFromDirname(dirname); |
| 86 | + expect(actionMetadata).toEqual({ |
| 87 | + creator: 'michmich112', |
| 88 | + name: 'version-bumper', |
| 89 | + version: 'fix/bug-fix-important' |
| 90 | + }); |
| 91 | + }); |
| 92 | +}); |
| 93 | + |
| 94 | +describe('GetActionMetadataFromDirname Tests Windows', () => { |
| 95 | + test('it can get the right info from a action with a version', () => { |
| 96 | + process.env.RUNNER_OS = 'Windows'; |
| 97 | + path.sep = '\\'; |
| 98 | + const dirname = `D:\\a\\_actions\\michmich112\\version-bumper\\v1.0.0\\node_modules\\gh-action-stats`; |
| 99 | + const actionMetadata = getActionMetadataFromDirname(dirname); |
| 100 | + expect(actionMetadata).toEqual({ |
| 101 | + creator: 'michmich112', |
| 102 | + name: 'version-bumper', |
| 103 | + version: 'v1.0.0' |
| 104 | + }); |
| 105 | + }); |
| 106 | + |
| 107 | + test('it can get the right info from an action with a commit hash', () => { |
| 108 | + const dirname = `D:\\a\\_actions\\michmich112\\version-bumper\\8fc6e82c93abcdaae3fbb8239d101efc6b63b606\\node_modules\\gh-action-stats` |
| 109 | + const actionMetadata = getActionMetadataFromDirname(dirname); |
| 110 | + expect(actionMetadata).toEqual({ |
| 111 | + creator: 'michmich112', |
| 112 | + name: 'version-bumper', |
| 113 | + version: '8fc6e82c93abcdaae3fbb8239d101efc6b63b606' |
| 114 | + }); |
| 115 | + }); |
| 116 | + |
| 117 | + test('it can get the right info from an action with a branch', () => { |
| 118 | + const dirname = `D:\\a\\_actions\\michmich112\\version-bumper\\master\\node_modules\\gh-action-stats` |
| 119 | + const actionMetadata = getActionMetadataFromDirname(dirname); |
| 120 | + expect(actionMetadata).toEqual({ |
| 121 | + creator: 'michmich112', |
| 122 | + name: 'version-bumper', |
| 123 | + version: 'master' |
| 124 | + }); |
| 125 | + }); |
| 126 | + |
| 127 | + test('it can get the righ info from an action with a branch with the / character', () => { |
| 128 | + const dirname = `D:\\a\\_actions\\michmich112\\version-bumper\\fix\\bug-fix-important\\node_modules\\gh-action-stats` |
| 129 | + const actionMetadata = getActionMetadataFromDirname(dirname); |
| 130 | + expect(actionMetadata).toEqual({ |
| 131 | + creator: 'michmich112', |
| 132 | + name: 'version-bumper', |
| 133 | + version: 'fix/bug-fix-important' |
| 134 | + }); |
| 135 | + }); |
| 136 | +}); |
| 137 | + |
45 | 138 | describe('GetRunMetadata Tests', () => {
|
46 | 139 | const envVars = {
|
47 | 140 | 'GITHUB_RUN_ID': 'id',
|
|
0 commit comments