@knapsack-pro/jest 9.0.0-rc.1 → 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/README.md +0 -6
- package/lib/knapsack-pro-jest.js +21 -20
- package/lib/{test-files-finder.js → paths-finder.js} +8 -9
- package/lib/utils.js +5 -0
- package/package.json +14 -27
package/README.md
CHANGED
|
@@ -47,12 +47,6 @@ See the [docs](https://docs.knapsackpro.com/jest/guide/) to get started:
|
|
|
47
47
|
|
|
48
48
|
Follow the steps in the [root README.md](https://github.com/KnapsackPro/knapsack-pro-js#contributing) to set up the project.
|
|
49
49
|
|
|
50
|
-
You can compile TypeScript in watch mode from the root folder with:
|
|
51
|
-
|
|
52
|
-
```bash
|
|
53
|
-
npm start -w packages/jest
|
|
54
|
-
```
|
|
55
|
-
|
|
56
50
|
### Testing
|
|
57
51
|
|
|
58
52
|
To test `@knapsack-pro/jest` against a real test suite we use:
|
package/lib/knapsack-pro-jest.js
CHANGED
|
@@ -1,46 +1,47 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import pkg from '@knapsack-pro/jest/package.json' with { type: 'json' };
|
|
2
3
|
import { KnapsackProCore, KnapsackProLogger, } from '@knapsack-pro/core';
|
|
3
4
|
import { v4 as uuidv4 } from 'uuid';
|
|
5
|
+
import { relative } from 'path';
|
|
4
6
|
import { EnvConfig } from './env-config.js';
|
|
5
|
-
import {
|
|
7
|
+
import { PathsFinder } from './paths-finder.js';
|
|
6
8
|
import { JestCLI } from './jest-cli.js';
|
|
9
|
+
import { normalizePaths } from './utils.js';
|
|
7
10
|
const jestImport = await import('jest');
|
|
8
11
|
const jest = jestImport.default ?? jestImport;
|
|
9
|
-
const clientName = '@knapsack-pro/jest';
|
|
10
|
-
const clientVersion = '9.0.0-rc.1';
|
|
11
12
|
const jestCLIOptions = JestCLI.argvToOptions();
|
|
12
13
|
const knapsackProLogger = new KnapsackProLogger();
|
|
13
14
|
knapsackProLogger.debug(`Jest CLI options:\n${KnapsackProLogger.objectInspect(jestCLIOptions)}`);
|
|
14
15
|
EnvConfig.loadEnvironmentVariables();
|
|
15
16
|
const projectPath = process.cwd();
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const onSuccess = async (queueTestFiles) => {
|
|
19
|
-
const testFilePaths = queueTestFiles.map((testFile) => testFile.path);
|
|
17
|
+
const knapsackPro = new KnapsackProCore(pkg.name, pkg.version, PathsFinder.allPaths);
|
|
18
|
+
const onSuccess = async (scheduledPaths) => {
|
|
20
19
|
const jestCLICoverage = EnvConfig.coverageDirectory
|
|
21
20
|
? { coverageDirectory: `${EnvConfig.coverageDirectory}/${uuidv4()}` }
|
|
22
21
|
: {};
|
|
23
|
-
const { results
|
|
22
|
+
const { results } = await jest.runCLI({
|
|
24
23
|
...jestCLIOptions,
|
|
25
24
|
...jestCLICoverage,
|
|
26
25
|
runTestsByPath: true,
|
|
27
|
-
_:
|
|
26
|
+
_: scheduledPaths,
|
|
28
27
|
$0: 'jest',
|
|
29
28
|
}, [projectPath]);
|
|
30
|
-
const
|
|
29
|
+
const recordedPaths = {};
|
|
30
|
+
const failedPaths = new Set();
|
|
31
|
+
results.testResults.forEach(({ testFilePath, perfStats, testResults }) => {
|
|
31
32
|
const path = process.platform === 'win32'
|
|
32
|
-
?
|
|
33
|
-
:
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
path
|
|
38
|
-
|
|
39
|
-
};
|
|
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
|
+
}
|
|
40
40
|
});
|
|
41
41
|
return {
|
|
42
|
-
|
|
43
|
-
isTestSuiteGreen,
|
|
42
|
+
recordedPaths: normalizePaths(scheduledPaths, recordedPaths),
|
|
43
|
+
isTestSuiteGreen: results.success,
|
|
44
|
+
failedPaths,
|
|
44
45
|
};
|
|
45
46
|
};
|
|
46
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,13 +30,9 @@
|
|
|
30
30
|
],
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"scripts": {
|
|
33
|
-
"start": "nodemon --ext ts --watch src/ --exec \"npm run build\"",
|
|
34
33
|
"build": "rm -rf lib && tsc && chmod u+x lib/knapsack-pro-jest.js",
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"eslint:format": "eslint src/**/*.ts --fix",
|
|
38
|
-
"prettier:check": "prettier --config .prettierrc.json --check .",
|
|
39
|
-
"prettier:format": "prettier --config .prettierrc.json --write ."
|
|
34
|
+
"test": "vitest --run",
|
|
35
|
+
"test:watch": "vitest"
|
|
40
36
|
},
|
|
41
37
|
"files": [
|
|
42
38
|
"/lib"
|
|
@@ -52,33 +48,24 @@
|
|
|
52
48
|
"bin": {
|
|
53
49
|
"knapsack-pro-jest": "lib/knapsack-pro-jest.js"
|
|
54
50
|
},
|
|
51
|
+
"exports": {
|
|
52
|
+
"./package.json": "./package.json"
|
|
53
|
+
},
|
|
55
54
|
"dependencies": {
|
|
56
|
-
"@knapsack-pro/core": "^
|
|
57
|
-
"glob": "^
|
|
58
|
-
"minimatch": "^10.
|
|
55
|
+
"@knapsack-pro/core": "^11.0.0",
|
|
56
|
+
"glob": "^13.0.6",
|
|
57
|
+
"minimatch": "^10.2.5",
|
|
59
58
|
"minimist": "^1.2.8",
|
|
60
|
-
"uuid": "^
|
|
59
|
+
"uuid": "^14.0.1"
|
|
61
60
|
},
|
|
62
61
|
"peerDependencies": {
|
|
63
62
|
"jest": ">=23.0.0"
|
|
64
63
|
},
|
|
65
64
|
"devDependencies": {
|
|
66
|
-
"@eslint/eslintrc": "^3.3.1",
|
|
67
|
-
"@eslint/js": "^9.35.0",
|
|
68
65
|
"@types/jest": "^30.0.0",
|
|
69
|
-
"@types/node": "^
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"eslint-config-airbnb-base": "^15.0.0",
|
|
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"
|
|
66
|
+
"@types/node": "^26.1.1",
|
|
67
|
+
"jest": "^30.4.2",
|
|
68
|
+
"typescript": "^7.0.2",
|
|
69
|
+
"vitest": "^4.1.10"
|
|
83
70
|
}
|
|
84
71
|
}
|