diff --git a/CHANGELOG.md b/CHANGELOG.md index 31284a4d69a8..f2f78d6c8630 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index df031aadd292..e1e24827dade 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -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(); }); }); diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index f2304fc71791..c9269cee1016 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -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` +