@nx/jest 22.1.0-beta.4 → 22.1.0-beta.6

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/index.d.ts CHANGED
@@ -8,4 +8,5 @@ export { addPropertyToJestConfig, removePropertyFromJestConfig, } from './src/ut
8
8
  export { jestConfigObjectAst } from './src/utils/config/functions';
9
9
  export { jestInitGenerator } from './src/generators/init/init';
10
10
  export { getJestProjectsAsync } from './src/utils/config/get-jest-projects';
11
+ export { findJestConfig } from './src/utils/config/config-file';
11
12
  //# sourceMappingURL=index.d.ts.map
package/index.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/jest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAC;AACtF,OAAO,EAAE,sBAAsB,EAAE,CAAC;AAGlC;;GAEG;AACH,eAAO,MAAM,oBAAoB,+BAAyB,CAAC;AAE3D,OAAO,EACL,uBAAuB,EACvB,4BAA4B,GAC7B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../packages/jest/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,8CAA8C,CAAC;AACtF,OAAO,EAAE,sBAAsB,EAAE,CAAC;AAGlC;;GAEG;AACH,eAAO,MAAM,oBAAoB,+BAAyB,CAAC;AAE3D,OAAO,EACL,uBAAuB,EACvB,4BAA4B,GAC7B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC"}
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getJestProjectsAsync = exports.jestInitGenerator = exports.jestConfigObjectAst = exports.removePropertyFromJestConfig = exports.addPropertyToJestConfig = exports.jestProjectGenerator = exports.configurationGenerator = void 0;
3
+ exports.findJestConfig = exports.getJestProjectsAsync = exports.jestInitGenerator = exports.jestConfigObjectAst = exports.removePropertyFromJestConfig = exports.addPropertyToJestConfig = exports.jestProjectGenerator = exports.configurationGenerator = void 0;
4
4
  const configuration_1 = require("./src/generators/configuration/configuration");
5
5
  Object.defineProperty(exports, "configurationGenerator", { enumerable: true, get: function () { return configuration_1.configurationGenerator; } });
6
6
  // Exported for backwards compatibility in case a plugin is using the old name.
@@ -17,3 +17,5 @@ var init_1 = require("./src/generators/init/init");
17
17
  Object.defineProperty(exports, "jestInitGenerator", { enumerable: true, get: function () { return init_1.jestInitGenerator; } });
18
18
  var get_jest_projects_1 = require("./src/utils/config/get-jest-projects");
19
19
  Object.defineProperty(exports, "getJestProjectsAsync", { enumerable: true, get: function () { return get_jest_projects_1.getJestProjectsAsync; } });
