@nx/jest 21.3.0-beta.5 → 21.3.0-beta.7

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/migrations.json CHANGED
@@ -16,6 +16,22 @@
16
16
  "version": "21.0.0-beta.10",
17
17
  "description": "Remove the previously deprecated and unused `tsConfig` option from the `@nx/jest:jest` executor.",
18
18
  "implementation": "./src/migrations/update-21-0-0/remove-tsconfig-option-from-jest-executor"
19
+ },
20
+ "rename-test-path-pattern": {
21
+ "version": "21.3.0-beta.3",
22
+ "requires": {
23
+ "jest": ">=30.0.0"
24
+ },
25
+ "description": "Rename the CLI option `testPathPattern` to `testPathPatterns`.",
26
+ "implementation": "./src/migrations/update-21-3-0/rename-test-path-pattern"
27
+ },
28
+ "replace-removed-matcher-aliases": {
29
+ "version": "21.3.0-beta.3",
30
+ "requires": {
31
+ "jest": ">=30.0.0"
32
+ },
33
+ "description": "Replace removed matcher aliases in Jest v30 with their corresponding matcher",
34
+ "implementation": "./src/migrations/update-21-3-0/replace-removed-matcher-aliases"
19
35
  }
20
36
  },
21
37
  "packageJsonUpdates": {
@@ -60,6 +76,44 @@
60
76
  "alwaysAddToPackageJson": false
61
77
  }
62
78
  }
79
+ },
80
+ "21.3.0": {
81
+ "version": "21.3.0-beta.3",
82
+ "x-prompt": "Do you want to update the Jest version to v30?",
83
+ "packages": {
84
+ "jest": {
85
+ "version": "~30.0.0",
86
+ "alwaysAddToPackageJson": false
87
+ },
88
+ "@types/jest": {
89
+ "version": "~30.0.0",
90
+ "alwaysAddToPackageJson": false
91
+ },
92
+ "expect": {
93
+ "version": "~30.0.0",
94
+ "alwaysAddToPackageJson": false
95
+ },
96
+ "@jest/globals": {
97
+ "version": "~30.0.0",
98
+ "alwaysAddToPackageJson": false
99
+ },
100
+ "jest-jasmine2": {
101
+ "version": "~30.0.0",
102
+ "alwaysAddToPackageJson": false
103
+ },
104
+ "jest-environment-jsdom": {
105
+ "version": "~30.0.0",
106
+ "alwaysAddToPackageJson": false
107
+ },
108
+ "babel-jest": {
109
+ "version": "~30.0.0",
110
+ "alwaysAddToPackageJson": false
111
+ },
112
+ "@swc/jest": {
113
+ "version": "~0.2.38",
114
+ "alwaysAddToPackageJson": false
115
+ }
116
+ }
63
117
  }
64
118
  }
65
119
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/jest",
3
- "version": "21.3.0-beta.5",
3
+ "version": "21.3.0-beta.7",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Jest contains executors and generators allowing your workspace to use the powerful Jest testing capabilities.",
6
6
  "repository": {
@@ -35,15 +35,15 @@
35
35
  "migrations": "./migrations.json"
36
36
  },
