@nx/jest 16.8.0-beta.4 → 16.8.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.
Files changed (26) hide show
  1. package/package.json +5 -5
  2. package/plugins/resolver.js +10 -3
  3. package/src/executors/jest/jest.impl.js +144 -116
  4. package/src/executors/jest/summary.js +4 -4
  5. package/src/generators/configuration/configuration.js +16 -15
  6. package/src/generators/configuration/lib/check-for-test-target.js +1 -2
  7. package/src/generators/configuration/lib/create-files.js +11 -3
  8. package/src/generators/configuration/lib/update-workspace.js +1 -2
  9. package/src/generators/init/init.js +27 -27
  10. package/src/migrations/update-12-1-2/update-jest-preset-angular.js +5 -8
  11. package/src/migrations/update-12-1-2/update-ts-jest.js +5 -9
  12. package/src/migrations/update-12-4-0/add-test-environment-for-node.js +5 -8
  13. package/src/migrations/update-12-4-0/update-jest-preset-angular.js +14 -20
  14. package/src/migrations/update-12-6-0/update-base-jest-config.js +4 -8
  15. package/src/migrations/update-13-1-2/update-tsconfigs-for-tests.js +3 -6
  16. package/src/migrations/update-13-4-4/add-missing-root-babel-config.js +7 -10
  17. package/src/migrations/update-14-0-0/update-jest-config-ext.js +46 -50
  18. package/src/migrations/update-14-6-0/update-configs-jest-28.js +6 -7
  19. package/src/migrations/update-14-6-0/update-tests-jest-28.js +12 -16
  20. package/src/migrations/update-15-0-0/add-jest-inputs.js +27 -32
  21. package/src/migrations/update-15-8-0/update-configs-jest-29.js +28 -34
  22. package/src/migrations/update-15-8-0/update-tests-jest-29.js +11 -14
  23. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +3 -6
  24. package/src/migrations/update-16-5-0/add-test-setup-to-inputs-ignore.js +11 -15
  25. package/src/utils/config/functions.js +3 -5
  26. package/src/utils/config/get-jest-projects.js +1 -2
@@ -1,19 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
5
  const path_1 = require("path");
7
6
  const update_config_1 = require("../../utils/config/update-config");
8
7
  function updateJestConfig(tree) {
9
8
  (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/jest:jest', (options, project) => {
10
- var _a;
11
9
  if (!options.jestConfig) {
12
10
  return;
13
11
  }
14
12
  const jestConfigPath = options.jestConfig;
15
13
  const config = require((0, path_1.join)(tree.root, jestConfigPath));
16
- const tsJestConfig = (_a = config.globals) === null || _a === void 0 ? void 0 : _a['ts-jest'];
14
+ const tsJestConfig = config.globals?.['ts-jest'];
17
15
  if (!(tsJestConfig && tsJestConfig.tsConfig)) {
18
16
  return;
19
17
  }
@@ -21,15 +19,13 @@ function updateJestConfig(tree) {
21
19
  (0, update_config_1.removePropertyFromJestConfig)(tree, jestConfigPath, 'globals.ts-jest.tsConfig');
22
20
  (0, update_config_1.addPropertyToJestConfig)(tree, jestConfigPath, 'globals.ts-jest.tsconfig', tsJestConfig.tsConfig);
23
21
  }
24
- catch (_b) {
22
+ catch {
25
23
  devkit_1.logger.error((0, devkit_1.stripIndents) `Unable to update jest.config.js for project ${project}.`);
26
24
  }
27
25
  });
28
26
  }
29
- function update(tree) {
30
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
31
- updateJestConfig(tree);
32
- yield (0, devkit_1.formatFiles)(tree);
33
- });
27
+ async function update(tree) {
28
+ updateJestConfig(tree);
29
+ await (0, devkit_1.formatFiles)(tree);
34
30
  }
35
31
  exports.default = update;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
5
  const path_1 = require("path");
