Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(testing): support extra jest cli args #9904

Merged
merged 1 commit into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/jest/src/executors/jest/jest.impl.spec.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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