From 410ee8e63f203a10b7000369736054a12938f8b9 Mon Sep 17 00:00:00 2001 From: Tim Seckinger Date: Tue, 29 Jan 2019 23:15:03 +0100 Subject: [PATCH 1/4] allow moduleFileExtensions without 'js' for custom runners --- CHANGELOG.md | 1 + .../jest-config/src/__tests__/normalize.test.js | 15 ++++++++++++++- packages/jest-config/src/normalize.js | 7 +++++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31284a4d69a8..3929c41f29df 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 (TODO) ### Chore & Maintenance diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index df031aadd292..0fc3047b3caa 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -1448,7 +1448,7 @@ describe('moduleFileExtensions', () => { ]); }); - it('throws if missing `js`', () => { + it('throws if missing `js` but using jest-runner', () => { expect(() => normalize( { @@ -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', () => { diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index f2304fc71791..bf6887e393b2 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -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 + !value.includes('js') + ) { const errorMessage = ` moduleFileExtensions must include 'js':\n` + ` but instead received:\n` + From 2c53e8782db9b05fab729941c59002d2069a4c8d Mon Sep 17 00:00:00 2001 From: Tim Seckinger Date: Tue, 29 Jan 2019 23:22:08 +0100 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3929c41f29df..624b8a294419 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +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 (TODO) +- `[jest-config]` Allow `moduleFileExtensions` without 'js' for custom runners ([#7736](https://github.com/facebook/jest/pull/7751)) ### Chore & Maintenance From eca26fcaf786b70db3dc4142b21430880a1d21b9 Mon Sep 17 00:00:00 2001 From: Tim Seckinger Date: Tue, 29 Jan 2019 23:22:42 +0100 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 624b8a294419..f2f78d6c8630 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +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 ([#7736](https://github.com/facebook/jest/pull/7751)) +- `[jest-config]` Allow `moduleFileExtensions` without 'js' for custom runners ([#7751](https://github.com/facebook/jest/pull/7751)) ### Chore & Maintenance From 1114b977d832c68f771ee96802744bd424fa2329 Mon Sep 17 00:00:00 2001 From: Tim Seckinger Date: Tue, 29 Jan 2019 23:44:17 +0100 Subject: [PATCH 4/4] also handle explicit `runner: 'jest-runner'` --- .../src/__tests__/normalize.test.js | 21 +++++++++++-------- packages/jest-config/src/normalize.js | 3 ++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index 0fc3047b3caa..e1e24827dade 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -1449,15 +1449,18 @@ describe('moduleFileExtensions', () => { }); it('throws if missing `js` but using jest-runner', () => { - expect(() => - normalize( - { - rootDir: '/root/', - moduleFileExtensions: ['json', 'jsx'], - }, - {}, - ), - ).toThrowError("moduleFileExtensions must include 'js'"); + [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', () => { diff --git a/packages/jest-config/src/normalize.js b/packages/jest-config/src/normalize.js index bf6887e393b2..c9269cee1016 100644 --- a/packages/jest-config/src/normalize.js +++ b/packages/jest-config/src/normalize.js @@ -652,7 +652,8 @@ export default function normalize( 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 + (options.runner === undefined || + options.runner === DEFAULT_CONFIG.runner) && // Only require 'js' for the default jest-runner !value.includes('js') ) { const errorMessage =