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

allow moduleFileExtensions without 'js' for custom runners #7751

Merged
merged 4 commits into from
Jan 29, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- `[jest-cli]` Print log entries when logging happens after test environment is torn down ([#7731](https://github.com/facebook/jest/pull/7731))
- `[jest-config]` Do not use a uuid as `name` since that breaks caching ([#7746](https://github.com/facebook/jest/pull/7746))
- `[jest-config]` Make sure `normalize` can consume `Defaults` without warnings ([#7742](https://github.com/facebook/jest/pull/7742))
- `[jest-config]` Allow `moduleFileExtensions` without 'js' for custom runners ([#7751](https://github.com/facebook/jest/pull/7751))

### Chore & Maintenance

Expand Down
20 changes: 18 additions & 2 deletions packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1448,16 +1448,32 @@ describe('moduleFileExtensions', () => {
]);
});

it('throws if missing `js`', () => {
it('throws if missing `js` but using jest-runner', () => {
[undefined, 'jest-runner'].forEach(runner =>
expect(() =>
normalize(
{
rootDir: '/root/',
moduleFileExtensions: ['json', 'jsx'],
runner,
},
{},
),
).toThrowError("moduleFileExtensions must include 'js'"),
);
});

it('does not throw if missing `js` with a custom runner', () => {
expect(() =>
normalize(
{
rootDir: '/root/',
moduleFileExtensions: ['json', 'jsx'],
runner: './', // does not need to be a valid runner for this validation
},
{},
),
).toThrowError("moduleFileExtensions must include 'js'");
).not.toThrow();
});
});

Expand Down
8 changes: 6 additions & 2 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,12 @@ export default function normalize(
case 'moduleFileExtensions': {
value = options[key];

// If it's the wrong type, it can throw at a later time
if (Array.isArray(value) && !value.includes('js')) {
if (
Array.isArray(value) && // If it's the wrong type, it can throw at a later time
(options.runner === undefined ||
options.runner === DEFAULT_CONFIG.runner) && // Only require 'js' for the default jest-runner
!value.includes('js')
) {
const errorMessage =
` moduleFileExtensions must include 'js':\n` +
` but instead received:\n` +
Expand Down