Skip to content

Commit

Permalink
feat(testing): support extra jest cli args (#9904)
Browse files Browse the repository at this point in the history
pass extra cli args to jest to allow 3rd party plugins to work correct like jest-runner-groups

ISSUES CLOSED: #9873
  • Loading branch information
barbados-clemens committed Apr 20, 2022
1 parent e744768 commit c265c46
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/jest/src/executors/jest/jest.impl.spec.ts
Expand Up @@ -97,6 +97,28 @@ describe('Jest Executor', () => {
);
});

it('should send extra options to jestCLI', async () => {
await jestExecutor(
{
...defaultOptions,
jestConfig: './jest.config.js',
watch: false,
// @ts-ignore
group: 'core',
},
mockContext
);
expect(runCLI).toHaveBeenCalledWith(
expect.objectContaining({
_: [],
testPathPattern: [],
watch: false,
group: 'core',
}),
['/root/jest.config.js']
);
});

it('should send appropriate options to jestCLI when testFile is specified', async () => {
await jestExecutor(
{
Expand Down
20 changes: 20 additions & 0 deletions packages/jest/src/executors/jest/jest.impl.ts
Expand Up @@ -23,6 +23,20 @@ export async function jestExecutor(
return { success: results.success };
}

function getExtraArgs(
options: JestExecutorOptions,
schema: { properties: Record<string, any> }
) {
const extraArgs = {};
for (const key of Object.keys(options)) {
if (!schema.properties[key]) {
extraArgs[key] = options[key];
}
}

return extraArgs;
}

export async function jestConfigParser(
options: JestExecutorOptions,
context: ExecutorContext,
Expand All @@ -36,7 +50,13 @@ export async function jestConfigParser(
}
| undefined;

// support passing extra args to jest cli supporting 3rd party plugins
// like 'jest-runner-groups' --group arg
const schema = await import('./schema.json');
const extraArgs = getExtraArgs(options, schema);

const config: Config.Argv = {
...extraArgs,
$0: undefined,
_: [],
config: options.config,
Expand Down

0 comments on commit c265c46

Please sign in to comment.