37
37
  "dependencies": {
38
- "@jest/reporters": "^29.4.1",
39
- "@jest/test-result": "^29.4.1",
40
- "@nx/devkit": "21.3.0-beta.5",
41
- "@nx/js": "21.3.0-beta.5",
38
+ "@jest/reporters": "^30.0.2",
39
+ "@jest/test-result": "^30.0.2",
40
+ "@nx/devkit": "21.3.0-beta.7",
41
+ "@nx/js": "21.3.0-beta.7",
42
42
  "@phenomnomnominal/tsquery": "~5.0.1",
43
43
  "identity-obj-proxy": "3.0.0",
44
- "jest-config": "^29.4.1",
45
- "jest-resolve": "^29.4.1",
46
- "jest-util": "^29.4.1",
44
+ "jest-config": "^30.0.2",
45
+ "jest-resolve": "^30.0.2",
46
+ "jest-util": "^30.0.2",
47
47
  "minimatch": "9.0.3",
48
48
  "picocolors": "^1.1.0",
49
49
  "resolve.exports": "2.0.3",
@@ -2,8 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const path_1 = require("path");
4
4
  const resolve_exports_1 = require("resolve.exports");
5
+ const jest_1 = require("jest");
5
6
  let compilerSetup;
6
7
  let ts;
8
+ const jestMajorVersion = Number((0, jest_1.getVersion)().split('.')[0]);
7
9
  function getCompilerSetup(rootDir) {
8
10
  const tsConfigPath = ts.findConfigFile(rootDir, ts.sys.fileExists, 'tsconfig.spec.json') ||
9
11
  ts.findConfigFile(rootDir, ts.sys.fileExists, 'tsconfig.test.json') ||
@@ -27,10 +29,16 @@ module.exports = function (path, options) {
27
29
  // Try to use the defaultResolver with default options
28
30
  return options.defaultResolver(path, options);
29
31
  }
30
- catch {
32
+ catch (e) {
33
+ if (jestMajorVersion >= 30) {
34
+ // The default resolver already handles what we had a workaround for in
35
+ // previous versions. Let the error bubble up.
36
+ throw e;
37
+ }
31
38
  // Try to use the defaultResolver with a packageFilter
32
39
  return options.defaultResolver(path, {
33
40
  ...options,
41
+ // @ts-expect-error packageFilter and pathFilter where available in Jest 29
34
42
  packageFilter: (pkg) => ({
35
43
  ...pkg,
36
44
  main: pkg.main || pkg.es2015 || pkg.module,
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.nxPreset = void 0;
4
4
  exports.nxPreset = {
5
5
  // This is one of the patterns that jest finds by default https://jestjs.io/docs/configuration#testmatch-arraystring
6
- testMatch: ['**/?(*.)+(spec|test).[jt]s?(x)'],
6
+ testMatch: ['**/?(*.)+(spec|test).?([mc])[jt]s?(x)'],
7
7
  resolver: '@nx/jest/plugins/resolver',
8
- moduleFileExtensions: ['ts', 'js', 'mjs', 'html'],
8
+ moduleFileExtensions: ['ts', 'js', 'mts', 'mjs', 'cts', 'cjs', 'html'],
9
9
  coverageReporters: ['html'],
10
10
  transform: {
11
- '^.+\\.(ts|js|html)$': [
11
+ '^.+\\.(ts|js|mts|mjs|cts|cjs|html)$': [
12
12
  'ts-jest',
13
13
  { tsconfig: '<rootDir>/tsconfig.spec.json' },
14
14
  ],
@@ -67,7 +67,7 @@ async function parseJestConfig(options, context, multiProjects = false) {
67
67
  silent: options.silent,
68
68
  testLocationInResults: options.testLocationInResults,
69
69
  testNamePattern: options.testNamePattern,
70
- testPathPattern: options.testPathPattern,
70
+ testPathPatterns: options.testPathPatterns,
71
71
  testPathIgnorePatterns: options.testPathIgnorePatterns,
72
72
  testTimeout: options.testTimeout,
73
73
  colors: options.colors,
@@ -24,7 +24,7 @@ export interface JestExecutorOptions {
24
24
  silent?: boolean;
25
25
  testNamePattern?: string;
26
26
  testPathIgnorePatterns?: string[];
27
- testPathPattern?: string[];
27
+ testPathPatterns?: string[];
28
28
  colors?: boolean;
29
29
  reporters?: string[];
30
30
  verbose?: boolean;
@@ -123,7 +123,7 @@
123
123
  "type": "string"
124
124
  },
125
125
  "passWithNoTests": {
126
- "description": "Will not fail if no tests are found (for example while using `--testPathPattern`.) (https://jestjs.io/docs/cli#--passwithnotests)",
126
+ "description": "Will not fail if no tests are found (for example while using `--testPathPatterns`.) (https://jestjs.io/docs/cli#--passwithnotests)",
127
127
  "type": "boolean"
128
128
  },
129
129
  "randomize": {
@@ -155,8 +155,8 @@
155
155
  "type": "string"
156
156
  }
157
157
  },
158
- "testPathPattern": {
159
- "description": "An array of regexp pattern strings that is matched against all tests paths before executing the test. (https://jestjs.io/docs/cli#--testpathpatternregex)",
158
+ "testPathPatterns": {
159
+ "description": "An array of regexp pattern strings that is matched against all tests paths before executing the test. (https://jestjs.io/docs/cli#--testpathpatternsregex)",
160
160
  "type": "array",
161
161
  "items": {
162
162
  "type": "string"
@@ -8,6 +8,7 @@ const jest_config_1 = require("jest-config");
8
8
  const node_path_1 = require("node:path");
9
9
  const plugin_1 = require("../../plugins/plugin");
10
10
  const config_file_1 = require("../../utils/config/config-file");
11
+ const version_utils_1 = require("../../utils/version-utils");
11
12
  async function convertToInferred(tree, options) {
12
13
  const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
13
14
  const migratedProjects = await (0, executor_to_plugin_migrator_1.migrateProjectExecutorsToPlugin)(tree, projectGraph, '@nx/jest/plugin', plugin_1.createNodesV2, { targetName: 'test' }, [
@@ -87,14 +88,25 @@ async function updateOptions(targetOptions, projectRoot, workspaceRoot, jestConf
87
88
  testPathPatterns.push(toProjectRelativeRegexPath(targetOptions.testFile, projectRoot));
88
89
  delete targetOptions.testFile;
89
90
  }
91
+ let testPathPatternsOptionName;
90
92
  if ('testPathPattern' in targetOptions) {
93
+ testPathPatternsOptionName = 'testPathPattern';
91
94
  testPathPatterns.push(...targetOptions.testPathPattern.map((pattern) => toProjectRelativeRegexPath(pattern, projectRoot)));
92
95
  }
96
+ else if ('testPathPatterns' in targetOptions) {
97
+ testPathPatternsOptionName = 'testPathPatterns';
98
+ testPathPatterns.push(...targetOptions.testPathPatterns.map((pattern) => toProjectRelativeRegexPath(pattern, projectRoot)));
99
+ }
100
+ else {
101
+ const jestMajorVersion = (0, version_utils_1.getInstalledJestMajorVersion)();
102
+ testPathPatternsOptionName =
103
+ jestMajorVersion >= 30 ? 'testPathPatterns' : 'testPathPattern';
104
+ }
93
105
  if (testPathPatterns.length > 1) {
94
- targetOptions.testPathPattern = `\"${testPathPatterns.join('|')}\"`;
106
+ targetOptions[testPathPatternsOptionName] = `\"${testPathPatterns.join('|')}\"`;
95
107
  }
96
108
  else if (testPathPatterns.length === 1) {
97
- targetOptions.testPathPattern = testPathPatterns[0];
109
+ targetOptions[testPathPatternsOptionName] = testPathPatterns[0];
98
110
  }
99
111
  if ('testPathIgnorePatterns' in targetOptions) {
100
112
  if (targetOptions.testPathIgnorePatterns.length > 1) {
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function (tree: Tree): Promise<void>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
+ // migration for https://github.com/jestjs/jest/commit/41133b526d2c17bc9758f90d6026b25301cf0552
7
+ async function default_1(tree) {
8
+ // update options from project configs
9
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/jest:jest', (_, project, target, configuration) => {
10
+ const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, project);
11
+ const config = configuration
12
+ ? projectConfiguration.targets[target].configurations[configuration]
13
+ : projectConfiguration.targets[target].options;
14
+ renameTestPathPattern(config);
15
+ (0, devkit_1.updateProjectConfiguration)(tree, project, projectConfiguration);
16
+ });
17
+ // update options from nx.json target defaults
18
+ const nxJson = (0, devkit_1.readNxJson)(tree);
19
+ if (!nxJson.targetDefaults) {
20
+ return;
21
+ }
22
+ for (const [targetOrExecutor, targetConfig] of Object.entries(nxJson.targetDefaults)) {
23
+ if (targetOrExecutor !== '@nx/jest:jest' &&
24
+ targetConfig.executor !== '@nx/jest:jest') {
25
+ continue;
26
+ }
27
+ if (targetConfig.options) {
28
+ renameTestPathPattern(targetConfig.options);
29
+ }
30
+ Object.values(targetConfig.configurations ?? {}).forEach((config) => {
31
+ renameTestPathPattern(config);
32
+ });
33
+ }
34
+ (0, devkit_1.updateNxJson)(tree, nxJson);
35
+ await (0, devkit_1.formatFiles)(tree);
36
+ }
37
+ function renameTestPathPattern(config) {
38
+ if (!config.testPathPattern) {
39
+ return;
40
+ }
41
+ config.testPathPatterns = config.testPathPattern;
42
+ delete config.testPathPattern;
43
+ }
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function (tree: Tree): Promise<void>;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = default_1;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
6
+ const jest_1 = require("jest");
7
+ const jest_config_1 = require("jest-config");
8
+ const jest_runtime_1 = require("jest-runtime");
9
+ const path_1 = require("path");
10
+ const posix_1 = require("node:path/posix");
11
+ const matcherAliasesMap = new Map([
12
+ ['toBeCalled', 'toHaveBeenCalled'],
13
+ ['toBeCalledTimes', 'toHaveBeenCalledTimes'],
14
+ ['toBeCalledWith', 'toHaveBeenCalledWith'],
15
+ ['lastCalledWith', 'toHaveBeenLastCalledWith'],
16
+ ['nthCalledWith', 'toHaveBeenNthCalledWith'],
17
+ ['toReturn', 'toHaveReturned'],
18
+ ['toReturnTimes', 'toHaveReturnedTimes'],
19
+ ['toReturnWith', 'toHaveReturnedWith'],
20
+ ['lastReturnedWith', 'toHaveLastReturnedWith'],
21
+ ['nthReturnedWith', 'toHaveNthReturnedWith'],
22
+ ['toThrowError', 'toThrow'],
23
+ ]);
24
+ // migration for https://github.com/jestjs/jest/commit/eac241cf0bcb7a808e192e6fcf3afe67edbdbf8e
25
+ async function default_1(tree) {
26
+ const testFilePaths = await getTestFilePaths(tree);
27
+ for (const testFilePath of testFilePaths) {
28
+ let testFileContent = tree.read(testFilePath, 'utf-8');
29
+ for (const [alias, matcher] of matcherAliasesMap) {
30
+ testFileContent = tsquery_1.tsquery.replace(testFileContent, `CallExpression PropertyAccessExpression:has(CallExpression Identifier[name=expect]) Identifier[name=${alias}]`, (_node) => matcher);
31
+ }
32
+ tree.write(testFilePath, testFileContent);
33
+ }
34
+ await (0, devkit_1.formatFiles)(tree);
35
+ }
36
+ async function getTestFilePaths(tree) {
37
+ const jestConfigFiles = await (0, devkit_1.globAsync)(tree, [
38
+ '**/jest.config.{cjs,mjs,js,cts,mts,ts}',
39
+ ]);
40
+ if (!jestConfigFiles.length) {
41
+ return [];
42
+ }
43
+ const testFilePaths = new Set();
44
+ for (const jestConfigFile of jestConfigFiles) {
45
+ const jestConfigContent = tree.read(jestConfigFile, 'utf-8');
46
+ if (jestConfigContent.includes('getJestProjectsAsync()')) {
47
+ // skip the root jest config file which includes all projects
48
+ continue;
49
+ }
50
+ const config = await (0, jest_config_1.readConfig)({ _: [], $0: undefined }, (0, path_1.join)(tree.root, jestConfigFile));
51
+ const jestContext = await jest_runtime_1.default.createContext(config.projectConfig, {
52
+ maxWorkers: 1,
53
+ watchman: false,
54
+ });
55
+ const source = new jest_1.SearchSource(jestContext);
56
+ const specs = await source.getTestPaths(config.globalConfig, config.projectConfig);
57
+ for (const testPath of specs.tests) {
58
+ testFilePaths.add((0, posix_1.relative)(tree.root, testPath.path));
59
+ }
60
+ }
61
+ return Array.from(testFilePaths);
62
+ }
@@ -12,7 +12,6 @@ const package_json_1 = require("nx/src/plugins/package-json");
12
12
  const cache_directory_1 = require("nx/src/utils/cache-directory");
13
13
  const globs_1 = require("nx/src/utils/globs");
14
14
  const path_1 = require("path");
15
- const version_utils_1 = require("../utils/version-utils");
16
15
  const workspace_context_1 = require("nx/src/utils/workspace-context");
17
16
  const node_path_1 = require("node:path");
18
17
  const installation_directory_1 = require("nx/src/utils/installation-directory");
@@ -264,10 +263,7 @@ async function buildJestTargets(configFilePath, projectRoot, options, context, p
264
263
  });
265
264
  const jest = require(resolveJestPath(projectRoot, context.workspaceRoot));
266
265
  const source = new jest.SearchSource(jestContext);
267
- const jestVersion = (0, version_utils_1.getInstalledJestMajorVersion)();
268
- const specs = jestVersion >= 30
269
- ? await source.getTestPaths(config.globalConfig, config.projectConfig)
270
- : await source.getTestPaths(config.globalConfig);
266
+ const specs = await source.getTestPaths(config.globalConfig, config.projectConfig);
271
267
  const testPaths = new Set(specs.tests.map(({ path }) => path));
272
268
  if (testPaths.size > 0) {
273
269
  const targetGroup = [];
@@ -381,8 +377,9 @@ function resolvePresetInputWithJestResolver(presetValue, projectRoot, workspaceR
381
377
  ? presetPath
382
378
  : (0, path_1.join)(presetPath, 'jest-preset');
383
379
  const { default: jestResolve } = requireJestUtil('jest-resolve', projectRoot, workspaceRoot);
380
+ const absoluteProjectRoot = (0, path_1.join)(workspaceRoot, projectRoot);
384
381
  const presetModule = jestResolve.findNodeModule(presetPath, {
385
- basedir: projectRoot,
382
+ basedir: absoluteProjectRoot,
386
383
  extensions: ['.json', '.js', '.cjs', '.mjs'],
387
384
  });
388
385
  if (!presetModule) {
@@ -391,7 +388,7 @@ function resolvePresetInputWithJestResolver(presetValue, projectRoot, workspaceR
391
388
  if (isNpmPackage) {
392
389
  return { externalDependencies: [presetValue] };
393
390
  }
394
- const relativePath = (0, path_1.relative)((0, path_1.join)(workspaceRoot, projectRoot), presetModule);
391
+ const relativePath = (0, path_1.relative)(absoluteProjectRoot, presetModule);
395
392
  return relativePath.startsWith('..')
396
393
  ? (0, path_1.join)('{workspaceRoot}', (0, path_1.join)(projectRoot, relativePath))
397
394
  : (0, path_1.join)('{projectRoot}', relativePath);
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getInstalledJestVersion = getInstalledJestVersion;
4
4
  exports.getInstalledJestMajorVersion = getInstalledJestMajorVersion;
5
+ const jest_1 = require("jest");
5
6
  const semver_1 = require("semver");
6
7
  function getInstalledJestVersion() {
7
8
  try {
8
- return require('jest/package.json').version;
9
+ return (0, jest_1.getVersion)();
9
10
  }
10
11
  catch {
11
12
  return null;
@@ -1,9 +1,9 @@
1
1
  export declare const nxVersion: any;
2
- export declare const jestVersion = "^29.7.0";
3
- export declare const babelJestVersion = "^29.7.0";
4
- export declare const jestTypesVersion = "^29.5.12";
5
- export declare const tsJestVersion = "^29.1.0";
2
+ export declare const jestVersion = "^30.0.2";
3
+ export declare const babelJestVersion = "^30.0.2";
4
+ export declare const jestTypesVersion = "^30.0.0";
5
+ export declare const tsJestVersion = "^29.4.0";
6
6
  export declare const tslibVersion = "^2.3.0";
7
- export declare const swcJestVersion = "~0.2.36";
7
+ export declare const swcJestVersion = "~0.2.38";
8
8
  export declare const typesNodeVersion = "18.16.9";
9
9
  export declare const tsNodeVersion = "10.9.1";
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tsNodeVersion = exports.typesNodeVersion = exports.swcJestVersion = exports.tslibVersion = exports.tsJestVersion = exports.jestTypesVersion = exports.babelJestVersion = exports.jestVersion = exports.nxVersion = void 0;
4
4
  exports.nxVersion = require('../../package.json').version;
5
- exports.jestVersion = '^29.7.0';
6
- exports.babelJestVersion = '^29.7.0';
7
- exports.jestTypesVersion = '^29.5.12';
8
- exports.tsJestVersion = '^29.1.0';
5
+ exports.jestVersion = '^30.0.2';
6
+ exports.babelJestVersion = '^30.0.2';
7
+ exports.jestTypesVersion = '^30.0.0';
8
+ exports.tsJestVersion = '^29.4.0';
9
9
  exports.tslibVersion = '^2.3.0';
10
- exports.swcJestVersion = '~0.2.36';
10
+ exports.swcJestVersion = '~0.2.38';
11
11
  exports.typesNodeVersion = '18.16.9';
12
12
  exports.tsNodeVersion = '10.9.1';