@nx/jest 17.0.5 → 17.0.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 (40) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +4 -9
  3. package/generators.json +2 -2
  4. package/index.d.ts +1 -1
  5. package/index.js +1 -2
  6. package/migrations.json +0 -14
  7. package/package.json +4 -6
  8. package/src/generators/configuration/configuration.d.ts +0 -1
  9. package/src/generators/configuration/configuration.js +7 -42
  10. package/src/generators/configuration/files/jest.config.ts__tmpl__ +1 -1
  11. package/src/generators/configuration/files-angular/jest.config.ts__tmpl__ +1 -1
  12. package/src/generators/configuration/lib/create-files.d.ts +1 -1
  13. package/src/generators/configuration/lib/create-files.js +1 -2
  14. package/src/generators/configuration/lib/update-jestconfig.js +1 -6
  15. package/src/generators/configuration/lib/update-workspace.js +8 -1
  16. package/src/generators/configuration/schema.d.ts +0 -8
  17. package/src/generators/configuration/schema.json +1 -1
  18. package/src/generators/init/init.d.ts +3 -4
  19. package/src/generators/init/init.js +130 -66
  20. package/src/generators/init/schema.d.ts +8 -5
  21. package/src/generators/init/schema.json +20 -13
  22. package/src/utils/config/find-root-jest-files.js +0 -3
  23. package/src/utils/config/get-jest-projects.d.ts +1 -16
  24. package/src/utils/config/get-jest-projects.js +3 -98
  25. package/src/utils/versions.d.ts +1 -1
  26. package/src/utils/versions.js +1 -1
  27. package/plugin.d.ts +0 -1
  28. package/plugin.js +0 -6
  29. package/src/generators/configuration/lib/create-jest-config.d.ts +0 -3
  30. package/src/generators/configuration/lib/create-jest-config.js +0 -102
  31. package/src/generators/configuration/lib/ensure-dependencies.d.ts +0 -3
  32. package/src/generators/configuration/lib/ensure-dependencies.js +0 -34
  33. package/src/generators/configuration/lib/update-vscode-recommended-extensions.d.ts +0 -2
  34. package/src/generators/configuration/lib/update-vscode-recommended-extensions.js +0 -18
  35. package/src/migrations/update-17-1-0/move-options-to-target-defaults.d.ts +0 -2
  36. package/src/migrations/update-17-1-0/move-options-to-target-defaults.js +0 -117
  37. package/src/plugins/plugin.d.ts +0 -6
  38. package/src/plugins/plugin.js +0 -130
  39. package/src/utils/config/is-preset-cjs.d.ts +0 -2
  40. package/src/utils/config/is-preset-cjs.js +0 -15
