@knapsack-pro/jest 7.4.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/env-config.js +16 -31
- package/lib/jest-cli.js +6 -9
- package/lib/knapsack-pro-jest.js +40 -93
- package/lib/test-files-finder.js +39 -21
- package/package.json +19 -27
package/lib/env-config.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EnvConfig = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
EnvConfig.loadEnvironmentVariables = function () {
|
|
4
|
+
class EnvConfig {
|
|
5
|
+
static loadEnvironmentVariables() {
|
|
8
6
|
if (process.env.KNAPSACK_PRO_TEST_SUITE_TOKEN_JEST) {
|
|
9
7
|
process.env.KNAPSACK_PRO_TEST_SUITE_TOKEN =
|
|
10
8
|
process.env.KNAPSACK_PRO_TEST_SUITE_TOKEN_JEST;
|
|
@@ -12,31 +10,18 @@ var EnvConfig = (function () {
|
|
|
12
10
|
if (process.env.NODE_ENV == null) {
|
|
13
11
|
process.env.NODE_ENV = 'test';
|
|
14
12
|
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
enumerable: false,
|
|
31
|
-
configurable: true
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(EnvConfig, "coverageDirectory", {
|
|
34
|
-
get: function () {
|
|
35
|
-
return process.env.KNAPSACK_PRO_COVERAGE_DIRECTORY;
|
|
36
|
-
},
|
|
37
|
-
enumerable: false,
|
|
38
|
-
configurable: true
|
|
39
|
-
});
|
|
40
|
-
return EnvConfig;
|
|
41
|
-
}());
|
|
13
|
+
}
|
|
14
|
+
static get testFilePattern() {
|
|
15
|
+
if (process.env.KNAPSACK_PRO_TEST_FILE_PATTERN) {
|
|
16
|
+
return process.env.KNAPSACK_PRO_TEST_FILE_PATTERN;
|
|
17
|
+
}
|
|
18
|
+
return '{**/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x)}';
|
|
19
|
+
}
|
|
20
|
+
static get testFileExcludePattern() {
|
|
21
|
+
return process.env.KNAPSACK_PRO_TEST_FILE_EXCLUDE_PATTERN;
|
|
22
|
+
}
|
|
23
|
+
static get coverageDirectory() {
|
|
24
|
+
return process.env.KNAPSACK_PRO_COVERAGE_DIRECTORY;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
42
27
|
exports.EnvConfig = EnvConfig;
|
package/lib/jest-cli.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JestCLI = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
JestCLI.argvToOptions = function () {
|
|
9
|
-
var argv = process.argv.slice(2);
|
|
4
|
+
const minimist = require('minimist');
|
|
5
|
+
class JestCLI {
|
|
6
|
+
static argvToOptions() {
|
|
7
|
+
const argv = process.argv.slice(2);
|
|
10
8
|
return minimist(argv);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
}());
|
|
9
|
+
}
|
|
10
|
+
}
|
|
14
11
|
exports.JestCLI = JestCLI;
|
package/lib/knapsack-pro-jest.js
CHANGED
|
@@ -1,99 +1,46 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var __assign = (this && this.__assign) || function () {
|
|
4
|
-
__assign = Object.assign || function(t) {
|
|
5
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
-
s = arguments[i];
|
|
7
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
8
|
-
t[p] = s[p];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
return __assign.apply(this, arguments);
|
|
13
|
-
};
|
|
14
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
24
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
25
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
26
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
27
|
-
function step(op) {
|
|
28
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
29
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
30
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
31
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
32
|
-
switch (op[0]) {
|
|
33
|
-
case 0: case 1: t = op; break;
|
|
34
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
35
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
36
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
37
|
-
default:
|
|
38
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
39
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
40
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
41
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
42
|
-
if (t[2]) _.ops.pop();
|
|
43
|
-
_.trys.pop(); continue;
|
|
44
|
-
}
|
|
45
|
-
op = body.call(thisArg, _);
|
|
46
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
47
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
knapsackProLogger.debug(
|
|
4
|
+
const core_1 = require("@knapsack-pro/core");
|
|
5
|
+
const env_config_1 = require("./env-config");
|
|
6
|
+
const test_files_finder_1 = require("./test-files-finder");
|
|
7
|
+
const jest_cli_1 = require("./jest-cli");
|
|
8
|
+
const jest = require('jest');
|
|
9
|
+
const { v4: uuidv4 } = require('uuid');
|
|
10
|
+
const { name: clientName, version: clientVersion } = require('../package.json');
|
|
11
|
+
const jestCLIOptions = jest_cli_1.JestCLI.argvToOptions();
|
|
12
|
+
const knapsackProLogger = new core_1.KnapsackProLogger();
|
|
13
|
+
knapsackProLogger.debug(`Jest CLI options:\n${core_1.KnapsackProLogger.objectInspect(jestCLIOptions)}`);
|
|
61
14
|
env_config_1.EnvConfig.loadEnvironmentVariables();
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
path: path,
|
|
88
|
-
time_execution: timeExecution,
|
|
89
|
-
};
|
|
90
|
-
});
|
|
91
|
-
return [2, {
|
|
92
|
-
recordedTestFiles: recordedTestFiles,
|
|
93
|
-
isTestSuiteGreen: isTestSuiteGreen,
|
|
94
|
-
}];
|
|
95
|
-
}
|
|
15
|
+
const projectPath = process.cwd();
|
|
16
|
+
const testFilesToExecute = () => test_files_finder_1.TestFilesFinder.allTestFiles();
|
|
17
|
+
const knapsackPro = new core_1.KnapsackProCore(clientName, clientVersion, testFilesToExecute);
|
|
18
|
+
const onSuccess = async (queueTestFiles) => {
|
|
19
|
+
const testFilePaths = queueTestFiles.map((testFile) => testFile.path);
|
|
20
|
+
const jestCLICoverage = env_config_1.EnvConfig.coverageDirectory
|
|
21
|
+
? { coverageDirectory: `${env_config_1.EnvConfig.coverageDirectory}/${uuidv4()}` }
|
|
22
|
+
: {};
|
|
23
|
+
const { results: { success: isTestSuiteGreen, testResults }, } = await jest.runCLI({
|
|
24
|
+
...jestCLIOptions,
|
|
25
|
+
...jestCLICoverage,
|
|
26
|
+
runTestsByPath: true,
|
|
27
|
+
_: testFilePaths,
|
|
28
|
+
}, [projectPath]);
|
|
29
|
+
const recordedTestFiles = testResults.map(({ testFilePath, perfStats: { start, end }, }) => {
|
|
30
|
+
const path = process.platform === 'win32'
|
|
31
|
+
? testFilePath.replace(`${projectPath}\\`, '').replace(/\\/g, '/')
|
|
32
|
+
: testFilePath.replace(`${projectPath}/`, '');
|
|
33
|
+
const timeExecutionMiliseconds = end - start;
|
|
34
|
+
const timeExecution = timeExecutionMiliseconds > 0 ? timeExecutionMiliseconds / 1000 : 0.0;
|
|
35
|
+
return {
|
|
36
|
+
path,
|
|
37
|
+
time_execution: timeExecution,
|
|
38
|
+
};
|
|
96
39
|
});
|
|
97
|
-
|
|
98
|
-
|
|
40
|
+
return {
|
|
41
|
+
recordedTestFiles,
|
|
42
|
+
isTestSuiteGreen,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
const onError = (error) => { };
|
|
99
46
|
knapsackPro.runQueueMode(onSuccess, onError);
|
package/lib/test-files-finder.js
CHANGED
|
@@ -1,37 +1,55 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.TestFilesFinder = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
TestFilesFinder.allTestFiles = function () {
|
|
13
|
-
var testFiles = glob
|
|
27
|
+
const glob_1 = require("glob");
|
|
28
|
+
const minimatch_1 = require("minimatch");
|
|
29
|
+
const core_1 = require("@knapsack-pro/core");
|
|
30
|
+
const env_config_1 = require("./env-config");
|
|
31
|
+
const Urls = __importStar(require("./urls"));
|
|
32
|
+
class TestFilesFinder {
|
|
33
|
+
static allTestFiles() {
|
|
34
|
+
const testFiles = glob_1.glob
|
|
14
35
|
.sync(env_config_1.EnvConfig.testFilePattern)
|
|
15
|
-
.filter(
|
|
36
|
+
.filter((testFilePath) => {
|
|
16
37
|
if (env_config_1.EnvConfig.testFileExcludePattern) {
|
|
17
|
-
return !minimatch(testFilePath, env_config_1.EnvConfig.testFileExcludePattern, {
|
|
38
|
+
return !(0, minimatch_1.minimatch)(testFilePath, env_config_1.EnvConfig.testFileExcludePattern, {
|
|
18
39
|
matchBase: true,
|
|
19
40
|
});
|
|
20
41
|
}
|
|
21
42
|
return true;
|
|
22
43
|
})
|
|
23
|
-
.filter(
|
|
24
|
-
|
|
25
|
-
})
|
|
26
|
-
.map(function (testFilePath) { return ({ path: testFilePath }); });
|
|
44
|
+
.filter((testFilePath) => !testFilePath.match(/node_modules/))
|
|
45
|
+
.map((testFilePath) => ({ path: testFilePath }));
|
|
27
46
|
if (testFiles.length === 0) {
|
|
28
|
-
|
|
29
|
-
|
|
47
|
+
const knapsackProLogger = new core_1.KnapsackProLogger();
|
|
48
|
+
const errorMessage = `Test files cannot be found.\nPlease set KNAPSACK_PRO_TEST_FILE_PATTERN matching your test directory structure.\nLearn more: ${Urls.NO_TESTS_FOUND}`;
|
|
30
49
|
knapsackProLogger.error(errorMessage);
|
|
31
50
|
throw errorMessage;
|
|
32
51
|
}
|
|
33
52
|
return testFiles;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
}());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
37
55
|
exports.TestFilesFinder = TestFilesFinder;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knapsack-pro/jest",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Knapsack Pro Jest splits Jest tests across CI nodes and makes sure that tests will run in optimal time on each CI node.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"knapsack",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
],
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"scripts": {
|
|
32
|
-
"start": "
|
|
33
|
-
"build": "
|
|
32
|
+
"start": "nodemon --ext ts --watch src/ --exec \"npm run build\"",
|
|
33
|
+
"build": "rm -rf lib && tsc && chmod u+w lib/knapsack-pro-jest.js",
|
|
34
34
|
"lint": "npm run eslint:check && npm run prettier:check",
|
|
35
35
|
"eslint:check": "eslint . --ext .ts",
|
|
36
36
|
"eslint:format": "eslint . --ext .ts --fix",
|
|
@@ -53,36 +53,28 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@knapsack-pro/core": "^6.4.0",
|
|
56
|
-
"glob": "^
|
|
57
|
-
"minimatch": "^
|
|
56
|
+
"glob": "^10.3.4",
|
|
57
|
+
"minimatch": "^9.0.3",
|
|
58
58
|
"minimist": "^1.2.6",
|
|
59
|
-
"uuid": "^9.0.
|
|
59
|
+
"uuid": "^9.0.1"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"jest": ">=22.0.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@
|
|
66
|
-
"@
|
|
67
|
-
"@
|
|
68
|
-
"@
|
|
69
|
-
"
|
|
70
|
-
"@types/node": "^20.3.1",
|
|
71
|
-
"@typescript-eslint/eslint-plugin": "^5.27.1",
|
|
72
|
-
"@typescript-eslint/parser": "^5.27.1",
|
|
73
|
-
"del": "^6.1.1",
|
|
74
|
-
"eslint": "^7.32.0",
|
|
65
|
+
"@types/jest": "^29.5.5",
|
|
66
|
+
"@types/node": "^20.6.2",
|
|
67
|
+
"@typescript-eslint/eslint-plugin": "^6.7.2",
|
|
68
|
+
"@typescript-eslint/parser": "^6.7.2",
|
|
69
|
+
"eslint": "^8.49.0",
|
|
75
70
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
76
|
-
"eslint-config-prettier": "^
|
|
77
|
-
"eslint-plugin-import": "^2.
|
|
78
|
-
"eslint-plugin-prettier": "^
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"prettier": "^2.6.2",
|
|
85
|
-
"ts-jest": "^29.0.5",
|
|
86
|
-
"typescript": "^4.7.3"
|
|
71
|
+
"eslint-config-prettier": "^9.0.0",
|
|
72
|
+
"eslint-plugin-import": "^2.28.1",
|
|
73
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
74
|
+
"jest": "^29.7.0",
|
|
75
|
+
"nodemon": "^3.0.1",
|
|
76
|
+
"prettier": "^3.0.3",
|
|
77
|
+
"ts-jest": "^29.1.1",
|
|
78
|
+
"typescript": "^5.2.2"
|
|
87
79
|
}
|
|
88
80
|
}
|