@@ -20,18 +19,16 @@ function updateJestConfig(tree) {
20
19
  try {
21
20
  (0, update_config_1.addPropertyToJestConfig)(tree, jestConfigPath, 'testEnvironment', 'node');
22
21
  }
23
- catch (_a) {
22
+ catch {
24
23
  devkit_1.logger.error((0, devkit_1.stripIndents) `Unable to update jest.config.js for project ${project}.`);
25
24
  }
26
25
  });
27
26
  }
28
- function update(tree) {
29
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
30
- updateJestConfig(tree);
31
- yield (0, devkit_1.formatFiles)(tree);
32
- });
27
+ async function update(tree) {
28
+ updateJestConfig(tree);
29
+ await (0, devkit_1.formatFiles)(tree);
33
30
  }
34
31
  exports.default = update;
35
32
  function checkIfNodeProject(config) {
36
- return Object.entries(config.targets).some(([targetName, targetConfig]) => { var _a, _b; return (_b = (_a = targetConfig.executor) === null || _a === void 0 ? void 0 : _a.includes) === null || _b === void 0 ? void 0 : _b.call(_a, 'node'); });
33
+ return Object.entries(config.targets).some(([targetName, targetConfig]) => targetConfig.executor?.includes?.('node'));
37
34
  }
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.usesJestPresetAngular = exports.transformerIsFromJestPresetAngular = exports.getNewAstTransformers = exports.updateTransform = exports.updateASTTransformers = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
7
6
  const path_1 = require("path");
@@ -20,21 +19,18 @@ function updateJestConfig(tree) {
20
19
  updateASTTransformers(tree, jestConfigPath, jestConfig);
21
20
  updateTransform(tree, jestConfigPath, jestConfig);
22
21
  }
23
- catch (_a) {
22
+ catch {
24
23
  devkit_1.logger.error((0, devkit_1.stripIndents) `Unable to update jest.config.js for project ${project}.`);
25
24
  }
26
25
  });
27
26
  }
28
- function update(tree) {
29
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
30
- updateJestConfig(tree);
31
- yield (0, devkit_1.formatFiles)(tree);
32
- });
27
+ async function update(tree) {
28
+ updateJestConfig(tree);
29
+ await (0, devkit_1.formatFiles)(tree);
33
30
  }
34
31
  exports.default = update;
