From e60da056a78f6f7963ff7e459e4a0f8895a8d938 Mon Sep 17 00:00:00 2001 From: Gamote Date: Wed, 21 Oct 2020 18:44:03 +0200 Subject: [PATCH 1/8] Fix for `jest.config.ts` compiler to not interfere with `tsconfig.json` --- packages/jest-config/src/readConfigFileAndSetRootDir.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/jest-config/src/readConfigFileAndSetRootDir.ts b/packages/jest-config/src/readConfigFileAndSetRootDir.ts index 47f1d6823efc..68cee0e87a6b 100644 --- a/packages/jest-config/src/readConfigFileAndSetRootDir.ts +++ b/packages/jest-config/src/readConfigFileAndSetRootDir.ts @@ -107,7 +107,11 @@ const loadTSConfigFile = async ( // Register TypeScript compiler instance try { - registerer = require('ts-node').register(); + registerer = require('ts-node').register({ + compilerOptions: { + module: 'CommonJS', + }, + }); } catch (e) { if (e.code === 'MODULE_NOT_FOUND') { throw new Error( From a167c3dd63c66867ddce1b74b0a19b2746ab8c5a Mon Sep 17 00:00:00 2001 From: Gamote Date: Wed, 21 Oct 2020 18:57:20 +0200 Subject: [PATCH 2/8] Include the #10675 changes --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eaee24dc0baa..852818a36027 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - `[expect]` Fix `objectContaining` to work recursively into sub-objects ([#10508](https://github.com/facebook/jest/pull/10508)) - `[jest-message-util]` Update to work properly with Node 15 ([#10660](https://github.com/facebook/jest/pull/10660)) - `[jest-mock]` Allow to mock methods in getters (TypeScript 3.9 export) ([#10156](https://github.com/facebook/jest/pull/10156)) +- `[jest-config]` Fix for the `jest.config.ts` compiler to not interfere with `tsconfig.json` files ### Chore & Maintenance From 5f945684ed88de8269c2e3066215855df50dbcf1 Mon Sep 17 00:00:00 2001 From: Gamote Date: Wed, 21 Oct 2020 19:09:30 +0200 Subject: [PATCH 3/8] Arrange CHANGELOG entry alphabetically --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 852818a36027..4b567f1cce4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,9 @@ ### Fixes - `[expect]` Fix `objectContaining` to work recursively into sub-objects ([#10508](https://github.com/facebook/jest/pull/10508)) +- `[jest-config]` Fix for the `jest.config.ts` compiler to not interfere with `tsconfig.json` files - `[jest-message-util]` Update to work properly with Node 15 ([#10660](https://github.com/facebook/jest/pull/10660)) - `[jest-mock]` Allow to mock methods in getters (TypeScript 3.9 export) ([#10156](https://github.com/facebook/jest/pull/10156)) -- `[jest-config]` Fix for the `jest.config.ts` compiler to not interfere with `tsconfig.json` files ### Chore & Maintenance From 771d5e57899103de3ee66fe86f3f86db12289790 Mon Sep 17 00:00:00 2001 From: Gamote Date: Wed, 21 Oct 2020 19:39:42 +0200 Subject: [PATCH 4/8] Added a test for `jest.config.ts` in combination with `tsconfig.json` --- .../__snapshots__/jest.config.ts.test.ts.snap | 13 +++++++++++++ e2e/__tests__/jest.config.ts.test.ts | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap b/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap index 231d926a36de..b8b58ef4e7ed 100644 --- a/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap +++ b/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap @@ -34,3 +34,16 @@ Snapshots: 0 total Time: <> Ran all test suites. `; + +exports[`works with tsconfig.json 1`] = ` +PASS __tests__/a-giraffe.js + ✓ giraffe +`; + +exports[`works with tsconfig.json 2`] = ` +Test Suites: 1 passed, 1 total +Tests: 1 passed, 1 total +Snapshots: 0 total +Time: <> +Ran all test suites. +`; diff --git a/e2e/__tests__/jest.config.ts.test.ts b/e2e/__tests__/jest.config.ts.test.ts index 9b3edcef87ff..28fd7a80f1ce 100644 --- a/e2e/__tests__/jest.config.ts.test.ts +++ b/e2e/__tests__/jest.config.ts.test.ts @@ -29,6 +29,21 @@ test('works with jest.config.ts', () => { expect(wrap(summary)).toMatchSnapshot(); }); +test('works with tsconfig.json', () => { + writeFiles(DIR, { + '__tests__/a-giraffe.js': `test('giraffe', () => expect(1).toBe(1));`, + 'jest.config.ts': `export default {testEnvironment: 'jest-environment-node', testRegex: '.*-giraffe.js'};`, + 'package.json': '{}', + 'tsconfig.json': '{ "compilerOptions": { "module": "esnext" } }', + }); + + const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false']); + const {rest, summary} = extractSummary(stderr); + expect(exitCode).toBe(0); + expect(wrap(rest)).toMatchSnapshot(); + expect(wrap(summary)).toMatchSnapshot(); +}); + test('traverses directory tree up until it finds jest.config', () => { writeFiles(DIR, { '__tests__/a-giraffe.js': ` From 44b9d41d835fb20f4a403558c1250ca32406bc05 Mon Sep 17 00:00:00 2001 From: Gamote Date: Wed, 21 Oct 2020 21:03:30 +0200 Subject: [PATCH 5/8] chore: update dir namings to look like directories instead of files --- .../__snapshots__/jest.config.js.test.ts.snap | 36 -------------- .../__snapshots__/jest.config.ts.test.ts.snap | 49 ------------------- e2e/__tests__/jest.config.js.test.ts | 2 +- e2e/__tests__/jest.config.ts.test.ts | 2 +- 4 files changed, 2 insertions(+), 87 deletions(-) delete mode 100644 e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap delete mode 100644 e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap diff --git a/e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap b/e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap deleted file mode 100644 index db94a91b08e4..000000000000 --- a/e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap +++ /dev/null @@ -1,36 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`traverses directory tree up until it finds jest.config 1`] = ` - console.log -<>/jest.config.js/some/nested/directory - - at Object.log (__tests__/a-banana.js:3:27) - -`; - -exports[`traverses directory tree up until it finds jest.config 2`] = ` -PASS ../../../__tests__/a-banana.js - ✓ banana - ✓ abc -`; - -exports[`traverses directory tree up until it finds jest.config 3`] = ` -Test Suites: 1 passed, 1 total -Tests: 2 passed, 2 total -Snapshots: 0 total -Time: <> -Ran all test suites. -`; - -exports[`works with jest.config.js 1`] = ` -PASS __tests__/a-banana.js - ✓ banana -`; - -exports[`works with jest.config.js 2`] = ` -Test Suites: 1 passed, 1 total -Tests: 1 passed, 1 total -Snapshots: 0 total -Time: <> -Ran all test suites. -`; diff --git a/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap b/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap deleted file mode 100644 index b8b58ef4e7ed..000000000000 --- a/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap +++ /dev/null @@ -1,49 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`traverses directory tree up until it finds jest.config 1`] = ` - console.log -<>/jest.config.ts/some/nested/directory - - at Object.log (__tests__/a-giraffe.js:3:27) - -`; - -exports[`traverses directory tree up until it finds jest.config 2`] = ` -PASS ../../../__tests__/a-giraffe.js - ✓ giraffe - ✓ abc -`; - -exports[`traverses directory tree up until it finds jest.config 3`] = ` -Test Suites: 1 passed, 1 total -Tests: 2 passed, 2 total -Snapshots: 0 total -Time: <> -Ran all test suites. -`; - -exports[`works with jest.config.ts 1`] = ` -PASS __tests__/a-giraffe.js - ✓ giraffe -`; - -exports[`works with jest.config.ts 2`] = ` -Test Suites: 1 passed, 1 total -Tests: 1 passed, 1 total -Snapshots: 0 total -Time: <> -Ran all test suites. -`; - -exports[`works with tsconfig.json 1`] = ` -PASS __tests__/a-giraffe.js - ✓ giraffe -`; - -exports[`works with tsconfig.json 2`] = ` -Test Suites: 1 passed, 1 total -Tests: 1 passed, 1 total -Snapshots: 0 total -Time: <> -Ran all test suites. -`; diff --git a/e2e/__tests__/jest.config.js.test.ts b/e2e/__tests__/jest.config.js.test.ts index 5fd47a0ba1c9..f07e4624dbaf 100644 --- a/e2e/__tests__/jest.config.js.test.ts +++ b/e2e/__tests__/jest.config.js.test.ts @@ -10,7 +10,7 @@ import {wrap} from 'jest-snapshot-serializer-raw'; import runJest from '../runJest'; import {cleanup, extractSummary, writeFiles} from '../Utils'; -const DIR = path.resolve(__dirname, '../jest.config.js'); +const DIR = path.resolve(__dirname, '../tmp/jest-config-js'); beforeEach(() => cleanup(DIR)); afterAll(() => cleanup(DIR)); diff --git a/e2e/__tests__/jest.config.ts.test.ts b/e2e/__tests__/jest.config.ts.test.ts index 28fd7a80f1ce..75fffca6478d 100644 --- a/e2e/__tests__/jest.config.ts.test.ts +++ b/e2e/__tests__/jest.config.ts.test.ts @@ -10,7 +10,7 @@ import {wrap} from 'jest-snapshot-serializer-raw'; import runJest from '../runJest'; import {cleanup, extractSummary, writeFiles} from '../Utils'; -const DIR = path.resolve(__dirname, '../jest.config.ts'); +const DIR = path.resolve(__dirname, '../tmp/jest-config-ts'); beforeEach(() => cleanup(DIR)); afterAll(() => cleanup(DIR)); From 0ff1df87aa3465a3b2baa9308823ba0c7969d4ae Mon Sep 17 00:00:00 2001 From: Gamote Date: Thu, 22 Oct 2020 10:48:30 +0200 Subject: [PATCH 6/8] chore: Revert the 'tmp' added in the DIR path --- e2e/__tests__/jest.config.js.test.ts | 2 +- e2e/__tests__/jest.config.ts.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/__tests__/jest.config.js.test.ts b/e2e/__tests__/jest.config.js.test.ts index f07e4624dbaf..a81611071cd7 100644 --- a/e2e/__tests__/jest.config.js.test.ts +++ b/e2e/__tests__/jest.config.js.test.ts @@ -10,7 +10,7 @@ import {wrap} from 'jest-snapshot-serializer-raw'; import runJest from '../runJest'; import {cleanup, extractSummary, writeFiles} from '../Utils'; -const DIR = path.resolve(__dirname, '../tmp/jest-config-js'); +const DIR = path.resolve(__dirname, '../jest-config-js'); beforeEach(() => cleanup(DIR)); afterAll(() => cleanup(DIR)); diff --git a/e2e/__tests__/jest.config.ts.test.ts b/e2e/__tests__/jest.config.ts.test.ts index 75fffca6478d..d93dc33bfd84 100644 --- a/e2e/__tests__/jest.config.ts.test.ts +++ b/e2e/__tests__/jest.config.ts.test.ts @@ -10,7 +10,7 @@ import {wrap} from 'jest-snapshot-serializer-raw'; import runJest from '../runJest'; import {cleanup, extractSummary, writeFiles} from '../Utils'; -const DIR = path.resolve(__dirname, '../tmp/jest-config-ts'); +const DIR = path.resolve(__dirname, '../jest-config-ts'); beforeEach(() => cleanup(DIR)); afterAll(() => cleanup(DIR)); From 9f338da629833cead62a20022ff0476be5cd6232 Mon Sep 17 00:00:00 2001 From: Gamote Date: Thu, 22 Oct 2020 11:12:00 +0200 Subject: [PATCH 7/8] chore: Add the snapshots for jest.config.[js|ts] --- .../__snapshots__/jest.config.js.test.ts.snap | 36 ++++++++++++++ .../__snapshots__/jest.config.ts.test.ts.snap | 49 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap create mode 100644 e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap diff --git a/e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap b/e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap new file mode 100644 index 000000000000..9bf15c021352 --- /dev/null +++ b/e2e/__tests__/__snapshots__/jest.config.js.test.ts.snap @@ -0,0 +1,36 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`traverses directory tree up until it finds jest.config 1`] = ` + console.log +<>/jest-config-js/some/nested/directory + + at Object.log (__tests__/a-banana.js:3:27) + +`; + +exports[`traverses directory tree up until it finds jest.config 2`] = ` +PASS ../../../__tests__/a-banana.js + ✓ banana + ✓ abc +`; + +exports[`traverses directory tree up until it finds jest.config 3`] = ` +Test Suites: 1 passed, 1 total +Tests: 2 passed, 2 total +Snapshots: 0 total +Time: <> +Ran all test suites. +`; + +exports[`works with jest.config.js 1`] = ` +PASS __tests__/a-banana.js + ✓ banana +`; + +exports[`works with jest.config.js 2`] = ` +Test Suites: 1 passed, 1 total +Tests: 1 passed, 1 total +Snapshots: 0 total +Time: <> +Ran all test suites. +`; diff --git a/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap b/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap new file mode 100644 index 000000000000..5930200701cb --- /dev/null +++ b/e2e/__tests__/__snapshots__/jest.config.ts.test.ts.snap @@ -0,0 +1,49 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`traverses directory tree up until it finds jest.config 1`] = ` + console.log +<>/jest-config-ts/some/nested/directory + + at Object.log (__tests__/a-giraffe.js:3:27) + +`; + +exports[`traverses directory tree up until it finds jest.config 2`] = ` +PASS ../../../__tests__/a-giraffe.js + ✓ giraffe + ✓ abc +`; + +exports[`traverses directory tree up until it finds jest.config 3`] = ` +Test Suites: 1 passed, 1 total +Tests: 2 passed, 2 total +Snapshots: 0 total +Time: <> +Ran all test suites. +`; + +exports[`works with jest.config.ts 1`] = ` +PASS __tests__/a-giraffe.js + ✓ giraffe +`; + +exports[`works with jest.config.ts 2`] = ` +Test Suites: 1 passed, 1 total +Tests: 1 passed, 1 total +Snapshots: 0 total +Time: <> +Ran all test suites. +`; + +exports[`works with tsconfig.json 1`] = ` +PASS __tests__/a-giraffe.js + ✓ giraffe +`; + +exports[`works with tsconfig.json 2`] = ` +Test Suites: 1 passed, 1 total +Tests: 1 passed, 1 total +Snapshots: 0 total +Time: <> +Ran all test suites. +`; From 446e31dd5855a3df78a4da3bf24f173f1afac70f Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 22 Oct 2020 11:31:57 +0200 Subject: [PATCH 8/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b567f1cce4a..41669d689333 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ ### Fixes - `[expect]` Fix `objectContaining` to work recursively into sub-objects ([#10508](https://github.com/facebook/jest/pull/10508)) -- `[jest-config]` Fix for the `jest.config.ts` compiler to not interfere with `tsconfig.json` files +- `[jest-config]` Fix for the `jest.config.ts` compiler to not interfere with `tsconfig.json` files ([#10675](https://github.com/facebook/jest/pull/10675)) - `[jest-message-util]` Update to work properly with Node 15 ([#10660](https://github.com/facebook/jest/pull/10660)) - `[jest-mock]` Allow to mock methods in getters (TypeScript 3.9 export) ([#10156](https://github.com/facebook/jest/pull/10156))