@nx/jest 24.0.0 → 24.0.1

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.
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "extends": "<%= extendedConfig %>",
3
3
  "compilerOptions": {
4
- "outDir": "<%= outDir %>",<% if (module) { %>
4
+ "outDir": "<%= outDir %>",<% if (rootDir) { %>
5
+ "rootDir": "<%= rootDir %>",<% } if (module) { %>
5
6
  "module": "<%= module %>",<% } if (module === 'commonjs') { %>
6
7
  "moduleResolution": "<%= moduleResolution %>",<% } if (isolatedModules) { %>
7
8
  "isolatedModules": true,<% } if (supportTsx) { %>
@@ -56,6 +56,9 @@ function createFiles(tree, options, presetExt) {
56
56
  const isolatedModules = options.isTsSolutionSetup &&
57
57
  transformer === 'ts-jest' &&
58
58
  moduleResolution === 'node10';
59
+ // ts-jest drops `composite` and, with `isolatedModules`, compiles each test
60
+ // file alone. TypeScript 6 then fails with TS5011 unless `rootDir` is set.
61
+ const rootDir = options.isTsSolutionSetup && transformer === 'ts-jest' ? '.' : undefined;
59
62
  (0, devkit_1.generateFiles)(tree, (0, path_1.join)(__dirname, commonFilesFolder), projectConfig.root, {
60
63
  tmpl: '',
61
64
  ...options,
@@ -74,6 +77,7 @@ function createFiles(tree, options, presetExt) {
74
77
  outDir: options.isTsSolutionSetup
75
78
  ? `./out-tsc/jest`
76
79
  : `${rootOffset}dist/out-tsc`,
80
+ rootDir,
77
81
  module: usesTsJestModuleSettings ? 'commonjs' : undefined,
78
82
  moduleResolution,
79
83
  isolatedModules,
@@ -1,4 +1,4 @@
1
- import { type Tree } from '@nx/devkit';
1
+ import type { Tree } from '@nx/devkit';
2
2
  import { type JestPresetExtension } from '../../../utils/config/config-file';
3
3
  import type { NormalizedJestProjectSchema } from '../schema';
4
4
  export declare function writeRootJestPreset(tree: Tree, presetExt: JestPresetExtension): void;
@@ -2,10 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.writeRootJestPreset = writeRootJestPreset;
4
4
  exports.createJestConfig = createJestConfig;
5
- const devkit_1 = require("@nx/devkit");
6
5
  const config_file_1 = require("../../../utils/config/config-file");
7
- const internal_1 = require("@nx/js/internal");
8
- const internal_2 = require("@nx/devkit/internal");
9
6
  function writeRootJestPreset(tree, presetExt) {
10
7
  if (!tree.exists(`jest.preset.${presetExt}`)) {
11
8
  if (presetExt === 'mjs') {
@@ -28,72 +25,8 @@ async function createJestConfig(tree, options, presetExt) {
28
25
  // will copy the template config file
29
26
  return;
30
27
  }
31
- const rootJestPath = (0, config_file_1.findRootJestConfig)(tree);
32
- if (!rootJestPath) {
33
- // if there's not root jest config, we will create one and return
34
- // this can happen when:
35
- // - root jest config was renamed => in which case there is migration needed
36
- // - root project didn't have jest setup => again, no migration is needed
28
+ if (!(0, config_file_1.findRootJestConfig)(tree)) {
37
29
  generateGlobalConfig(tree, options.js);
38
- return;
39
- }
40
- if (tree.exists(rootJestPath)) {
41
- // moving from root project config to monorepo-style config
42
- const { nodes: projects } = await (0, devkit_1.createProjectGraphAsync)();
43
- const projectConfigurations = Object.values(projects);
44
- const rootProject = projectConfigurations.find((projectNode) => projectNode.data?.root === '.');
45
- // root project might have been removed,
46
- // if it's missing there's nothing to migrate
47
- if (rootProject) {
48
- const jestTarget = Object.entries(rootProject.data?.targets ?? {}).find(([_, t]) => ((t?.executor === '@nx/jest:jest' ||
49
- t?.executor === '@nrwl/jest:jest') &&
50
- t?.options?.jestConfig === rootJestPath) ||
51
- (t?.executor === 'nx:run-commands' && t?.options?.command === 'jest'));
52
- if (!jestTarget) {
53
- return;
54
- }
55
- const [jestTargetName, jestTargetConfigInGraph] = jestTarget;
56
- // if root project doesn't have jest target, there's nothing to migrate
57
- const rootProjectConfig = (0, devkit_1.readProjectConfiguration)(tree, rootProject.name);
58
- if (rootProjectConfig.targets?.['test']?.executor === 'nx:run-commands'
59
- ? rootProjectConfig.targets?.['test']?.command !== 'jest'
60
- : rootProjectConfig.targets?.['test']?.options?.jestConfig !==
61
- rootJestPath) {
62
- // Jest target has already been updated
63
- return;
64
- }
65
- const jestProjectConfig = `jest.config.${(0, internal_1.getProjectType)(tree, rootProjectConfig.root, rootProjectConfig.projectType) === 'application'
66
- ? 'app'
67
- : 'lib'}.${options.js ? 'js' : 'ts'}`;
68
- tree.rename(rootJestPath, jestProjectConfig);
69
- const nxJson = (0, devkit_1.readNxJson)(tree);
70
- const targetDefaults = (0, internal_2.readTargetDefaultsForTarget)(jestTargetName, nxJson.targetDefaults, jestTargetConfigInGraph.executor);
71
- const target = (rootProjectConfig.targets[jestTargetName] ??=
72
- jestTargetConfigInGraph.executor === 'nx:run-commands'
73
- ? { command: `jest --config ${jestProjectConfig}` }
74
- : {
75
- executor: jestTargetConfigInGraph.executor,
76
- options: {},
77
- });
78
- if (target.executor === '@nx/jest:jest') {
79
- target.options.jestConfig = jestProjectConfig;
80
- }
81
- if (targetDefaults?.cache === undefined) {
82
- target.cache = jestTargetConfigInGraph.cache;
83
- }
84
- if (targetDefaults?.inputs === undefined) {
85
- target.inputs = jestTargetConfigInGraph.inputs;
86
- }
87
- if (targetDefaults?.outputs === undefined) {
88
- target.outputs = jestTargetConfigInGraph.outputs;
89
- }
90
- if (targetDefaults?.dependsOn === undefined) {
91
- target.dependsOn = jestTargetConfigInGraph.dependsOn;
92
- }
93
- (0, devkit_1.updateProjectConfiguration)(tree, rootProject.name, rootProjectConfig);
94
- // generate new global config as it was move to project config or is missing
95
- generateGlobalConfig(tree, options.js);
96
- }
97
30
  }
98
31
  }
99
32
  function generateGlobalConfig(tree, isJS) {
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateTsConfig = updateTsConfig;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
5
6
  const internal_1 = require("@nx/js/internal");
6
7
  function updateTsConfig(host, options) {
7
8
  const { root, projectType: _projectType } = (0, devkit_1.readProjectConfiguration)(host, options.project);
@@ -55,9 +56,31 @@ function updateTsConfig(host, options) {
55
56
  json.exclude = [...uniqueExclude];
56
57
  return json;
57
58
  });
59
+ // A composite spec config reaches runtime sources only through a project
60
+ // reference. Skip it when the runtime config references the spec config.
61
+ const specTsconfigPath = (0, devkit_1.joinPathFragments)(root, 'tsconfig.spec.json');
62
+ const runtimeReference = `./${path_1.posix.relative(root, runtimeTsconfigPath)}`;
63
+ if (options.isTsSolutionSetup &&
64
+ canBeReferencedBy(host, runtimeTsconfigPath, specTsconfigPath)) {
65
+ (0, devkit_1.updateJson)(host, specTsconfigPath, (json) => {
66
+ json.references ??= [];
67
+ if (!json.references.some((r) => r.path === runtimeReference)) {
68
+ json.references.push({ path: runtimeReference });
69
+ }
70
+ return json;
71
+ });
72
+ }
58
73
  }
59
74
  else {
60
75
  devkit_1.logger.warn(`Couldn't find a runtime tsconfig file at ${runtimeTsconfigPath} to exclude the test files from. ` +
61
76
  `If you're using a different filename for your runtime tsconfig, please provide it with the '--runtimeTsconfigFileName' flag.`);
62
77
  }
63
78
  }
79
+ function canBeReferencedBy(tree, tsconfigPath, referrerPath) {
80
+ const ts = (0, internal_1.ensureTypescript)();
81
+ const host = (0, internal_1.createTreeParseConfigHost)(tree);
82
+ const { options, projectReferences } = ts.parseJsonConfigFileContent(ts.readConfigFile(tsconfigPath, host.readFile).config, host, path_1.posix.dirname(tsconfigPath));
83
+ return (options.composite === true &&
84
+ !options.noEmit &&
85
+ !projectReferences?.some((r) => ts.resolveProjectReferencePath(r) === referrerPath));
86
+ }
@@ -1,4 +1,4 @@
1
- import type { Tree } from '@nx/devkit';
1
+ import { type Tree } from '@nx/devkit';
2
2
  export default function update(tree: Tree): Promise<{
3
3
  nextSteps?: string[];
4
4
  agentContext?: string[];
@@ -1,10 +1,225 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = update;
4
+ const devkit_1 = require("@nx/devkit");
4
5
  const internal_1 = require("@nx/devkit/internal");
6
+ const node_path_1 = require("node:path");
7
+ const node_util_1 = require("node:util");
8
+ const config_file_1 = require("../../utils/config/config-file");
9
+ const removedExecutors = ['@nx/jest:jest', '@nrwl/jest:jest'];
10
+ // The removed executor set this on every run; @nx/jest/plugin sets the same value
11
+ const tsNodeCompilerOptions = JSON.stringify({
12
+ moduleResolution: 'node10',
13
+ module: 'commonjs',
14
+ customConditions: null,
15
+ });
16
+ const isBoolean = (value) => typeof value === 'boolean';
17
+ const isPositiveInteger = (value) => Number.isSafeInteger(value) && value > 0;
18
+ /**
19
+ * The only options a rewritten target may set. Generators wrote jestConfig,
20
+ * tsConfig, passWithNoTests, ci and codeCoverage. Jest 29 and 30 read the other
21
+ * flags from --name=value as the values the executor passed to runCLI.
22
+ */
23
+ const acceptedOptions = new Map([
24
+ ['jestConfig', isPlainPath],
25
+ ['tsConfig', (value) => typeof value === 'string'],
26
+ ['codeCoverage', isBoolean],
27
+ ['bail', isBoolean],
28
+ ['ci', isBoolean],
29
+ ['detectOpenHandles', isBoolean],
30
+ ['forceExit', isBoolean],
31
+ ['logHeapUsage', isBoolean],
32
+ ['passWithNoTests', isBoolean],
33
+ ['runInBand', isBoolean],
34
+ ['silent', isBoolean],
35
+ ['maxWorkers', isPositiveInteger],
36
+ ['testTimeout', isPositiveInteger],
37
+ ]);
5
38
  function update(tree) {
6
- return (0, internal_1.migrateRemovedExecutors)(tree, ['@nx/jest:jest', '@nrwl/jest:jest'], async (tree, options) => {
7
- const { convertToInferred } = require('../../generators/convert-to-inferred/convert-to-inferred');
8
- return convertToInferred(tree, options);
39
+ return (0, internal_1.migrateRemovedExecutors)(tree, removedExecutors, async (tree, options) => {
40
+ const converter = require('../../generators/convert-to-inferred/convert-to-inferred');
41
+ const unconverted = rewriteTargetsWithUndetectedConfig(tree);
42
+ try {
43
+ return await converter.convertToInferred(tree, options);
44
+ }
45
+ finally {
46
+ restoreTargets(tree, unconverted);
47
+ }
9
48
  });
10
49
  }
50
+ /**
51
+ * @nx/jest/plugin infers a project's target only from `jest.config.<ext>` in
52
+ * its root, so a target running another config becomes an explicit command.
53
+ * A target that can't be rewritten is removed and returned, because the
54
+ * converter would switch it to the project's `jest.config.<ext>`.
55
+ */
56
+ function rewriteTargetsWithUndetectedConfig(tree) {
57
+ const targetDefaults = (0, devkit_1.readNxJson)(tree)?.targetDefaults;
58
+ const unconvertedByProject = new Map();
59
+ for (const [projectName, project] of (0, devkit_1.getProjects)(tree)) {
60
+ const unconverted = {};
61
+ let changed = false;
62
+ for (const [targetName, target] of Object.entries(project.targets ?? {})) {
63
+ if (!removedExecutors.includes(target.executor)) {
64
+ continue;
65
+ }
66
+ const readDefaults = (executor) => (0, internal_1.readTargetDefaultsForTarget)(targetName, targetDefaults, executor, {
67
+ projectName,
68
+ projectNode: { name: projectName, type: 'lib', data: project },
69
+ });
70
+ let runsUndetectedConfig = false;
71
+ try {
72
+ const executorDefaults = readDefaults(target.executor);
73
+ const resolved = resolveTarget(target, executorDefaults, project, `${projectName}:${targetName}`);
74
+ const jestConfig = resolved.options?.jestConfig;
75
+ if (!jestConfig || isProjectRootJestConfig(jestConfig, project.root)) {
76
+ continue;
77
+ }
78
+ runsUndetectedConfig = true;
79
+ const rewritten = toRunCommandsTarget(resolved);
80
+ assertDefaultsKeepTarget(rewritten, executorDefaults, readDefaults('nx:run-commands'));
81
+ project.targets[targetName] = rewritten;
82
+ changed = true;
83
+ }
84
+ catch (error) {
85
+ devkit_1.logger.warn(`Could not rewrite target "${targetName}" in project "${projectName}" to run Jest with its config file: ${String(error)}`);
86
+ if (runsUndetectedConfig) {
87
+ unconverted[targetName] = target;
88
+ delete project.targets[targetName];
89
+ changed = true;
90
+ }
91
+ }
92
+ }
93
+ if (changed) {
94
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
95
+ }
96
+ if (Object.keys(unconverted).length) {
97
+ unconvertedByProject.set(projectName, unconverted);
98
+ }
99
+ }
100
+ return unconvertedByProject;
101
+ }
102
+ function restoreTargets(tree, targetsByProject) {
103
+ for (const [projectName, targets] of targetsByProject) {
104
+ // Read again to keep what the converter did to sibling targets
105
+ const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
106
+ project.targets = { ...project.targets, ...targets };
107
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
108
+ }
109
+ }
110
+ /**
111
+ * The target merged with the defaults the removed executor received, with Nx
112
+ * tokens resolved.
113
+ */
114
+ function resolveTarget(target, defaults, project, key) {
115
+ const resolved = (0, internal_1.mergeTargetConfigurations)(structuredClone(target), structuredClone(defaults ?? {}));
116
+ if (resolved.options) {
117
+ resolved.options = (0, internal_1.resolveNxTokensInOptions)(resolved.options, project, key);
118
+ }
119
+ for (const name of Object.keys(resolved.configurations ?? {})) {
120
+ resolved.configurations[name] = (0, internal_1.resolveNxTokensInOptions)(resolved.configurations[name], project, `${key}:${name}`);
121
+ }
122
+ return resolved;
123
+ }
124
+ /**
125
+ * Target defaults are matched by executor, so the rewritten target can get
126
+ * entries the removed executor never did. They must not change it.
127
+ */
128
+ function assertDefaultsKeepTarget(target, executorDefaults, runCommandsDefaults) {
129
+ if (!runCommandsDefaults) {
130
+ return;
131
+ }
132
+ // The executor got these entries too, and the target holds their values
133
+ // translated for Jest
134
+ if ((0, node_util_1.isDeepStrictEqual)(executorDefaults, runCommandsDefaults)) {
135
+ return;
136
+ }
137
+ if (!(0, node_util_1.isDeepStrictEqual)(withDefaults(target, runCommandsDefaults), withDefaults(target, {}))) {
138
+ throw new Error('The target defaults that apply to nx:run-commands targets would change it.');
139
+ }
140
+ }
141
+ // Resolves '...' spreads too, and drops the undefined values the merge leaves
142
+ function withDefaults(target, defaults) {
143
+ return JSON.parse(JSON.stringify((0, internal_1.mergeTargetConfigurations)(structuredClone(target), structuredClone(defaults), undefined, undefined, undefined, false)));
144
+ }
145
+ function isProjectRootJestConfig(jestConfig, projectRoot) {
146
+ const path = node_path_1.posix.normalize(jestConfig);
147
+ return config_file_1.jestConfigExtensions.some((ext) => path === node_path_1.posix.join(projectRoot, `jest.config.${ext}`));
148
+ }
149
+ // Relative, and left unchanged by sh, cmd.exe and nx:run-commands
150
+ function isPlainPath(value) {
151
+ return typeof value === 'string' && /^[\w@+.-][\w@+./-]*$/.test(value);
152
+ }
153
+ function assertAcceptedOptions(options) {
154
+ for (const [name, value] of Object.entries(options)) {
155
+ if (!acceptedOptions.get(name)?.(value)) {
156
+ throw new Error(`The rewrite does not accept the "${name}" option set to ${JSON.stringify(value)}.`);
157
+ }
158
+ }
159
+ }
160
+ // jestConfig becomes the command, and the executor never passed tsConfig to Jest
161
+ function toJestOptions({ jestConfig: _jestConfig, tsConfig: _tsConfig, codeCoverage, ...flags }) {
162
+ return codeCoverage === undefined
163
+ ? flags
164
+ : { ...flags, coverage: codeCoverage };
165
+ }
166
+ // The leading ./ is what the move generator rewrites for a root project
167
+ function jestCommand(jestConfig) {
168
+ return `jest --config ${(0, internal_1.toProjectRelativePath)(node_path_1.posix.normalize(jestConfig), '.')}`;
169
+ }
170
+ function optionsFor(target, configuration) {
171
+ return {
172
+ ...target.options,
173
+ ...(configuration ? target.configurations[configuration] : {}),
174
+ };
175
+ }
176
+ function toRunCommandsTarget(target) {
177
+ const { executor: _executor, options, configurations, ...rest } = target;
178
+ const configurationNames = Object.keys(configurations ?? {});
179
+ for (const values of [options, ...Object.values(configurations ?? {})]) {
180
+ assertAcceptedOptions(values);
181
+ }
182
+ for (const name of [undefined, ...configurationNames]) {
183
+ const values = optionsFor(target, name);
184
+ // runCLI accepted this pair, but Jest's CLI rejects it
185
+ if (values.runInBand === true && 'maxWorkers' in values) {
186
+ throw new Error('Jest rejects runInBand with maxWorkers on its CLI.');
187
+ }
188
+ }
189
+ const rewritten = {
190
+ executor: 'nx:run-commands',
191
+ ...rest,
192
+ options: {
193
+ command: jestCommand(options.jestConfig),
194
+ // The executor ran from where nx started, usually the workspace root.
195
+ // Set explicitly, so an nx:run-commands default's cwd can't apply.
196
+ cwd: '.',
197
+ env: { TS_NODE_COMPILER_OPTIONS: tsNodeCompilerOptions },
198
+ ...toJestOptions(options),
199
+ },
200
+ };
201
+ if (configurations) {
202
+ rewritten.configurations = Object.fromEntries(configurationNames.map((name) => {
203
+ const { jestConfig } = configurations[name];
204
+ return [
205
+ name,
206
+ {
207
+ ...(jestConfig ? { command: jestCommand(jestConfig) } : {}),
208
+ ...toJestOptions(configurations[name]),
209
+ },
210
+ ];
211
+ }));
212
+ }
213
+ const outputOptions = [
214
+ ...(rest.outputs ?? []).join(' ').matchAll(/\{options\.(\w+)/g),
215
+ ].map(([, name]) => name);
216
+ for (const name of [undefined, ...configurationNames]) {
217
+ const before = optionsFor(target, name);
218
+ const after = optionsFor(rewritten, name);
219
+ const changed = outputOptions.find((option) => !(0, node_util_1.isDeepStrictEqual)(before[option], after[option]));
220
+ if (changed) {
221
+ throw new Error(`An output reads the "${changed}" option, which the rewrite changes.`);
222
+ }
223
+ }
224
+ return rewritten;
225
+ }
@@ -2,6 +2,22 @@
2
2
 
3
3
  Nx 24 removes the `@nx/jest:jest` executor and its `@nrwl/jest:jest` alias. The migration registers `@nx/jest/plugin` in `nx.json` and converts the targets that use those executors to inferred tasks. Options the plugin does not infer stay on the target. A target with nothing left to override is removed from project configuration. When several projects share the same remaining options, those options move to a `targetDefaults` entry scoped to the plugin. `targetDefaults` entries keyed by a removed executor are removed once no target uses that executor.
4
4
 
5
+ The plugin only infers a target from `jest.config.<ext>` in the project root. A target that runs any other config file, such as a root project's `jest.config.app.ts`, becomes an `nx:run-commands` target that runs `jest --config <file>` from the workspace root. It keeps the options, configurations and target defaults it used. The executor ran Jest from the directory `nx` started in, so a run started from another directory now uses the workspace root too.
6
+
7
+ The rewrite accepts only these options, in the target and in each configuration:
8
+
9
+ - `jestConfig`, set to a relative path made of ASCII letters, digits and `_ @ + . / -`. A configuration's `jestConfig` becomes its own command.
10
+ - `codeCoverage`, `bail`, `ci`, `detectOpenHandles`, `forceExit`, `logHeapUsage`, `passWithNoTests`, `runInBand` and `silent`, set to `true` or `false`. `codeCoverage` becomes `--coverage`.
11
+ - `maxWorkers` and `testTimeout`, set to a positive integer.
12
+ - `tsConfig`, which Jest never read. The rewrite drops it.
13
+
14
+ The target keeps the removed executor, and the migration lists it, in these cases:
15
+
16
+ - It sets any other option, or sets an accepted option to another kind of value.
17
+ - It sets `runInBand: true` together with `maxWorkers`, also through a configuration. Jest's CLI rejects that pair.
18
+ - An output reads an option the rewrite removes or renames, such as `{options.tsConfig}`.
19
+ - `targetDefaults` that apply to `nx:run-commands` targets would change it.
20
+
5
21
  The migration lists the targets the converter cannot convert safely. In agentic runs, an AI prompt finishes them and validates the project graph.
6
22
 
7
23
  #### Sample code changes
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * Get a list of paths to all the jest config files
3
- * using the Nx Jest executor and `@nx/run:commands`
4
- * running `jest`.
3
+ * used by `nx:run-commands` targets running `jest`,
4
+ * including the targets `@nx/jest/plugin` infers.
5
5
  *
6
6
  * This is used to configure Jest multi-project support.
7
7
  *
8
- * To add a project not using the Nx Jest executor:
8
+ * To add a project without such a target:
9
9
  * export default async () => ({
10
10
  * projects: [...(await getJestProjectsAsync()), '<rootDir>/path/to/jest.config.ts'];
11
11
  * });
@@ -10,12 +10,12 @@ function getJestConfigProjectPath(projectJestConfigPath) {
10
10
  }
11
11
  /**
12
12
  * Get a list of paths to all the jest config files
13
- * using the Nx Jest executor and `@nx/run:commands`
14
- * running `jest`.
13
+ * used by `nx:run-commands` targets running `jest`,
14
+ * including the targets `@nx/jest/plugin` infers.
15
15
  *
16
16
  * This is used to configure Jest multi-project support.
17
17
  *
18
- * To add a project not using the Nx Jest executor:
18
+ * To add a project without such a target:
19
19
  * export default async () => ({
20
20
  * projects: [...(await getJestProjectsAsync()), '<rootDir>/path/to/jest.config.ts'];
21
21
  * });
@@ -33,11 +33,7 @@ async function getJestProjectsAsync() {
33
33
  continue;
34
34
  }
35
35
  for (const targetConfiguration of Object.values(projectConfig.targets)) {
36
- if (targetConfiguration.executor === '@nx/jest:jest' ||
37
- targetConfiguration.executor === '@nrwl/jest:jest') {
38
- collectJestConfigFromJestExecutor(targetConfiguration, jestConfigurations);
39
- }
40
- else if (targetConfiguration.executor === 'nx:run-commands') {
36
+ if (targetConfiguration.executor === 'nx:run-commands') {
41
37
  collectJestConfigFromRunCommandsExecutor(targetConfiguration, projectConfig.root, jestConfigurations);
42
38
  }
43
39
  }
@@ -55,18 +51,6 @@ function removeDuplicates(configs) {
55
51
  configs.delete(dir);
56
52
  });
57
53
  }
58
- function collectJestConfigFromJestExecutor(targetConfiguration, jestConfigurations) {
59
- if (targetConfiguration.options?.jestConfig) {
60
- jestConfigurations.add(getJestConfigProjectPath(targetConfiguration.options.jestConfig));
61
- }
62
- if (targetConfiguration.configurations) {
63
- for (const configurationObject of Object.values(targetConfiguration.configurations)) {
64
- if (configurationObject.jestConfig) {
65
- jestConfigurations.add(getJestConfigProjectPath(configurationObject.jestConfig));
66
- }
67
- }
68
- }
69
- }
70
54
  function collectJestConfigFromRunCommandsExecutor(targetConfiguration, projectRoot, jestConfigurations) {
71
55
  if (targetConfiguration.options?.command) {
72
56
  collectJestConfigFromCommand(targetConfiguration.options.command, targetConfiguration.options.cwd ?? projectRoot, jestConfigurations);
@@ -80,12 +64,16 @@ function collectJestConfigFromRunCommandsExecutor(targetConfiguration, projectRo
80
64
  if (targetConfiguration.configurations) {
81
65
  for (const configurationObject of Object.values(targetConfiguration.configurations)) {
82
66
  if (configurationObject.command) {
83
- collectJestConfigFromCommand(configurationObject.command, configurationObject.cwd ?? projectRoot, jestConfigurations);
67
+ collectJestConfigFromCommand(configurationObject.command, configurationObject.cwd ??
68
+ targetConfiguration.options?.cwd ??
69
+ projectRoot, jestConfigurations);
84
70
  }
85
71
  else if (configurationObject.commands) {
86
72
  for (const command of configurationObject.commands) {
87
73
  const commandScript = typeof command === 'string' ? command : command.command;
88
- collectJestConfigFromCommand(commandScript, configurationObject.cwd ?? projectRoot, jestConfigurations);
74
+ collectJestConfigFromCommand(commandScript, configurationObject.cwd ??
75
+ targetConfiguration.options?.cwd ??
76
+ projectRoot, jestConfigurations);
89
77
  }
90
78
  }
91
79
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/jest",
3
- "version": "24.0.0",
3
+ "version": "24.0.1",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -103,8 +103,8 @@
103
103
  }
104
104
  },
105
105
  "dependencies": {
106
- "@nx/devkit": "24.0.0",
107
- "@nx/js": "24.0.0",
106
+ "@nx/devkit": "24.0.1",
107
+ "@nx/js": "24.0.1",
108
108
  "@phenomnomnominal/tsquery": "~6.2.0",
109
109
  "identity-obj-proxy": "3.0.0",
110
110
  "jest-config": "^30.0.2",
@@ -117,7 +117,7 @@
117
117
  "yargs-parser": "21.1.1"
118
118
  },
119
119
  "devDependencies": {
120
- "nx": "24.0.0"
120
+ "nx": "24.0.1"
121
121
  },
122
122
  "publishConfig": {
123
123
  "access": "public"