@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 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:
@@ -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 { TestFilesFinder } from './test-files-finder.js';
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 testFilesToExecute = () => TestFilesFinder.allTestFiles();
17
- const knapsackPro = new KnapsackProCore(clientName, clientVersion, testFilesToExecute);
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: { success: isTestSuiteGreen, testResults }, } = await jest.runCLI({
22
+ const { results } = await jest.runCLI({
24
23
  ...jestCLIOptions,
25
24
  ...jestCLICoverage,
26
25
  runTestsByPath: true,
27
- _: testFilePaths,
26
+ _: scheduledPaths,
28
27
  $0: 'jest',
29
28
  }, [projectPath]);
30
- const recordedTestFiles = testResults.map(({ testFilePath, perfStats: { start, end }, }) => {
29
+ const recordedPaths = {};
30
+ const failedPaths = new Set();
31
+ results.testResults.forEach(({ testFilePath, perfStats, testResults }) => {
31
32
  const path = process.platform === 'win32'
32
- ? testFilePath.replace(`${projectPath}\\`, '').replace(/\\/g, '/')
33
- : testFilePath.replace(`${projectPath}/`, '');
34
- const timeExecutionMiliseconds = end - start;
35
- const timeExecution = timeExecutionMiliseconds > 0 ? timeExecutionMiliseconds / 1000 : 0.0;
36
- return {
37
- path,
38
- time_execution: timeExecution,
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
- recordedTestFiles,
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 TestFilesFinder {
7
- static allTestFiles() {
8
- const testFiles = glob
6
+ export class PathsFinder {
7
+ static allPaths() {
8
+ const paths = glob
9
9
  .sync(EnvConfig.testFilePattern)
10
- .filter((testFilePath) => {
10
+ .filter((path) => {
11
11
  if (EnvConfig.testFileExcludePattern) {
12
- return !minimatch(testFilePath, EnvConfig.testFileExcludePattern, {
12
+ return !minimatch(path, EnvConfig.testFileExcludePattern, {
13
13
  matchBase: true,
14
14
  });
15
15
  }
16
16
  return true;
17
17
  })
18
- .filter((testFilePath) => !testFilePath.match(/node_modules/))
19
- .map((testFilePath) => ({ path: testFilePath }));
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 testFiles;
25
+ return paths;
27
26
  }
28
27
  }
package/lib/utils.js ADDED
@@ -0,0 +1,5 @@
1
+ export const normalizePaths = (scheduledPaths, recordedPaths) => {
2
+ return Object.entries(recordedPaths).reduce((acc, [path, time]) => {
3
+ return { ...acc, [path]: (acc[path] ?? 0) + time };
4
+ }, scheduledPaths.reduce((acc, path) => ({ ...acc, [path]: 0 }), {}));
5
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@knapsack-pro/jest",
3
- "version": "9.0.0-rc.1",
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
- "lint": "npm run eslint:check && npm run prettier:check",
36
- "eslint:check": "eslint src/**/*.ts",
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": "^9.0.0-rc.1",
57
- "glob": "^11.0.3",
58
- "minimatch": "^10.0.3",
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": "^13.0.0"
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": "^24.5.1",
70
- "@typescript-eslint/eslint-plugin": "^8.44.0",
71
- "@typescript-eslint/parser": "^8.44.0",
72
- "eslint": "^9.35.0",
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
  }