Skip to content

Commit d27de31

Browse files
Mararokleosvelperez
authored andcommitted
fix(testing): fix passing extra args to Jest cli (#27704)
Small fix for using jest-runner-groups(https://www.npmjs.com/package/jest-runner-groups) with Nx. ## Current Behavior When running jest executor with extra group argument like: ``` nx run app-nebula-explorer-api:test --group=unit ``` `jest-runner-groups` runs all tests, not only from selected group. From my investigation, `jest-runner-groups` using process.argv to extract `--group` args https://github.com/eugene-manuilov/jest-runner-groups/blob/3c9d3cf4cb3e595bdea733100f2bdc8d64f871d7/index.js#L57 and `process.argv` passed to runner contains: ```javascript [ 'M:\\programs\\nodejs\\22\\node.exe', 'M:\\projects\\someproject\\node_modules\\.pnpm\\[email protected]_@[email protected]_@[email protected]_\\node_modules\\nx\\bin\\run-executor.js' ] ``` ## Expected Behavior Running jest executor with jest-runner-groups runner and `--group` args should run only tests from group. ## PR changes summary I implemented fix as generic and any extra arg will be added to `process.argv` . --------- Co-authored-by: Leosvel Pérez Espinosa <[email protected]> (cherry picked from commit 8266785)
1 parent aca2e15 commit d27de31

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

packages/jest/src/executors/jest/jest.impl.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ describe('Jest Executor', () => {
127127
},
128128
mockContext
129129
);
130+
expect(process.argv).toContain('--group=core');
130131
expect(runCLI).toHaveBeenCalledWith(
131132
expect.objectContaining({
132133
_: [],
@@ -136,6 +137,7 @@ describe('Jest Executor', () => {
136137
}),
137138
['/root/jest.config.js']
138139
);
140+
process.argv.pop(); // clean extra arg.
139141
});
140142

141143
it('should send appropriate options to jestCLI when testFile is specified', async () => {

packages/jest/src/executors/jest/jest.impl.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ export async function jestExecutor(
2525
// We want to support of ESM via 'module':'nodenext', we need to override the resolution until Jest supports it.
2626
process.env.TS_NODE_COMPILER_OPTIONS ??= '{"moduleResolution":"node10"}';
2727

28-
const config = await jestConfigParser(options, context);
28+
const config = await parseJestConfig(options, context);
2929

3030
const { results } = await runCLI(config, [options.jestConfig]);
31-
3231
return { success: results.success };
3332
}
3433

@@ -40,13 +39,14 @@ function getExtraArgs(
4039
for (const key of Object.keys(options)) {
4140
if (!schema.properties[key]) {
4241
extraArgs[key] = options[key];
42+
process.argv.push(`--${key}=${options[key]}`);
4343
}
4444
}
4545

4646
return extraArgs;
4747
}
4848

49-
export async function jestConfigParser(
49+
export async function parseJestConfig(
5050
options: JestExecutorOptions,
5151
context: ExecutorContext,
5252
multiProjects = false
@@ -198,7 +198,7 @@ export async function batchJest(
198198
You can learn more about this requirement from Jest here: https://jestjs.io/docs/cli#--selectprojects-project1--projectn`
199199
);
200200
}
201-
const parsedConfigs = await jestConfigParser(overrides, context, true);
201+
const parsedConfigs = await parseJestConfig(overrides, context, true);
202202

203203
const { globalConfig, results } = await runCLI(
204204
{

0 commit comments

Comments
 (0)