@@ -1,16 +1,16 @@
1
1
  {
2
- "$schema": "https://json-schema.org/schema",
2
+ "$schema": "http://json-schema.org/schema",
3
3
  "$id": "NxJestInit",
4
4
  "cli": "nx",
5
5
  "title": "Jest init",
6
6
  "description": "Add Jest Configuration to a workspace.",
7
7
  "type": "object",
8
8
  "properties": {
9
- "skipFormat": {
10
- "description": "Skip formatting files.",
9
+ "babelJest": {
11
10
  "type": "boolean",
12
- "default": false,
13
- "x-priority": "internal"
11
+ "alias": "babel-jest",
12
+ "description": "Use `babel-jest` instead of `ts-jest`.",
13
+ "default": false
14
14
  },
15
15
  "skipPackageJson": {
16
16
  "type": "boolean",
@@ -18,17 +18,24 @@
18
18
  "description": "Do not add dependencies to `package.json`.",
19
19
  "x-priority": "internal"
20
20
  },
21
- "keepExistingVersions": {
21
+ "testEnvironment": {
22
+ "type": "string",
23
+ "enum": ["jsdom", "node", "none"],
24
+ "description": "The test environment for jest. This controls which jest-environment-* package is installed",
25
+ "default": "jsdom",
26
+ "x-priority": "important"
27
+ },
28
+ "js": {
22
29
  "type": "boolean",
23
- "x-priority": "internal",
24
- "description": "Keep existing dependencies versions",
25
- "default": false
30
+ "default": false,
31
+ "description": "Use JavaScript instead of TypeScript for config files"
26
32
  },
27
- "updatePackageScripts": {
33
+ "rootProject": {
34
+ "description": "initialize Jest for an application at the root of the workspace",
28
35
  "type": "boolean",
29
- "x-priority": "internal",
30
- "description": "Update `package.json` scripts with inferred targets",
31
- "default": false
36
+ "default": false,
37
+ "hidden": true,
38
+ "x-priority": "internal"
32
39
  }
33
40
  },
34
41
  "required": []
@@ -15,9 +15,6 @@ function findRootJestPreset(tree) {
15
15
  if (tree.exists('jest.preset.js')) {
16
16
  return 'jest.preset.js';
17
17
  }
18
- if (tree.exists('jest.preset.cjs')) {
19
- return 'jest.preset.cjs';
20
- }
21
18
  return null;
22
19
  }
23
20
  exports.findRootJestPreset = findRootJestPreset;
@@ -2,8 +2,7 @@
2
2
  * Get a list of paths to all the jest config files
3
3
  * using the Nx Jest executor.
4
4
  *
5
- * This is used to configure Jest multi-project support. To support projects
6
- * using inferred targets @see getJestProjectsAsync
5
+ * This is used to configure Jest multi-project support.
7
6
  *
8
7
  * To add a project not using the Nx Jest executor:
9
8
  * export default {
@@ -18,17 +17,3 @@ export declare function getJestProjects(): string[];
18
17
  * https://jestjs.io/docs/configuration#testpathignorepatterns-arraystring
19
18
  * */
20
19
  export declare function getNestedJestProjects(): string[];
21
- /**
22
- * Get a list of paths to all the jest config files
23
- * using the Nx Jest executor and `@nx/run:commands`
24
- * running `jest`.
25
- *
26
- * This is used to configure Jest multi-project support.
27
- *
28
- * To add a project not using the Nx Jest executor:
29
- * export default async () => ({
30
- * projects: [...(await getJestProjectsAsync()), '<rootDir>/path/to/jest.config.ts'];
31
- * });
32
- *
33
- **/
34
- export declare function getJestProjectsAsync(): Promise<string[]>;
@@ -1,10 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getJestProjectsAsync = exports.getNestedJestProjects = exports.getJestProjects = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- const file_utils_1 = require("nx/src/project-graph/file-utils");
3
+ exports.getNestedJestProjects = exports.getJestProjects = void 0;
6
4
  const path_1 = require("path");
7
- const yargs = require("yargs-parser");
5
+ const file_utils_1 = require("nx/src/project-graph/file-utils");
8
6
  function getJestConfigProjectPath(projectJestConfigPath) {
9
7
  return (0, path_1.join)('<rootDir>', projectJestConfigPath);
10
8
  }
@@ -12,8 +10,7 @@ function getJestConfigProjectPath(projectJestConfigPath) {
12
10
  * Get a list of paths to all the jest config files
13
11
  * using the Nx Jest executor.
14
12
  *
15
- * This is used to configure Jest multi-project support. To support projects
16
- * using inferred targets @see getJestProjectsAsync
13
+ * This is used to configure Jest multi-project support.
17
14
  *
18
15
  * To add a project not using the Nx Jest executor:
19
16
  * export default {
@@ -63,95 +60,3 @@ function getNestedJestProjects() {
63
60
  return ['/node_modules/'];
64
61
  }
65
62
  exports.getNestedJestProjects = getNestedJestProjects;
66
- /**
67
- * Get a list of paths to all the jest config files
68
- * using the Nx Jest executor and `@nx/run:commands`
69
- * running `jest`.
70
- *
71
- * This is used to configure Jest multi-project support.
72
- *
73
- * To add a project not using the Nx Jest executor:
74
- * export default async () => ({
75
- * projects: [...(await getJestProjectsAsync()), '<rootDir>/path/to/jest.config.ts'];
76
- * });
77
- *
78
- **/
79
- async function getJestProjectsAsync() {
80
- const graph = await (0, devkit_1.createProjectGraphAsync)({
81
- exitOnError: false,
82
- resetDaemonClient: true,
83
- });
84
- const jestConfigurations = new Set();
85
- for (const node of Object.values(graph.nodes)) {
86
- const projectConfig = node.data;
87
- if (!projectConfig.targets) {
88
- continue;
89
- }
90
- for (const targetConfiguration of Object.values(projectConfig.targets)) {
91
- if (targetConfiguration.executor === '@nx/jest:jest' ||
92
- targetConfiguration.executor === '@nrwl/jest:jest') {
93
- collectJestConfigFromJestExecutor(targetConfiguration, jestConfigurations);
94
- }
95
- else if (targetConfiguration.executor === 'nx:run-commands') {
96
- collectJestConfigFromRunCommandsExecutor(targetConfiguration, projectConfig.root, jestConfigurations);
97
- }
98
- }
99
- }
100
- return Array.from(jestConfigurations);
101
- }
102
- exports.getJestProjectsAsync = getJestProjectsAsync;
103
- function collectJestConfigFromJestExecutor(targetConfiguration, jestConfigurations) {
104
- if (targetConfiguration.options?.jestConfig) {
105
- jestConfigurations.add(getJestConfigProjectPath(targetConfiguration.options.jestConfig));
106
- }
107
- if (targetConfiguration.configurations) {
108
- for (const configurationObject of Object.values(targetConfiguration.configurations)) {
109
- if (configurationObject.jestConfig) {
110
- jestConfigurations.add(getJestConfigProjectPath(configurationObject.jestConfig));
111
- }
112
- }
113
- }
114
- }
115
- function collectJestConfigFromRunCommandsExecutor(targetConfiguration, projectRoot, jestConfigurations) {
116
- if (targetConfiguration.options?.command) {
117
- collectJestConfigFromCommand(targetConfiguration.options.command, targetConfiguration.options.cwd ?? projectRoot, jestConfigurations);
118
- }
119
- else if (targetConfiguration.options?.commands) {
120
- for (const command of targetConfiguration.options.commands) {
121
- const commandScript = typeof command === 'string' ? command : command.command;
122
- collectJestConfigFromCommand(commandScript, targetConfiguration.options.cwd ?? projectRoot, jestConfigurations);
123
- }
124
- }
125
- if (targetConfiguration.configurations) {
126
- for (const configurationObject of Object.values(targetConfiguration.configurations)) {
127
- if (configurationObject.command) {
128
- collectJestConfigFromCommand(configurationObject.command, configurationObject.cwd ?? projectRoot, jestConfigurations);
129
- }
130
- else if (configurationObject.commands) {
131
- for (const command of configurationObject.commands) {
132
- const commandScript = typeof command === 'string' ? command : command.command;
133
- collectJestConfigFromCommand(commandScript, configurationObject.cwd ?? projectRoot, jestConfigurations);
134
- }
135
- }
136
- }
137
- }
138
- }
139
- function collectJestConfigFromCommand(command, cwd, jestConfigurations) {
140
- const jestCommandRegex = /(?<=^|&)(?:[^&\r\n\s]* )*jest(?: [^&\r\n\s]*)*(?=$|&)/g;
141
- const matches = command.match(jestCommandRegex);
142
- if (!matches) {
143
- return;
144
- }
145
- for (const match of matches) {
146
- const parsed = yargs(match, {
147
- configuration: { 'strip-dashed': true },
148
- string: ['config'],
149
- });
150
- if (parsed.config) {
151
- jestConfigurations.add(getJestConfigProjectPath((0, path_1.join)(cwd, parsed.config)));
152
- }
153
- else {
154
- jestConfigurations.add(getJestConfigProjectPath(cwd));
155
- }
156
- }
157
- }
@@ -5,5 +5,5 @@ export declare const jestTypesVersion = "^29.4.0";
5
5
  export declare const tsJestVersion = "^29.1.0";
6
6
  export declare const tslibVersion = "^2.3.0";
7
7
  export declare const swcJestVersion = "0.2.20";
8
- export declare const typesNodeVersion = "18.16.9";
8
+ export declare const typesNodeVersion = "16.11.7";
9
9
  export declare const tsNodeVersion = "10.9.1";
@@ -8,5 +8,5 @@ exports.jestTypesVersion = '^29.4.0';
8
8
  exports.tsJestVersion = '^29.1.0';
9
9
  exports.tslibVersion = '^2.3.0';
10
10
  exports.swcJestVersion = '0.2.20';
11
- exports.typesNodeVersion = '18.16.9';
11
+ exports.typesNodeVersion = '16.11.7';
12
12
  exports.tsNodeVersion = '10.9.1';
package/plugin.d.ts DELETED
@@ -1 +0,0 @@
1
- export { createNodes, createDependencies, JestPluginOptions, } from './src/plugins/plugin';
package/plugin.js DELETED
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDependencies = exports.createNodes = void 0;
4
- var plugin_1 = require("./src/plugins/plugin");
5
- Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
6
- Object.defineProperty(exports, "createDependencies", { enumerable: true, get: function () { return plugin_1.createDependencies; } });
@@ -1,3 +0,0 @@
1
- import { type Tree } from '@nx/devkit';
2
- import type { NormalizedJestProjectSchema } from '../schema';
3
- export declare function createJestConfig(tree: Tree, options: Partial<NormalizedJestProjectSchema>, presetExt: 'cjs' | 'js'): Promise<void>;
@@ -1,102 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createJestConfig = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
6
- const find_root_jest_files_1 = require("../../../utils/config/find-root-jest-files");
7
- async function createJestConfig(tree, options, presetExt) {
8
- if (!tree.exists(`jest.preset.${presetExt}`)) {
9
- // preset is always js file.
10
- tree.write(`jest.preset.${presetExt}`, `
11
- const nxPreset = require('@nx/jest/preset').default;
12
-
13
- module.exports = { ...nxPreset }`);
14
- }
15
- if (options.rootProject) {
16
- // we don't want any config to be made because the `configurationGenerator` will do it.
17
- // will copy the template config file
18
- return;
19
- }
20
- const rootJestPath = (0, find_root_jest_files_1.findRootJestConfig)(tree);
21
- if (!rootJestPath) {
22
- // if there's not root jest config, we will create one and return
23
- // this can happen when:
24
- // - root jest config was renamed => in which case there is migration needed
25
- // - root project didn't have jest setup => again, no migration is needed
26
- generateGlobalConfig(tree, options.js);
27
- return;
28
- }
29
- if (tree.exists(rootJestPath)) {
30
- // moving from root project config to monorepo-style config
31
- const { nodes: projects } = await (0, devkit_1.createProjectGraphAsync)();
32
- const projectConfigurations = Object.values(projects);
33
- const rootProject = projectConfigurations.find((projectNode) => projectNode.data?.root === '.');
34
- // root project might have been removed,
35
- // if it's missing there's nothing to migrate
36
- if (rootProject) {
37
- const jestTarget = Object.entries(rootProject.data?.targets ?? {}).find(([_, t]) => ((t?.executor === '@nx/jest:jest' ||
38
- t?.executor === '@nrwl/jest:jest') &&
39
- t?.options?.jestConfig === rootJestPath) ||
40
- (t?.executor === 'nx:run-commands' && t?.options?.command === 'jest'));
41
- if (!jestTarget) {
42
- return;
43
- }
44
- const [jestTargetName, jestTargetConfigInGraph] = jestTarget;
45
- // if root project doesn't have jest target, there's nothing to migrate
46
- const rootProjectConfig = (0, devkit_1.readProjectConfiguration)(tree, rootProject.name);
47
- if (rootProjectConfig.targets?.['test']?.executor === 'nx:run-commands'
48
- ? rootProjectConfig.targets?.['test']?.command !== 'jest'
49
- : rootProjectConfig.targets?.['test']?.options?.jestConfig !==
50
- rootJestPath) {
51
- // Jest target has already been updated
52
- return;
53
- }
54
- const jestProjectConfig = `jest.config.${rootProjectConfig.projectType === 'application' ? 'app' : 'lib'}.${options.js ? 'js' : 'ts'}`;
55
- tree.rename(rootJestPath, jestProjectConfig);
56
- const nxJson = (0, devkit_1.readNxJson)(tree);
57
- const targetDefaults = (0, project_configuration_utils_1.readTargetDefaultsForTarget)(jestTargetName, nxJson.targetDefaults, jestTargetConfigInGraph.executor);
58
- const target = (rootProjectConfig.targets[jestTargetName] ??=
59
- jestTargetConfigInGraph.executor === 'nx:run-commands'
60
- ? { command: `jest --config ${jestProjectConfig}` }
61
- : {
62
- executor: jestTargetConfigInGraph.executor,
63
- options: {},
64
- });
65
- if (target.executor === '@nx/jest:jest') {
66
- target.options.jestConfig = jestProjectConfig;
67
- }
68
- if (targetDefaults?.cache === undefined) {
69
- target.cache = jestTargetConfigInGraph.cache;
70
- }
71
- if (targetDefaults?.inputs === undefined) {
72
- target.inputs = jestTargetConfigInGraph.inputs;
73
- }
74
- if (targetDefaults?.outputs === undefined) {
75
- target.outputs = jestTargetConfigInGraph.outputs;
76
- }
77
- if (targetDefaults?.dependsOn === undefined) {
78
- target.dependsOn = jestTargetConfigInGraph.dependsOn;
79
- }
80
- (0, devkit_1.updateProjectConfiguration)(tree, rootProject.name, rootProjectConfig);
81
- // generate new global config as it was move to project config or is missing
82
- generateGlobalConfig(tree, options.js);
83
- }
84
- }
85
- }
86
- exports.createJestConfig = createJestConfig;
87
- function generateGlobalConfig(tree, isJS) {
88
- const contents = isJS
89
- ? (0, devkit_1.stripIndents) `
90
- const { getJestProjectsAsync } = require('@nx/jest');
91
-
92
- module.exports = async () => ({
93
- projects: await getJestProjectsAsync()
94
- });`
95
- : (0, devkit_1.stripIndents) `
96
- import { getJestProjectsAsync } from '@nx/jest';
97
-
98
- export default async () => ({
99
- projects: await getJestProjectsAsync()
100
- });`;
101
- tree.write(`jest.config.${isJS ? 'js' : 'ts'}`, contents);
102
- }
@@ -1,3 +0,0 @@
1
- import { type Tree } from '@nx/devkit';
2
- import type { NormalizedJestProjectSchema } from '../schema';
3
- export declare function ensureDependencies(tree: Tree, options: Partial<NormalizedJestProjectSchema>): import("@nx/devkit").GeneratorCallback;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ensureDependencies = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- const versions_1 = require("../../../utils/versions");
6
- function ensureDependencies(tree, options) {
7
- const dependencies = {
8
- tslib: versions_1.tslibVersion,
9
- };
10
- const devDeps = {
11
- // because the default jest-preset uses ts-jest,
12
- // jest will throw an error if it's not installed
13
- // even if not using it in overriding transformers
14
- 'ts-jest': versions_1.tsJestVersion,
15
- };
16
- if (options.testEnvironment !== 'none') {
17
- devDeps[`jest-environment-${options.testEnvironment}`] = versions_1.jestVersion;
18
- }
19
- if (!options.js) {
20
- devDeps['ts-node'] = versions_1.tsNodeVersion;
21
- devDeps['@types/jest'] = versions_1.jestTypesVersion;
22
- devDeps['@types/node'] = versions_1.typesNodeVersion;
23
- }
24
- if (options.compiler === 'babel' || options.babelJest) {
25
- devDeps['babel-jest'] = versions_1.babelJestVersion;
26
- // in some cases @nx/js will not already be present i.e. node only projects
27
- devDeps['@nx/js'] = versions_1.nxVersion;
28
- }
29
- else if (options.compiler === 'swc') {
30
- devDeps['@swc/jest'] = versions_1.swcJestVersion;
31
- }
32
- return (0, devkit_1.addDependenciesToPackageJson)(tree, dependencies, devDeps);
33
- }
34
- exports.ensureDependencies = ensureDependencies;
@@ -1,2 +0,0 @@
1
- import { type Tree } from '@nx/devkit';
2
- export declare function updateVsCodeRecommendedExtensions(host: Tree): void;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateVsCodeRecommendedExtensions = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- function updateVsCodeRecommendedExtensions(host) {
6
- if (!host.exists('.vscode/extensions.json')) {
7
- return;
8
- }
9
- (0, devkit_1.updateJson)(host, '.vscode/extensions.json', (json) => {
10
- json.recommendations = json.recommendations || [];
11
- const extension = 'firsttris.vscode-jest-runner';
12
- if (!json.recommendations.includes(extension)) {
13
- json.recommendations.push(extension);
14
- }
15
- return json;
16
- });
17
- }
18
- exports.updateVsCodeRecommendedExtensions = updateVsCodeRecommendedExtensions;
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export default function update(tree: Tree): Promise<void>;
@@ -1,117 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const devkit_1 = require("@nx/devkit");
4
- const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
5
- const project_configuration_utils_1 = require("nx/src/project-graph/utils/project-configuration-utils");
6
- async function update(tree) {
7
- const nxJson = (0, devkit_1.readNxJson)(tree);
8
- // Don't override anything if there are already target defaults for jest
9
- if (nxJson.targetDefaults?.['@nx/jest:jest']) {
10
- return;
11
- }
12
- nxJson.targetDefaults ??= {};
13
- /**
14
- * A set of targets which does not use any other executors
15
- */
16
- const jestTargets = new Set();
17
- const graph = await (0, devkit_1.createProjectGraphAsync)();
18
- (0, executor_options_utils_1.forEachExecutorOptionsInGraph)(graph, '@nx/jest:jest', (value, proj, targetName) => {
19
- jestTargets.add(targetName);
20
- });
21
- // Workspace does not use jest?
22
- if (jestTargets.size === 0) {
23
- return;
24
- }
25
- // Use the project graph so targets which are inferred are considered
26
- const projects = graph.nodes;
27
- const projectMap = (0, devkit_1.getProjects)(tree);
28
- const jestDefaults = (nxJson.targetDefaults['@nx/jest:jest'] = {});
29
- // All jest targets have the same name
30
- if (jestTargets.size === 1) {
31
- const targetName = Array.from(jestTargets)[0];
32
- if (nxJson.targetDefaults[targetName]) {
33
- Object.assign(jestDefaults, nxJson.targetDefaults[targetName]);
34
- }
35
- }
36
- jestDefaults.cache ??= true;
37
- const inputs = ['default'];
38
- inputs.push(nxJson.namedInputs?.production ? '^production' : '^default');
39
- if (tree.exists('jest.preset.js')) {
40
- inputs.push('{workspaceRoot}/jest.preset.js');
41
- }
42
- jestDefaults.inputs ??= inputs;
43
- // Remember if there were already defaults so we don't assume the executor default
44
- const passWithNoTestsPreviouslyInDefaults = jestDefaults.options?.passWithNoTests !== undefined;
45
- const ciCiPreviouslyInDefaults = jestDefaults.configurations?.ci?.ci !== undefined;
46
- const ciCodeCoveragePreviouslyInDefaults = jestDefaults.configurations?.ci?.codeCoverage !== undefined;
47
- jestDefaults.options ??= {};
48
- jestDefaults.options.passWithNoTests ??= true;
49
- jestDefaults.configurations ??= {};
50
- jestDefaults.configurations.ci ??= {};
51
- jestDefaults.configurations.ci.ci ??= true;
52
- jestDefaults.configurations.ci.codeCoverage ??= true;
53
- // Cleanup old target defaults
54
- for (const [targetDefaultKey, targetDefault] of Object.entries(nxJson.targetDefaults)) {
55
- if (!isTargetDefaultUsed(targetDefault, nxJson.targetDefaults, projects, projectMap)) {
56
- delete nxJson.targetDefaults[targetDefaultKey];
57
- }
58
- }
59
- (0, devkit_1.updateNxJson)(tree, nxJson);
60
- (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/jest:jest', (value, proj, targetName, configuration) => {
61
- const projConfig = projectMap.get(proj);
62
- if (!configuration) {
63
- // Options
64
- if (value.passWithNoTests === jestDefaults.options.passWithNoTests) {
65
- delete projConfig.targets[targetName].options.passWithNoTests;
66
- }
67
- else if (!passWithNoTestsPreviouslyInDefaults) {
68
- projConfig.targets[targetName].options.passWithNoTests ??= false;
69
- }
70
- if (Object.keys(projConfig.targets[targetName].options).length === 0) {
71
- delete projConfig.targets[targetName].options;
72
- }
73
- }
74
- else if (configuration === 'ci') {
75
- // CI Config
76
- if (value.ci === jestDefaults.configurations.ci.ci) {
77
- delete projConfig.targets[targetName].configurations.ci.ci;
78
- }
79
- else if (ciCiPreviouslyInDefaults) {
80
- projConfig.targets[targetName].configurations.ci.ci ??= false;
81
- }
82
- if (value.codeCoverage === jestDefaults.configurations.ci.codeCoverage) {
83
- delete projConfig.targets[targetName].configurations.ci.codeCoverage;
84
- }
85
- else if (ciCodeCoveragePreviouslyInDefaults) {
86
- projConfig.targets[targetName].configurations.ci.codeCoverage ??=
87
- false;
88
- }
89
- if (Object.keys(projConfig.targets[targetName].configurations.ci)
90
- .length === 0) {
91
- delete projConfig.targets[targetName].configurations.ci;
92
- }
93
- if (Object.keys(projConfig.targets[targetName].configurations).length ===
94
- 0) {
95
- delete projConfig.targets[targetName].configurations;
96
- }
97
- }
98
- (0, devkit_1.updateProjectConfiguration)(tree, proj, projConfig);
99
- });
100
- await (0, devkit_1.formatFiles)(tree);
101
- }
102
- exports.default = update;
103
- /**
104
- * Checks every target on every project to see if one of them uses the target default
105
- */
106
- function isTargetDefaultUsed(targetDefault, targetDefaults, projects, projectMap) {
107
- for (const p of Object.values(projects)) {
108
- for (const targetName in p.data?.targets ?? {}) {
109
- if ((0, project_configuration_utils_1.readTargetDefaultsForTarget)(targetName, targetDefaults,
110
- // It might seem like we should use the graph here too but we don't want to pass an executor which was processed in the graph
111
- projectMap.get(p.name)?.targets?.[targetName]?.executor) === targetDefault) {
112
- return true;
113
- }
114
- }
115
- }
116
- return false;
117
- }
@@ -1,6 +0,0 @@
1
- import { CreateDependencies, CreateNodes } from '@nx/devkit';
2
- export interface JestPluginOptions {
3
- targetName?: string;
4
- }
5
- export declare const createDependencies: CreateDependencies;
6
- export declare const createNodes: CreateNodes<JestPluginOptions>;