Skip to content

Commit

Permalink
fix(tests): ensure jest respects passed flags (#3329)
Browse files Browse the repository at this point in the history
this commit updates the jest argument builder to
respect updates to flags passed to jest. legacy jest
options would previously overwrite options that a
user passed in via the command line. by reordering
the input to the jest arguments, cli arguments are now
respected
  • Loading branch information
George-Payne committed Apr 13, 2022
1 parent a670421 commit c6a1d42
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/testing/jest/jest-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function buildJestArgv(config: d.Config): Config.Argv {
config.logger.info(config.logger.magenta(`jest args: ${args.join(' ')}`));

let jestArgv = yargs(args).argv as Config.Argv;
jestArgv = { ...jestArgv, ...getLegacyJestOptions() };
jestArgv = { ...getLegacyJestOptions(), ...jestArgv };
jestArgv.config = buildJestConfig(config);

if (typeof jestArgv.maxWorkers === 'string') {
Expand Down
14 changes: 14 additions & 0 deletions src/testing/jest/test/jest-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,18 @@ describe('jest-config', () => {
expect(parsedConfig.collectCoverageFrom).toHaveLength(1);
expect(parsedConfig.collectCoverageFrom[0]).toBe('**/*.+(ts|tsx)');
});

it('passed flags should be respected over defaults', () => {
const args = ['test', '--spec', '--passWithNoTests'];
const config = mockConfig();
config.flags = parseFlags(args, config.sys);
config.testing = {};

expect(config.flags.args).toEqual(['--spec', '--passWithNoTests']);
expect(config.flags.unknownArgs).toEqual(['--passWithNoTests']);

const jestArgv = buildJestArgv(config);
expect(jestArgv.spec).toBe(true);
expect(jestArgv.passWithNoTests).toBe(true);
});
});

0 comments on commit c6a1d42

Please sign in to comment.