Skip to content

Commit

Permalink
fix: allow moduleFileExtensions without 'js' for custom runners (#7751)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeysal authored and SimenB committed Jan 29, 2019
1 parent 832fe47 commit 09c5003
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
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

0 comments on commit 09c5003

Please sign in to comment.