20
+ var config_file_1 = require("./src/utils/config/config-file");
21
+ Object.defineProperty(exports, "findJestConfig", { enumerable: true, get: function () { return config_file_1.findJestConfig; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/jest",
3
- "version": "22.1.0-beta.4",
3
+ "version": "22.1.0-beta.6",
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": {
@@ -37,8 +37,8 @@
37
37
  "dependencies": {
38
38
  "@jest/reporters": "^30.0.2",
39
39
  "@jest/test-result": "^30.0.2",
40
- "@nx/devkit": "22.1.0-beta.4",
41
- "@nx/js": "22.1.0-beta.4",
40
+ "@nx/devkit": "22.1.0-beta.6",
41
+ "@nx/js": "22.1.0-beta.6",
42
42
  "@phenomnomnominal/tsquery": "~5.0.1",
43
43
  "identity-obj-proxy": "3.0.0",
44
44
  "jest-config": "^30.0.2",
@@ -52,7 +52,7 @@
52
52
  "yargs-parser": "21.1.1"
53
53
  },
54
54
  "devDependencies": {
55
- "nx": "22.1.0-beta.4"
55
+ "nx": "22.1.0-beta.6"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public"
@@ -9,6 +9,7 @@
9
9
  "files": ["src/test-setup.ts"],<% } %>
10
10
  "include": [
11
11
  "jest.config.ts",
12
+ "jest.config.cts",
12
13
  "src/**/*.test.ts",
13
14
  "src/**/*.spec.ts",<% if (supportTsx) { %>
14
15
  "src/**/*.test.tsx",
@@ -1 +1 @@
1
- {"version":3,"file":"create-files.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jest/src/generators/configuration/lib/create-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,IAAI,EACL,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAExD,wBAAgB,WAAW,CACzB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,2BAA2B,EACpC,SAAS,EAAE,mBAAmB,QAoG/B"}
1
+ {"version":3,"file":"create-files.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jest/src/generators/configuration/lib/create-files.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,IAAI,EACL,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAE7E,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAExD,wBAAgB,WAAW,CACzB,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,2BAA2B,EACpC,SAAS,EAAE,mBAAmB,QA4G/B"}
@@ -4,8 +4,14 @@ exports.createFiles = createFiles;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const add_swc_config_1 = require("@nx/js/src/utils/swc/add-swc-config");
6
6
  const path_1 = require("path");
7
+ const versions_1 = require("../../../utils/versions");
7
8
  function createFiles(tree, options, presetExt) {
8
9
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
10
+ // Detect Jest 30+ to use .cts config files (CommonJS TypeScript)
11
+ // Treat null (version cannot be determined) as Jest 30+
12
+ const jestMajorVersion = (0, versions_1.getInstalledJestMajorVersion)(tree);
13
+ const useCommonJsConfig = jestMajorVersion === null || jestMajorVersion >= 30;
14
+ const useJsSyntax = useCommonJsConfig || !!options.js;
9
15
  const commonFilesFolder = options.setupFile === 'angular' ? '../files-angular' : '../files/common';
10
16
  let transformer;
11
17
  let transformerOptions = null;
@@ -46,7 +52,7 @@ function createFiles(tree, options, presetExt) {
46
52
  testEnvironment,
47
53
  transformer,
48
54
  transformerOptions,
49
- js: !!options.js,
55
+ js: useJsSyntax,
50
56
  rootProject: options.rootProject,
51
57
  projectRoot,
52
58
  offsetFromRoot: rootOffset,
@@ -71,7 +77,7 @@ function createFiles(tree, options, presetExt) {
71
77
  testEnvironment,
72
78
  transformer,
73
79
  transformerOptions,
74
- js: !!options.js,
80
+ js: useJsSyntax,
75
81
  rootProject: options.rootProject,
76
82
  offsetFromRoot: rootOffset,
77
83
  presetExt,
@@ -81,7 +87,13 @@ function createFiles(tree, options, presetExt) {
81
87
  if (options.setupFile === 'none') {
82
88
  tree.delete((0, path_1.join)(projectConfig.root, './src/test-setup.ts'));
83
89
  }
84
- if (options.js) {
85
- tree.rename((0, path_1.join)(projectConfig.root, 'jest.config.ts'), (0, path_1.join)(projectConfig.root, 'jest.config.js'));
90
+ const configPath = (0, path_1.join)(projectConfig.root, 'jest.config.ts');
91
+ if (tree.exists(configPath)) {
92
+ if (options.js) {
93
+ tree.rename(configPath, (0, path_1.join)(projectConfig.root, 'jest.config.js'));
94
+ }
95
+ else if (useCommonJsConfig) {
96
+ tree.rename(configPath, (0, path_1.join)(projectConfig.root, 'jest.config.cts'));
97
+ }
86
98
  }
87
99
  }
@@ -1 +1 @@
1
- {"version":3,"file":"update-tsconfig.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jest/src/generators/configuration/lib/update-tsconfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAG7D,wBAAgB,cAAc,CAC5B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,2BAA2B,QAyErC"}
1
+ {"version":3,"file":"update-tsconfig.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jest/src/generators/configuration/lib/update-tsconfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAG7D,wBAAgB,cAAc,CAC5B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,2BAA2B,QAsFrC"}
@@ -15,6 +15,14 @@ function updateTsConfig(host, options) {
15
15
  path: './tsconfig.spec.json',
16
16
  });
17
17
  }
18
+ // If compilerOptions.types is defined, ensure "node" is included to support
19
+ // module.exports syntax in jest.config.cts. If types is not defined,
20
+ // TypeScript automatically loads @types/node.
21
+ if (json.compilerOptions?.types) {
22
+ if (!json.compilerOptions.types.includes('node')) {
23
+ json.compilerOptions.types.push('node');
24
+ }
25
+ }
18
26
  return json;
19
27
  });
20
28
  const projectType = (0, ts_solution_setup_1.getProjectType)(host, root, _projectType);
@@ -37,7 +45,9 @@ function updateTsConfig(host, options) {
37
45
  (0, devkit_1.updateJson)(host, runtimeTsconfigPath, (json) => {
38
46
  const uniqueExclude = new Set([
39
47
  ...(json.exclude || []),
40
- options.js ? 'jest.config.js' : 'jest.config.ts',
48
+ ...(options.js
49
+ ? ['jest.config.js']
50
+ : ['jest.config.ts', 'jest.config.cts']),
41
51
  'src/**/*.spec.ts',
42
52
  'src/**/*.test.ts',
43
53
  ...(options.js ? ['src/**/*.spec.js', 'src/**/*.test.js'] : []),
@@ -1 +1 @@
1
- {"version":3,"file":"update-workspace.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jest/src/generators/configuration/lib/update-workspace.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,IAAI,EAEV,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAE7D,wBAAgB,eAAe,CAC7B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,2BAA2B,QAiCrC"}
1
+ {"version":3,"file":"update-workspace.d.ts","sourceRoot":"","sources":["../../../../../../../packages/jest/src/generators/configuration/lib/update-workspace.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,IAAI,EAEV,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAE7D,wBAAgB,eAAe,CAC7B,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,2BAA2B,QAsCrC"}
@@ -2,11 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateWorkspace = updateWorkspace;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("../../../utils/versions");
5
6
  function updateWorkspace(tree, options) {
6
7
  const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
7
8
  if (!projectConfig.targets) {
8
9
  projectConfig.targets = {};
9
10
  }
11
+ // Detect Jest 30+ to use .cts config files (CommonJS TypeScript)
12
+ const jestMajorVersion = (0, versions_1.getInstalledJestMajorVersion)(tree);
13
+ const useCommonJsConfig = jestMajorVersion === null || jestMajorVersion >= 30;
14
+ const jestConfigExt = options.js ? 'js' : useCommonJsConfig ? 'cts' : 'ts';
10
15
  projectConfig.targets[options.targetName] = {
11
16
  executor: '@nx/jest:jest',
12
17
  outputs: [
@@ -15,7 +20,7 @@ function updateWorkspace(tree, options) {
15
20
  : (0, devkit_1.joinPathFragments)('{workspaceRoot}', 'coverage', options.rootProject ? '{projectName}' : '{projectRoot}'),
16
21
  ],
17
22
  options: {
18
- jestConfig: (0, devkit_1.joinPathFragments)(projectConfig.root, `jest.config.${options.js ? 'js' : 'ts'}`),
23
+ jestConfig: (0, devkit_1.joinPathFragments)(projectConfig.root, `jest.config.${jestConfigExt}`),
19
24
  },
20
25
  };
21
26
  if (options.setupFile === 'angular') {
@@ -5,5 +5,6 @@ export declare const jestPresetExtensions: readonly ["js", "cjs", "mjs"];
5
5
  export type JestPresetExtension = (typeof jestPresetExtensions)[number];
6
6
  export declare function getPresetExt(tree: Tree): JestPresetExtension;
7
7
  export declare function findRootJestConfig(tree: Tree): string | null;
8
+ export declare function findJestConfig(tree: Tree, projectPath: string): string | null;
8
9
  export declare function findRootJestPreset(tree: Tree): string | null;
9
10
  //# sourceMappingURL=config-file.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config-file.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/utils/config/config-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAEjD,eAAO,MAAM,oBAAoB,mDAOvB,CAAC;AACX,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE,eAAO,MAAM,oBAAoB,+BAAgC,CAAC;AAClE,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,mBAAmB,CAiB5D;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAM5D;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAM5D"}
1
+ {"version":3,"file":"config-file.d.ts","sourceRoot":"","sources":["../../../../../../packages/jest/src/utils/config/config-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAEjD,eAAO,MAAM,oBAAoB,mDAOvB,CAAC;AACX,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE,eAAO,MAAM,oBAAoB,+BAAgC,CAAC;AAClE,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,GAAG,mBAAmB,CAiB5D;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAM5D;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAM7E;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAM5D"}
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.jestPresetExtensions = exports.jestConfigExtensions = void 0;
4
4
  exports.getPresetExt = getPresetExt;
5
5
  exports.findRootJestConfig = findRootJestConfig;
6
+ exports.findJestConfig = findJestConfig;
6
7
  exports.findRootJestPreset = findRootJestPreset;
7
8
  const devkit_1 = require("@nx/devkit");
8
9
  exports.jestConfigExtensions = [
@@ -31,6 +32,10 @@ function findRootJestConfig(tree) {
31
32
  const ext = exports.jestConfigExtensions.find((ext) => tree.exists(`jest.config.${ext}`));
32
33
  return ext ? `jest.config.${ext}` : null;
33
34
  }
35
+ function findJestConfig(tree, projectPath) {
36
+ const ext = exports.jestConfigExtensions.find((ext) => tree.exists(`${projectPath}/jest.config.${ext}`));
37
+ return ext ? `${projectPath}/jest.config.${ext}` : null;
38
+ }
34
39
  function findRootJestPreset(tree) {
35
40
  const ext = exports.jestPresetExtensions.find((ext) => tree.exists(`jest.preset.${ext}`));
36
41
  return ext ? `jest.preset.${ext}` : null;