@knapsack-pro/jest 9.0.0 → 10.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/knapsack-pro-jest.js
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
import pkg from '@knapsack-pro/jest/package.json' with { type: 'json' };
|
|
3
3
|
import { KnapsackProCore, KnapsackProLogger, } from '@knapsack-pro/core';
|
|
4
4
|
import { v4 as uuidv4 } from 'uuid';
|
|
5
|
+
import { relative } from 'path';
|
|
5
6
|
import { EnvConfig } from './env-config.js';
|
|
6
|
-
import {
|
|
7
|
+
import { PathsFinder } from './paths-finder.js';
|
|
7
8
|
import { JestCLI } from './jest-cli.js';
|
|
9
|
+
import { normalizePaths } from './utils.js';
|
|
8
10
|
const jestImport = await import('jest');
|
|
9
11
|
const jest = jestImport.default ?? jestImport;
|
|
10
12
|
const jestCLIOptions = JestCLI.argvToOptions();
|
|
@@ -12,34 +14,34 @@ const knapsackProLogger = new KnapsackProLogger();
|
|
|
12
14
|
knapsackProLogger.debug(`Jest CLI options:\n${KnapsackProLogger.objectInspect(jestCLIOptions)}`);
|
|
13
15
|
EnvConfig.loadEnvironmentVariables();
|
|
14
16
|
const projectPath = process.cwd();
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const onSuccess = async (queueTestFiles) => {
|
|
18
|
-
const testFilePaths = queueTestFiles.map((testFile) => testFile.path);
|
|
17
|
+
const knapsackPro = new KnapsackProCore(pkg.name, pkg.version, PathsFinder.allPaths);
|
|
18
|
+
const onSuccess = async (scheduledPaths) => {
|
|
19
19
|
const jestCLICoverage = EnvConfig.coverageDirectory
|
|
20
20
|
? { coverageDirectory: `${EnvConfig.coverageDirectory}/${uuidv4()}` }
|
|
21
21
|
: {};
|
|
22
|
-
const { results
|
|
22
|
+
const { results } = await jest.runCLI({
|
|
23
23
|
...jestCLIOptions,
|
|
24
24
|
...jestCLICoverage,
|
|
25
25
|
runTestsByPath: true,
|
|
26
|
-
_:
|
|
26
|
+
_: scheduledPaths,
|
|
27
27
|
$0: 'jest',
|
|
28
28
|
}, [projectPath]);
|
|
29
|
-
const
|
|
29
|
+
const recordedPaths = {};
|
|
30
|
+
const failedPaths = new Set();
|
|
31
|
+
results.testResults.forEach(({ testFilePath, perfStats, testResults }) => {
|
|
30
32
|
const path = process.platform === 'win32'
|
|
31
|
-
?
|
|
32
|
-
:
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
path
|
|
37
|
-
|
|
38
|
-
};
|
|
33
|
+
? relative(projectPath, testFilePath).replace(/\\/g, '/')
|
|
34
|
+
: relative(projectPath, testFilePath);
|
|
35
|
+
const time = perfStats.end - perfStats.start;
|
|
36
|
+
recordedPaths[path] = time > 0 ? time / 1000 : 0.0;
|
|
37
|
+
if (testResults.some((assertionResult) => assertionResult.status === 'failed')) {
|
|
38
|
+
failedPaths.add(path);
|
|
39
|
+
}
|
|
39
40
|
});
|
|
40
41
|
return {
|
|
41
|
-
|
|
42
|
-
isTestSuiteGreen,
|
|
42
|
+
recordedPaths: normalizePaths(scheduledPaths, recordedPaths),
|
|
43
|
+
isTestSuiteGreen: results.success,
|
|
44
|
+
failedPaths,
|
|
43
45
|
};
|
|
44
46
|
};
|
|
45
47
|
const onError = () => { };
|
|
@@ -3,26 +3,25 @@ import { minimatch } from 'minimatch';
|
|
|
3
3
|
import { KnapsackProLogger } from '@knapsack-pro/core';
|
|
4
4
|
import { EnvConfig } from './env-config.js';
|
|
5
5
|
import * as Urls from './urls.js';
|
|
6
|
-
export class
|
|
7
|
-
static
|
|
8
|
-
const
|
|
6
|
+
export class PathsFinder {
|
|
7
|
+
static allPaths() {
|
|
8
|
+
const paths = glob
|
|
9
9
|
.sync(EnvConfig.testFilePattern)
|
|
10
|
-
.filter((
|
|
10
|
+
.filter((path) => {
|
|
11
11
|
if (EnvConfig.testFileExcludePattern) {
|
|
12
|
-
return !minimatch(
|
|
12
|
+
return !minimatch(path, EnvConfig.testFileExcludePattern, {
|
|
13
13
|
matchBase: true,
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
return true;
|
|
17
17
|
})
|
|
18
|
-
.filter((
|
|
19
|
-
|
|
20
|
-
if (testFiles.length === 0) {
|
|
18
|
+
.filter((path) => !path.match(/node_modules/));
|
|
19
|
+
if (paths.length === 0) {
|
|
21
20
|
const knapsackProLogger = new KnapsackProLogger();
|
|
22
21
|
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}`;
|
|
23
22
|
knapsackProLogger.error(errorMessage);
|
|
24
23
|
throw errorMessage;
|
|
25
24
|
}
|
|
26
|
-
return
|
|
25
|
+
return paths;
|
|
27
26
|
}
|
|
28
27
|
}
|
package/lib/utils.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knapsack-pro/jest",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.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
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
],
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build": "rm -rf lib && tsc && chmod u+x lib/knapsack-pro-jest.js"
|
|
33
|
+
"build": "rm -rf lib && tsc && chmod u+x lib/knapsack-pro-jest.js",
|
|
34
|
+
"test": "vitest --run",
|
|
35
|
+
"test:watch": "vitest"
|
|
34
36
|
},
|
|
35
37
|
"files": [
|
|
36
38
|
"/lib"
|
|
@@ -50,19 +52,20 @@
|
|
|
50
52
|
"./package.json": "./package.json"
|
|
51
53
|
},
|
|
52
54
|
"dependencies": {
|
|
53
|
-
"@knapsack-pro/core": "^
|
|
54
|
-
"glob": "^
|
|
55
|
-
"minimatch": "^10.
|
|
55
|
+
"@knapsack-pro/core": "^11.0.0",
|
|
56
|
+
"glob": "^13.0.6",
|
|
57
|
+
"minimatch": "^10.2.5",
|
|
56
58
|
"minimist": "^1.2.8",
|
|
57
|
-
"uuid": "^
|
|
59
|
+
"uuid": "^14.0.1"
|
|
58
60
|
},
|
|
59
61
|
"peerDependencies": {
|
|
60
62
|
"jest": ">=23.0.0"
|
|
61
63
|
},
|
|
62
64
|
"devDependencies": {
|
|
63
65
|
"@types/jest": "^30.0.0",
|
|
64
|
-
"@types/node": "^
|
|
65
|
-
"jest": "^30.2
|
|
66
|
-
"typescript": "^
|
|
66
|
+
"@types/node": "^26.1.1",
|
|
67
|
+
"jest": "^30.4.2",
|
|
68
|
+
"typescript": "^7.0.2",
|
|
69
|
+
"vitest": "^4.1.10"
|
|
67
70
|
}
|
|
68
71
|
}
|