@knapsack-pro/jest 8.1.0 → 9.0.0-rc.1
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 +1 -5
- package/lib/jest-cli.js +2 -6
- package/lib/knapsack-pro-jest.js +19 -18
- package/lib/test-files-finder.js +11 -38
- package/lib/urls.js +1 -4
- package/package.json +26 -22
package/lib/env-config.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EnvConfig = void 0;
|
|
4
|
-
class EnvConfig {
|
|
1
|
+
export class EnvConfig {
|
|
5
2
|
static loadEnvironmentVariables() {
|
|
6
3
|
if (process.env.KNAPSACK_PRO_TEST_SUITE_TOKEN_JEST) {
|
|
7
4
|
process.env.KNAPSACK_PRO_TEST_SUITE_TOKEN =
|
|
@@ -24,4 +21,3 @@ class EnvConfig {
|
|
|
24
21
|
return process.env.KNAPSACK_PRO_COVERAGE_DIRECTORY;
|
|
25
22
|
}
|
|
26
23
|
}
|
|
27
|
-
exports.EnvConfig = EnvConfig;
|
package/lib/jest-cli.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.JestCLI = void 0;
|
|
4
|
-
const minimist = require('minimist');
|
|
5
|
-
class JestCLI {
|
|
1
|
+
import minimist from 'minimist';
|
|
2
|
+
export class JestCLI {
|
|
6
3
|
static argvToOptions() {
|
|
7
4
|
const argv = process.argv.slice(2);
|
|
8
5
|
return minimist(argv);
|
|
9
6
|
}
|
|
10
7
|
}
|
|
11
|
-
exports.JestCLI = JestCLI;
|
package/lib/knapsack-pro-jest.js
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const jest =
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const jestCLIOptions =
|
|
12
|
-
const knapsackProLogger = new
|
|
13
|
-
knapsackProLogger.debug(`Jest CLI options:\n${
|
|
14
|
-
|
|
2
|
+
import { KnapsackProCore, KnapsackProLogger, } from '@knapsack-pro/core';
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
import { EnvConfig } from './env-config.js';
|
|
5
|
+
import { TestFilesFinder } from './test-files-finder.js';
|
|
6
|
+
import { JestCLI } from './jest-cli.js';
|
|
7
|
+
const jestImport = await import('jest');
|
|
8
|
+
const jest = jestImport.default ?? jestImport;
|
|
9
|
+
const clientName = '@knapsack-pro/jest';
|
|
10
|
+
const clientVersion = '9.0.0-rc.1';
|
|
11
|
+
const jestCLIOptions = JestCLI.argvToOptions();
|
|
12
|
+
const knapsackProLogger = new KnapsackProLogger();
|
|
13
|
+
knapsackProLogger.debug(`Jest CLI options:\n${KnapsackProLogger.objectInspect(jestCLIOptions)}`);
|
|
14
|
+
EnvConfig.loadEnvironmentVariables();
|
|
15
15
|
const projectPath = process.cwd();
|
|
16
|
-
const testFilesToExecute = () =>
|
|
17
|
-
const knapsackPro = new
|
|
16
|
+
const testFilesToExecute = () => TestFilesFinder.allTestFiles();
|
|
17
|
+
const knapsackPro = new KnapsackProCore(clientName, clientVersion, testFilesToExecute);
|
|
18
18
|
const onSuccess = async (queueTestFiles) => {
|
|
19
19
|
const testFilePaths = queueTestFiles.map((testFile) => testFile.path);
|
|
20
|
-
const jestCLICoverage =
|
|
21
|
-
? { coverageDirectory: `${
|
|
20
|
+
const jestCLICoverage = EnvConfig.coverageDirectory
|
|
21
|
+
? { coverageDirectory: `${EnvConfig.coverageDirectory}/${uuidv4()}` }
|
|
22
22
|
: {};
|
|
23
23
|
const { results: { success: isTestSuiteGreen, testResults }, } = await jest.runCLI({
|
|
24
24
|
...jestCLIOptions,
|
|
25
25
|
...jestCLICoverage,
|
|
26
26
|
runTestsByPath: true,
|
|
27
27
|
_: testFilePaths,
|
|
28
|
+
$0: 'jest',
|
|
28
29
|
}, [projectPath]);
|
|
29
30
|
const recordedTestFiles = testResults.map(({ testFilePath, perfStats: { start, end }, }) => {
|
|
30
31
|
const path = process.platform === 'win32'
|
|
@@ -42,5 +43,5 @@ const onSuccess = async (queueTestFiles) => {
|
|
|
42
43
|
isTestSuiteGreen,
|
|
43
44
|
};
|
|
44
45
|
};
|
|
45
|
-
const onError = (
|
|
46
|
+
const onError = () => { };
|
|
46
47
|
knapsackPro.runQueueMode(onSuccess, onError);
|
package/lib/test-files-finder.js
CHANGED
|
@@ -1,41 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.TestFilesFinder = void 0;
|
|
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 {
|
|
1
|
+
import { glob } from 'glob';
|
|
2
|
+
import { minimatch } from 'minimatch';
|
|
3
|
+
import { KnapsackProLogger } from '@knapsack-pro/core';
|
|
4
|
+
import { EnvConfig } from './env-config.js';
|
|
5
|
+
import * as Urls from './urls.js';
|
|
6
|
+
export class TestFilesFinder {
|
|
33
7
|
static allTestFiles() {
|
|
34
|
-
const testFiles =
|
|
35
|
-
.sync(
|
|
8
|
+
const testFiles = glob
|
|
9
|
+
.sync(EnvConfig.testFilePattern)
|
|
36
10
|
.filter((testFilePath) => {
|
|
37
|
-
if (
|
|
38
|
-
return !
|
|
11
|
+
if (EnvConfig.testFileExcludePattern) {
|
|
12
|
+
return !minimatch(testFilePath, EnvConfig.testFileExcludePattern, {
|
|
39
13
|
matchBase: true,
|
|
40
14
|
});
|
|
41
15
|
}
|
|
@@ -44,7 +18,7 @@ class TestFilesFinder {
|
|
|
44
18
|
.filter((testFilePath) => !testFilePath.match(/node_modules/))
|
|
45
19
|
.map((testFilePath) => ({ path: testFilePath }));
|
|
46
20
|
if (testFiles.length === 0) {
|
|
47
|
-
const knapsackProLogger = new
|
|
21
|
+
const knapsackProLogger = new KnapsackProLogger();
|
|
48
22
|
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}`;
|
|
49
23
|
knapsackProLogger.error(errorMessage);
|
|
50
24
|
throw errorMessage;
|
|
@@ -52,4 +26,3 @@ class TestFilesFinder {
|
|
|
52
26
|
return testFiles;
|
|
53
27
|
}
|
|
54
28
|
}
|
|
55
|
-
exports.TestFilesFinder = TestFilesFinder;
|
package/lib/urls.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NO_TESTS_FOUND = void 0;
|
|
4
|
-
exports.NO_TESTS_FOUND = 'https://knapsackpro.com/perma/jest/no-tests-found';
|
|
1
|
+
export const NO_TESTS_FOUND = 'https://knapsackpro.com/perma/jest/no-tests-found';
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knapsack-pro/jest",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-rc.1",
|
|
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
|
+
"type": "module",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"knapsack",
|
|
7
8
|
"knapsack pro",
|
|
@@ -32,8 +33,8 @@
|
|
|
32
33
|
"start": "nodemon --ext ts --watch src/ --exec \"npm run build\"",
|
|
33
34
|
"build": "rm -rf lib && tsc && chmod u+x lib/knapsack-pro-jest.js",
|
|
34
35
|
"lint": "npm run eslint:check && npm run prettier:check",
|
|
35
|
-
"eslint:check": "eslint
|
|
36
|
-
"eslint:format": "eslint
|
|
36
|
+
"eslint:check": "eslint src/**/*.ts",
|
|
37
|
+
"eslint:format": "eslint src/**/*.ts --fix",
|
|
37
38
|
"prettier:check": "prettier --config .prettierrc.json --check .",
|
|
38
39
|
"prettier:format": "prettier --config .prettierrc.json --write ."
|
|
39
40
|
},
|
|
@@ -52,29 +53,32 @@
|
|
|
52
53
|
"knapsack-pro-jest": "lib/knapsack-pro-jest.js"
|
|
53
54
|
},
|
|
54
55
|
"dependencies": {
|
|
55
|
-
"@knapsack-pro/core": "^
|
|
56
|
-
"glob": "^
|
|
57
|
-
"minimatch": "^
|
|
58
|
-
"minimist": "^1.2.
|
|
59
|
-
"uuid": "^
|
|
56
|
+
"@knapsack-pro/core": "^9.0.0-rc.1",
|
|
57
|
+
"glob": "^11.0.3",
|
|
58
|
+
"minimatch": "^10.0.3",
|
|
59
|
+
"minimist": "^1.2.8",
|
|
60
|
+
"uuid": "^13.0.0"
|
|
60
61
|
},
|
|
61
62
|
"peerDependencies": {
|
|
62
|
-
"jest": ">=
|
|
63
|
+
"jest": ">=23.0.0"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
|
-
"@
|
|
66
|
-
"@
|
|
67
|
-
"@
|
|
68
|
-
"@
|
|
69
|
-
"eslint": "^8.
|
|
66
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
67
|
+
"@eslint/js": "^9.35.0",
|
|
68
|
+
"@types/jest": "^30.0.0",
|
|
69
|
+
"@types/node": "^24.5.1",
|
|
70
|
+
"@typescript-eslint/eslint-plugin": "^8.44.0",
|
|
71
|
+
"@typescript-eslint/parser": "^8.44.0",
|
|
72
|
+
"eslint": "^9.35.0",
|
|
70
73
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
71
|
-
"eslint-config-prettier": "^
|
|
72
|
-
"eslint-plugin-import": "^2.
|
|
73
|
-
"eslint-plugin-
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
74
|
+
"eslint-config-prettier": "^10.1.8",
|
|
75
|
+
"eslint-plugin-import": "^2.32.0",
|
|
76
|
+
"eslint-plugin-jest": "^29.0.1",
|
|
77
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
78
|
+
"jest": "^30.1.3",
|
|
79
|
+
"nodemon": "^3.1.10",
|
|
80
|
+
"prettier": "^3.6.2",
|
|
81
|
+
"ts-jest": "^29.4.2",
|
|
82
|
+
"typescript": "^5.9.2"
|
|
79
83
|
}
|
|
80
84
|
}
|