35
32
  function updateASTTransformers(tree, jestConfigPath, jestConfig) {
36
- var _a, _b;
37
- const newTransformers = getNewAstTransformers((_b = (_a = jestConfig.globals) === null || _a === void 0 ? void 0 : _a['ts-jest']) === null || _b === void 0 ? void 0 : _b.astTransformers);
33
+ const newTransformers = getNewAstTransformers(jestConfig.globals?.['ts-jest']?.astTransformers);
38
34
  if (newTransformers === null) {
39
35
  (0, update_config_1.removePropertyFromJestConfig)(tree, jestConfigPath, 'globals.ts-jest.astTransformers');
40
36
  }
@@ -51,16 +47,15 @@ function updateTransform(tree, jestConfigPath, jestConfig) {
51
47
  }
52
48
  exports.updateTransform = updateTransform;
53
49
  function getNewAstTransformers(astTransformers) {
54
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
55
50
  let result = {
56
- before: (_b = (_a = astTransformers === null || astTransformers === void 0 ? void 0 : astTransformers.before) === null || _a === void 0 ? void 0 : _a.filter) === null || _b === void 0 ? void 0 : _b.call(_a, (x) => !transformerIsFromJestPresetAngular(x)),
57
- after: (_d = (_c = astTransformers === null || astTransformers === void 0 ? void 0 : astTransformers.after) === null || _c === void 0 ? void 0 : _c.filter) === null || _d === void 0 ? void 0 : _d.call(_c, (x) => !transformerIsFromJestPresetAngular(x)),
58
- afterDeclarations: (_f = (_e = astTransformers === null || astTransformers === void 0 ? void 0 : astTransformers.afterDeclarations) === null || _e === void 0 ? void 0 : _e.filter) === null || _f === void 0 ? void 0 : _f.call(_e, (x) => !transformerIsFromJestPresetAngular(x)),
51
+ before: astTransformers?.before?.filter?.((x) => !transformerIsFromJestPresetAngular(x)),
52
+ after: astTransformers?.after?.filter?.((x) => !transformerIsFromJestPresetAngular(x)),
53
+ afterDeclarations: astTransformers?.afterDeclarations?.filter?.((x) => !transformerIsFromJestPresetAngular(x)),
59
54
  };
60
55
  result = {
61
- before: ((_g = result.before) === null || _g === void 0 ? void 0 : _g.length) > 0 ? result.before : undefined,
62
- after: ((_h = result.after) === null || _h === void 0 ? void 0 : _h.length) > 0 ? result.after : undefined,
63
- afterDeclarations: ((_j = result.afterDeclarations) === null || _j === void 0 ? void 0 : _j.length) > 0
56
+ before: result.before?.length > 0 ? result.before : undefined,
57
+ after: result.after?.length > 0 ? result.after : undefined,
58
+ afterDeclarations: result.afterDeclarations?.length > 0
64
59
  ? result.afterDeclarations
65
60
  : undefined,
66
61
  };
@@ -79,10 +74,9 @@ function transformerIsFromJestPresetAngular(transformer) {
79
74
  }
80
75
  exports.transformerIsFromJestPresetAngular = transformerIsFromJestPresetAngular;
81
76
  function usesJestPresetAngular(jestConfig) {
82
- var _a, _b, _c, _d, _e, _f, _g;
83
- const transformers = Array.isArray((_b = (_a = jestConfig.globals) === null || _a === void 0 ? void 0 : _a['ts-jest']) === null || _b === void 0 ? void 0 : _b.astTransformers)
84
- ? ((_d = (_c = jestConfig.globals) === null || _c === void 0 ? void 0 : _c['ts-jest']) === null || _d === void 0 ? void 0 : _d.astTransformers) || []
85
- : ((_g = (_f = (_e = jestConfig.globals) === null || _e === void 0 ? void 0 : _e['ts-jest']) === null || _f === void 0 ? void 0 : _f.astTransformers) === null || _g === void 0 ? void 0 : _g.before) || [];
77
+ const transformers = Array.isArray(jestConfig.globals?.['ts-jest']?.astTransformers)
78
+ ? jestConfig.globals?.['ts-jest']?.astTransformers || []
79
+ : jestConfig.globals?.['ts-jest']?.astTransformers?.before || [];
86
80
  return transformers.some((x) => transformerIsFromJestPresetAngular(x));
87
81
  }
88
82
  exports.usesJestPresetAngular = usesJestPresetAngular;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const functions_1 = require("../../utils/config/functions");
6
5
  const get_jest_projects_1 = require("../../utils/config/get-jest-projects");
@@ -21,22 +20,19 @@ function determineProjectsValue(uncoveredJestProjects) {
21
20
  .join('')}]`;
22
21
  }
23
22
  function updateBaseJestConfig(tree, baseJestConfigPath = 'jest.config.js') {
24
- var _a;
25
23
  if (tree.read('/jest.config.js', 'utf-8').includes('getJestProjects()')) {
26
24
  return;
27
25
  }
28
26
  const currentConfig = (0, functions_1.jestConfigObject)(tree, baseJestConfigPath);
29
- (_a = currentConfig.projects) !== null && _a !== void 0 ? _a : (currentConfig.projects = []);
27
+ currentConfig.projects ??= [];
30
28
  const uncoveredJestProjects = determineUncoveredJestProjects(currentConfig.projects);
31
29
  (0, update_config_1.removePropertyFromJestConfig)(tree, baseJestConfigPath, 'projects');
32
30
  (0, update_config_1.addPropertyToJestConfig)(tree, baseJestConfigPath, 'projects', determineProjectsValue(uncoveredJestProjects), { valueAsString: true });
33
31
  (0, update_config_1.addImportStatementToJestConfig)(tree, baseJestConfigPath, `const { getJestProjects } = require('@nx/jest');`);
34
32
  return;
35
33
  }
36
- function update(tree) {
37
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
38
- updateBaseJestConfig(tree);
39
- yield (0, devkit_1.formatFiles)(tree);
40
- });
34
+ async function update(tree) {
35
+ updateBaseJestConfig(tree);
36
+ await (0, devkit_1.formatFiles)(tree);
41
37
  }
42
38
  exports.default = update;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
5
  const path_1 = require("path");
@@ -50,10 +49,8 @@ function makeAllPatternsFromSpecPatterns(specGlobs = ['**/*.spec.ts']) {
50
49
  function makeUniquePatterns(items = []) {
51
50
  return [...new Set(items)];
52
51
  }
53
- function update(tree) {
54
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
55
- updateTsConfigsForTests(tree);
56
- yield (0, devkit_1.formatFiles)(tree);
57
- });
52
+ async function update(tree) {
53
+ updateTsConfigsForTests(tree);
54
+ await (0, devkit_1.formatFiles)(tree);
58
55
  }
59
56
  exports.default = update;
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
5
  const functions_1 = require("../../utils/config/functions");
@@ -29,14 +28,12 @@ function checkIfProjectNeedsUpdate(tree) {
29
28
  });
30
29
  return shouldUpdate;
31
30
  }
32
- function update(tree) {
33
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
34
- const shouldUpdateConfigs = checkIfProjectNeedsUpdate(tree);
35
- if (shouldUpdateConfigs) {
36
- (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nrwl/web': versions_1.nxVersion });
37
- tree.write('babel.config.json', '{"babelrcRoots": ["*"]}');
38
- yield (0, devkit_1.formatFiles)(tree);
39
- }
40
- });
31
+ async function update(tree) {
32
+ const shouldUpdateConfigs = checkIfProjectNeedsUpdate(tree);
33
+ if (shouldUpdateConfigs) {
34
+ (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nrwl/web': versions_1.nxVersion });
35
+ tree.write('babel.config.json', '{"babelrcRoots": ["*"]}');
36
+ await (0, devkit_1.formatFiles)(tree);
37
+ }
41
38
  }
42
39
  exports.default = update;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateJestConfigExt = void 0;
4
- const tslib_1 = require("tslib");
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
7
6
  const path_1 = require("path");
@@ -52,63 +51,60 @@ function updateTsconfigSpec(tree, projectConfig, path, options = {
52
51
  });
53
52
  }
54
53
  function isNextWithProjectLint(projectConfig, esLintJson) {
55
- var _a, _b, _c, _d;
56
- const esLintOverrides = (_a = esLintJson === null || esLintJson === void 0 ? void 0 : esLintJson.overrides) === null || _a === void 0 ? void 0 : _a.find((o) => ['*.ts', '*.tsx', '*.js', '*.jsx'].every((ext) => o.files.includes(ext)));
54
+ const esLintOverrides = esLintJson?.overrides?.find((o) => ['*.ts', '*.tsx', '*.js', '*.jsx'].every((ext) => o.files.includes(ext)));
57
55
  // check if it's a next app and has a parserOptions.project set in the eslint overrides
58
- return !!(((_c = (_b = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.targets) === null || _b === void 0 ? void 0 : _b['build']) === null || _c === void 0 ? void 0 : _c.executor) === '@nrwl/next:build' &&
59
- ((_d = esLintOverrides === null || esLintOverrides === void 0 ? void 0 : esLintOverrides.parserOptions) === null || _d === void 0 ? void 0 : _d.project));
56
+ return !!(projectConfig?.targets?.['build']?.executor === '@nrwl/next:build' &&
57
+ esLintOverrides?.parserOptions?.project);
60
58
  }
61
- function updateJestConfigExt(tree) {
62
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
63
- if (tree.exists('jest.config.js')) {
64
- tree.rename('jest.config.js', 'jest.config.ts');
59
+ async function updateJestConfigExt(tree) {
60
+ if (tree.exists('jest.config.js')) {
61
+ tree.rename('jest.config.js', 'jest.config.ts');
62
+ }
63
+ const projects = (0, devkit_1.getProjects)(tree);
64
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/jest:jest', (options, projectName, target, configuration) => {
65
+ const projectConfig = projects.get(projectName);
66
+ if (!options.jestConfig || !isJestConfigValid(tree, options)) {
67
+ return;
65
68
  }
66
- const projects = (0, devkit_1.getProjects)(tree);
67
- (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nrwl/jest:jest', (options, projectName, target, configuration) => {
68
- const projectConfig = projects.get(projectName);
69
- if (!options.jestConfig || !isJestConfigValid(tree, options)) {
70
- return;
71
- }
72
- addEsLintIgnoreComments(tree, options.jestConfig);
73
- const newJestConfigPath = options.jestConfig.replace('.js', '.ts');
74
- tree.rename(options.jestConfig, newJestConfigPath);
75
- const rootFiles = tree.children(projectConfig.root);
76
- for (const fileName of rootFiles) {
77
- if (fileName === 'tsconfig.json') {
78
- const filePath = (0, devkit_1.joinPathFragments)(projectConfig.root, fileName);
79
- const tsConfig = (0, devkit_1.readJson)(tree, filePath, {
80
- allowTrailingComma: true,
81
- disallowComments: false,
82
- });
83
- if (tsConfig.references) {
84
- for (const { path } of tsConfig.references) {
85
- // skip as editor.json should include everything anyway.
86
- if (path.endsWith('tsconfig.editor.json')) {
87
- continue;
88
- }
89
- if (path.endsWith('tsconfig.spec.json')) {
90
- const eslintPath = (0, devkit_1.joinPathFragments)(projectConfig.root, '.eslintrc.json');
91
- updateTsconfigSpec(tree, projectConfig, path, {
92
- isNextWithProjectParse: tree.exists(eslintPath)
93
- ? isNextWithProjectLint(projectConfig, (0, devkit_1.readJson)(tree, eslintPath))
94
- : false,
95
- tsConfigPath: filePath,
96
- });
97
- continue;
98
- }
99
- updateTsConfig(tree, (0, devkit_1.joinPathFragments)(projectConfig.root, path));
69
+ addEsLintIgnoreComments(tree, options.jestConfig);
70
+ const newJestConfigPath = options.jestConfig.replace('.js', '.ts');
71
+ tree.rename(options.jestConfig, newJestConfigPath);
72
+ const rootFiles = tree.children(projectConfig.root);
73
+ for (const fileName of rootFiles) {
74
+ if (fileName === 'tsconfig.json') {
75
+ const filePath = (0, devkit_1.joinPathFragments)(projectConfig.root, fileName);
76
+ const tsConfig = (0, devkit_1.readJson)(tree, filePath, {
77
+ allowTrailingComma: true,
78
+ disallowComments: false,
79
+ });
80
+ if (tsConfig.references) {
81
+ for (const { path } of tsConfig.references) {
82
+ // skip as editor.json should include everything anyway.
83
+ if (path.endsWith('tsconfig.editor.json')) {
84
+ continue;
100
85
  }
101
- }
102
- else {
103
- updateTsConfig(tree, filePath);
86
+ if (path.endsWith('tsconfig.spec.json')) {
87
+ const eslintPath = (0, devkit_1.joinPathFragments)(projectConfig.root, '.eslintrc.json');
88
+ updateTsconfigSpec(tree, projectConfig, path, {
89
+ isNextWithProjectParse: tree.exists(eslintPath)
90
+ ? isNextWithProjectLint(projectConfig, (0, devkit_1.readJson)(tree, eslintPath))
91
+ : false,
92
+ tsConfigPath: filePath,
93
+ });
94
+ continue;
95
+ }
96
+ updateTsConfig(tree, (0, devkit_1.joinPathFragments)(projectConfig.root, path));
104
97
  }
105
98
  }
99
+ else {
100
+ updateTsConfig(tree, filePath);
101
+ }
106
102
  }
107
- projectConfig.targets[target].options.jestConfig = newJestConfigPath;
108
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
109
- });
110
- yield (0, devkit_1.formatFiles)(tree);
103
+ }
104
+ projectConfig.targets[target].options.jestConfig = newJestConfigPath;
105
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, projectConfig);
111
106
  });
107
+ await (0, devkit_1.formatFiles)(tree);
112
108
  }
113
109
  exports.updateJestConfigExt = updateJestConfigExt;
114
110
  exports.default = updateJestConfigExt;
@@ -16,7 +16,7 @@ function updateConfigsJest28(tree) {
16
16
  const updatedConfig = updateJestConfig(tree.read(options.jestConfig, 'utf-8'));
17
17
  tree.write(options.jestConfig, updatedConfig);
18
18
  const projectConfigCheck = testFileForDep(updatedConfig);
19
- devDeps = Object.assign(Object.assign({}, devDeps), projectConfigCheck);
19
+ devDeps = { ...devDeps, ...projectConfigCheck };
20
20
  }
21
21
  });
22
22
  return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDeps);
@@ -24,8 +24,7 @@ function updateConfigsJest28(tree) {
24
24
  exports.updateConfigsJest28 = updateConfigsJest28;
25
25
  function updateJestConfig(config) {
26
26
  let content = tsquery_1.tsquery.replace(config, 'PropertyAssignment:has(Identifier[name="testURL"])', (node) => {
27
- var _a;
28
- const value = (_a = node === null || node === void 0 ? void 0 : node.initializer) === null || _a === void 0 ? void 0 : _a.getText();
27
+ const value = node?.initializer?.getText();
29
28
  return `testEnvironmentOptions: {url: ${value}}`;
30
29
  });
31
30
  content = tsquery_1.tsquery.replace(content, 'PropertyAssignment > Identifier[name="extraGlobals"]', () => {
@@ -33,8 +32,8 @@ function updateJestConfig(config) {
33
32
  });
34
33
  return tsquery_1.tsquery.replace(content, 'PropertyAssignment:has(Identifier[name="timers"])', (node) => {
35
34
  // must guard against non string properties as that means it's already been manually migrated
36
- if ((node === null || node === void 0 ? void 0 : node.initializer) && (0, typescript_1.isStringLiteralLike)(node.initializer)) {
37
- const value = node === null || node === void 0 ? void 0 : node.initializer.getText().trim();
35
+ if (node?.initializer && (0, typescript_1.isStringLiteralLike)(node.initializer)) {
36
+ const value = node?.initializer.getText().trim();
38
37
  // use .includes to ignore the different quotes (' " `)
