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 d4a10f7 commit 54bdaed
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ export function check(argv: Config.Argv): true {
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 54bdaed

Please sign in to comment.