Skip to content

Commit

Permalink
fix(cli): .cjs files support by "--config" option
Browse files Browse the repository at this point in the history
Fixes #9086
  • Loading branch information
the-spyke committed Feb 16, 2020
1 parent b2c8a69 commit 32665d8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
27 changes: 26 additions & 1 deletion packages/jest-cli/src/__tests__/cli/args.test.ts
Expand Up @@ -62,7 +62,32 @@ describe('check', () => {
it('raises an exception if config is not a valid JSON string', () => {
const argv = {config: 'x:1'} as Config.Argv;
expect(() => check(argv)).toThrow(
'The --config option requires a JSON string literal, or a file path with a .js or .json extension',
'The --config option requires a JSON string literal, or a file path with a .js, .cjs, or .json extension',
);
});

it('raises an exception if config is not a js/cjs/json file path', () => {
expect(() =>
check({config: 'jest.config.js'} as Config.Argv),
).not.toThrow();
expect(() =>
check({config: '../test/test/my_conf.js'} as Config.Argv),
).not.toThrow();
expect(() =>
check({config: 'jest.config.cjs'} as Config.Argv),
).not.toThrow();
expect(() =>
check({config: 'jest.config.json'} as Config.Argv),
).not.toThrow();

const message =
'The --config option requires a JSON string literal, or a file path with a .js, .cjs, or .json extension';

expect(() => check({config: 'jest.config.mjs'} as Config.Argv)).toThrow(
message,
);
expect(() => check({config: 'jest.config.ts'} as Config.Argv)).toThrow(
message,
);
});
});
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-cli/src/cli/args.ts
Expand Up @@ -52,10 +52,10 @@ export const check = (argv: Config.Argv) => {
if (
argv.config &&
!isJSONString(argv.config) &&
!argv.config.match(/\.js(on)?$/)
!argv.config.match(/\.(js|cjs|json)$/)
) {
throw new Error(
'The --config option requires a JSON string literal, or a file path with a .js or .json extension.\n' +
'The --config option requires a JSON string literal, or a file path with a .js, .cjs, or .json extension.\n' +
'Example usage: jest --config ./jest.config.js',
);
}
Expand Down

0 comments on commit 32665d8

Please sign in to comment.