39
38
  if (value.includes('fake') || value.includes('modern')) {
40
39
  return `fakeTimers: { enableGlobally: true }`;
@@ -58,12 +57,12 @@ function checkDeps(tree) {
58
57
  const rootJestConfig = (0, find_root_jest_files_1.findRootJestConfig)(tree);
59
58
  if (rootJestConfig) {
60
59
  const rootConfigCheck = testFileForDep(tree.read(rootJestConfig, 'utf-8'));
61
- devDeps = Object.assign(Object.assign({}, devDeps), rootConfigCheck);
60
+ devDeps = { ...devDeps, ...rootConfigCheck };
62
61
  }
63
62
  const rootJestPreset = (0, find_root_jest_files_1.findRootJestPreset)(tree);
64
63
  if (rootJestPreset) {
65
64
  const rootPresetCheck = testFileForDep(tree.read(rootJestPreset, 'utf-8'));
66
- devDeps = Object.assign(Object.assign({}, devDeps), rootPresetCheck);
65
+ devDeps = { ...devDeps, ...rootPresetCheck };
67
66
  }
68
67
  return devDeps;
69
68
  }
@@ -36,7 +36,7 @@ exports.updateTestsJest28 = updateTestsJest28;
36
36
  */
37
37
  function updateJestTimers(fileContents, legacyFakeTimersInConfig) {
38
38
  return tsquery_1.tsquery.replace(fileContents, 'CallExpression', (node) => {
39
- if (!(node === null || node === void 0 ? void 0 : node.getText().startsWith('jest.useFakeTimers'))) {
39
+ if (!node?.getText().startsWith('jest.useFakeTimers')) {
40
40
  return;
41
41
  }
42
42
  const timerType = node.getText();
@@ -68,10 +68,9 @@ function isTypedJestFnMock(node) {
68
68
  * jest.fn<number, [string, number, SomeType]>()
69
69
  */
70
70
  function isValid2Args(node) {
71
- var _a, _b;
72
- const r = (node === null || node === void 0 ? void 0 : node.typeArguments.length) === 2 &&
73
- (((_a = node.typeArguments[1]) === null || _a === void 0 ? void 0 : _a.kind) === ts.SyntaxKind.TupleType ||
74
- ((_b = node.typeArguments[1]) === null || _b === void 0 ? void 0 : _b.kind) === ts.SyntaxKind.ArrayType);
71
+ const r = node?.typeArguments.length === 2 &&
72
+ (node.typeArguments[1]?.kind === ts.SyntaxKind.TupleType ||
73
+ node.typeArguments[1]?.kind === ts.SyntaxKind.ArrayType);
75
74
  return r;
76
75
  }
77
76
  /**
@@ -82,10 +81,9 @@ function isValid2Args(node) {
82
81
  * jest.fn<() => Promise<string>>() is already valid, don't change it.
83
82
  */
84
83
  function isValid1Arg(node) {
85
- var _a, _b;
86
- const r = (node === null || node === void 0 ? void 0 : node.typeArguments.length) === 1 &&
87
- ((_a = node.typeArguments[0]) === null || _a === void 0 ? void 0 : _a.kind) !== ts.SyntaxKind.FunctionType &&
88
- ((_b = node.typeArguments[0]) === null || _b === void 0 ? void 0 : _b.kind) !== ts.SyntaxKind.TypeQuery;
84
+ const r = node?.typeArguments.length === 1 &&
85
+ node.typeArguments[0]?.kind !== ts.SyntaxKind.FunctionType &&
86
+ node.typeArguments[0]?.kind !== ts.SyntaxKind.TypeQuery;
89
87
  return r;
90
88
  }
91
89
  /**
@@ -93,20 +91,18 @@ function isValid1Arg(node) {
93
91
  * jest.fn<ReturnType<typeof add>, Parameters<typeof add>>();
94
92
  */
95
93
  function isValidTypeRef(node) {
96
- var _a, _b;
97
94
  const r = node.typeArguments[0].kind === ts.SyntaxKind.TypeReference &&
98
- !!((_b = (_a = node.typeArguments) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.typeArguments);
95
+ !!node.typeArguments?.[0]?.typeArguments;
99
96
  return r;
100
97
  }
101
98
  /**
102
99
  * has valid type args. prevent converting an already converted jest.fn<T>()
103
100
  */
104
101
  function isValidType(node) {
105
- var _a, _b, _c;
106
- const r = (node === null || node === void 0 ? void 0 : node.typeArguments.length) === 1 &&
107
- (((_a = node.typeArguments[0]) === null || _a === void 0 ? void 0 : _a.kind) === ts.SyntaxKind.FunctionType ||
108
- ((_b = node.typeArguments[0]) === null || _b === void 0 ? void 0 : _b.kind) === ts.SyntaxKind.TypeReference ||
109
- ((_c = node.typeArguments[0]) === null || _c === void 0 ? void 0 : _c.kind) === ts.SyntaxKind.TypeQuery ||
102
+ const r = node?.typeArguments.length === 1 &&
103
+ (node.typeArguments[0]?.kind === ts.SyntaxKind.FunctionType ||
104
+ node.typeArguments[0]?.kind === ts.SyntaxKind.TypeReference ||
105
+ node.typeArguments[0]?.kind === ts.SyntaxKind.TypeQuery ||
110
106
  node.parent.getText().includes('/** TODO:')); // has already been marked by a previous run.
111
107
  return r;
112
108
  }
@@ -1,40 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
3
  const devkit_1 = require("@nx/devkit");
5
4
  const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
- function default_1(tree) {
7
- var _a, _b, _c, _d;
8
- var _e;
9
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
- const nxJson = (0, devkit_1.readNxJson)(tree);
11
- const jestTargets = getJestTargetNames(tree);
12
- const hasProductionFileset = !!((_a = nxJson.namedInputs) === null || _a === void 0 ? void 0 : _a.production);
13
- if (jestTargets.size > 0 && hasProductionFileset) {
14
- const productionFileset = new Set(nxJson.namedInputs.production);
15
- for (const exclusion of [
16
- '!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)',
17
- '!{projectRoot}/tsconfig.spec.json',
18
- '!{projectRoot}/jest.config.[jt]s',
19
- ]) {
20
- productionFileset.add(exclusion);
21
- }
22
- nxJson.namedInputs.production = Array.from(productionFileset);
5
+ async function default_1(tree) {
6
+ const nxJson = (0, devkit_1.readNxJson)(tree);
7
+ const jestTargets = getJestTargetNames(tree);
8
+ const hasProductionFileset = !!nxJson.namedInputs?.production;
9
+ if (jestTargets.size > 0 && hasProductionFileset) {
10
+ const productionFileset = new Set(nxJson.namedInputs.production);
11
+ for (const exclusion of [
12
+ '!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)',
13
+ '!{projectRoot}/tsconfig.spec.json',
14
+ '!{projectRoot}/jest.config.[jt]s',
15
+ ]) {
16
+ productionFileset.add(exclusion);
23
17
  }
24
- for (const targetName of jestTargets) {
25
- (_b = nxJson.targetDefaults) !== null && _b !== void 0 ? _b : (nxJson.targetDefaults = {});
26
- const jestTargetDefaults = ((_c = (_e = nxJson.targetDefaults)[targetName]) !== null && _c !== void 0 ? _c : (_e[targetName] = {}));
27
- (_d = jestTargetDefaults.inputs) !== null && _d !== void 0 ? _d : (jestTargetDefaults.inputs = [
28
- 'default',
29
- hasProductionFileset ? '^production' : '^default',
30
- ...(tree.exists('jest.preset.js')
31
- ? ['{workspaceRoot}/jest.preset.js']
32
- : []),
33
- ]);
34
- }
35
- (0, devkit_1.updateNxJson)(tree, nxJson);
36
- yield (0, devkit_1.formatFiles)(tree);
37
- });
18
+ nxJson.namedInputs.production = Array.from(productionFileset);
19
+ }
20
+ for (const targetName of jestTargets) {
21
+ nxJson.targetDefaults ??= {};
22
+ const jestTargetDefaults = (nxJson.targetDefaults[targetName] ??= {});
23
+ jestTargetDefaults.inputs ??= [
24
+ 'default',
25
+ hasProductionFileset ? '^production' : '^default',
26
+ ...(tree.exists('jest.preset.js')
27
+ ? ['{workspaceRoot}/jest.preset.js']
28
+ : []),
29
+ ];
30
+ }
31
+ (0, devkit_1.updateNxJson)(tree, nxJson);
32
+ await (0, devkit_1.formatFiles)(tree);
38
33
  }
39
34
  exports.default = default_1;
40
35
  function getJestTargetNames(tree) {