diff --git a/packages/jest/src/executors/jest/jest.impl.spec.ts b/packages/jest/src/executors/jest/jest.impl.spec.ts index 26728946853423..87327cbd70345d 100644 --- a/packages/jest/src/executors/jest/jest.impl.spec.ts +++ b/packages/jest/src/executors/jest/jest.impl.spec.ts @@ -108,6 +108,7 @@ describe('Jest Executor', () => { }, mockContext ); + expect(process.argv).toContain('--group=core'); expect(runCLI).toHaveBeenCalledWith( expect.objectContaining({ _: [], @@ -117,6 +118,7 @@ describe('Jest Executor', () => { }), ['/root/jest.config.js'] ); + process.argv.pop(); // clean extra arg. }); it('should send appropriate options to jestCLI when testFile is specified', async () => { diff --git a/packages/jest/src/executors/jest/jest.impl.ts b/packages/jest/src/executors/jest/jest.impl.ts index 2c8210d5cb89f1..f36e13134c35c3 100644 --- a/packages/jest/src/executors/jest/jest.impl.ts +++ b/packages/jest/src/executors/jest/jest.impl.ts @@ -17,14 +17,22 @@ import { readFileSync } from 'fs'; import type { BatchResults } from 'nx/src/tasks-runner/batch/batch-messages'; process.env.NODE_ENV ??= 'test'; +function injectExtraArgsToProcessArgv(extraArgs) { + if (typeof extraArgs === 'object') { + for (const arg in extraArgs) { + process.argv.push(`--${arg}=${extraArgs[arg]}`); + } + } +} + export async function jestExecutor( options: JestExecutorOptions, context: ExecutorContext ): Promise<{ success: boolean }> { const config = await jestConfigParser(options, context); + injectExtraArgsToProcessArgv(config.extraArgs); const { results } = await runCLI(config, [options.jestConfig]); - return { success: results.success }; } @@ -97,6 +105,10 @@ export async function jestConfigParser( randomize: options.randomize, }; + if (Object.keys(extraArgs).length > 0) { + config['extraArgs'] = extraArgs; + } + if (!multiProjects) { options.jestConfig = path.resolve(context.root, options.jestConfig);