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 3 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
15 changes: 14 additions & 1 deletion packages/jest-config/src/__tests__/normalize.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1448,7 +1448,7 @@ describe('moduleFileExtensions', () => {
]);
});

it('throws if missing `js`', () => {
it('throws if missing `js` but using jest-runner', () => {
expect(() =>
normalize(
{
Expand All @@ -1459,6 +1459,19 @@ describe('moduleFileExtensions', () => {
),
).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
},
{},
),
).not.toThrow();
});
});

describe('Defaults', () => {
Expand Down
7 changes: 5 additions & 2 deletions packages/jest-config/src/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,11 @@ 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 && // Only require 'js' for the default jest-runner
SimenB marked this conversation as resolved.
Show resolved Hide resolved
!value.includes('js')
) {
const errorMessage =
` moduleFileExtensions must include 'js':\n` +
` but instead received:\n` +
Expand Down