From d0077f8b2e1835b22264168035a7d6f2a034e839 Mon Sep 17 00:00:00 2001 From: M4rk9696 Date: Wed, 14 Aug 2019 22:26:53 +0530 Subject: [PATCH 1/5] feat: Allow testRunner to be configurable --- CHANGELOG.md | 1 + e2e/__tests__/transform.test.ts | 11 ++++++ e2e/babel-plugin-jest-hoist/package.json | 4 ++- .../package.json | 5 +++ e2e/transform-linked-modules/package.json | 5 ++- .../babel-jest-ignored/babel.config.js | 10 +++++- .../multiple-transformers/package.json | 3 +- .../__tests__/add.test.js | 10 ++++++ .../transform-testrunner/babel.config.js | 18 ++++++++++ .../transform-testrunner/package.json | 10 ++++++ .../transform-testrunner/test-runner.ts | 34 +++++++++++++++++++ .../transform-testrunner/tsconfig.json | 6 ++++ packages/jest-runner/package.json | 1 + packages/jest-runner/src/runTest.ts | 9 ++--- 14 files changed, 118 insertions(+), 9 deletions(-) create mode 100644 e2e/transform/transform-testrunner/__tests__/add.test.js create mode 100644 e2e/transform/transform-testrunner/babel.config.js create mode 100644 e2e/transform/transform-testrunner/package.json create mode 100644 e2e/transform/transform-testrunner/test-runner.ts create mode 100644 e2e/transform/transform-testrunner/tsconfig.json diff --git a/CHANGELOG.md b/CHANGELOG.md index e2d47d1a5316..76133c3a5ff7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -552,6 +552,7 @@ - `[@jest/test-result]` Create method to create empty `TestResult` ([#8867](https://github.com/facebook/jest/pull/8867)) - `[jest-worker]` [**BREAKING**] Return a promise from `end()`, resolving with the information whether workers exited gracefully ([#8206](https://github.com/facebook/jest/pull/8206)) - `[jest-reporters]` Transform file paths into hyperlinks ([#8980](https://github.com/facebook/jest/pull/8980)) +- `[jest-runner]` [**BREAKING**] Run transforms over `testRunnner` ([#8823](https://github.com/facebook/jest/pull/8823)) ### Fixes diff --git a/e2e/__tests__/transform.test.ts b/e2e/__tests__/transform.test.ts index 956a258b4d2d..6f98abdbab28 100644 --- a/e2e/__tests__/transform.test.ts +++ b/e2e/__tests__/transform.test.ts @@ -227,3 +227,14 @@ describe('transform-runner', () => { expect(json.numPassedTests).toBe(1); }); }); + +describe('transform-testrunner', () => { + const dir = path.resolve(__dirname, '../transform/transform-testrunner'); + + it('should transform testRunner', () => { + const {json, stderr} = runWithJson(dir, ['--no-cache']); + expect(stderr).toMatch(/PASS/); + expect(json.success).toBe(true); + expect(json.numPassedTests).toBe(1); + }); +}); diff --git a/e2e/babel-plugin-jest-hoist/package.json b/e2e/babel-plugin-jest-hoist/package.json index c498b7ef21bf..b95dff321f67 100644 --- a/e2e/babel-plugin-jest-hoist/package.json +++ b/e2e/babel-plugin-jest-hoist/package.json @@ -9,7 +9,9 @@ "automock": true, "testEnvironment": "node", "transformIgnorePatterns": [ - "/jest-environment-node/" + "/jest-environment-node/", + "jest-jasmine2", + "jest-circus" ] } } diff --git a/e2e/coverage-transform-instrumented/package.json b/e2e/coverage-transform-instrumented/package.json index 3bb4016f58a2..202aeb598700 100644 --- a/e2e/coverage-transform-instrumented/package.json +++ b/e2e/coverage-transform-instrumented/package.json @@ -4,6 +4,11 @@ "transform": { "\\.(js)$": "/preprocessor.js" }, + "transformIgnorePatterns": [ + "jest-jasmine2", + "jest-each", + "jest-circus" + ], "testRegex": "/__tests__/.*\\.(js)$", "testEnvironment": "node", "transformIgnorePatterns": [ diff --git a/e2e/transform-linked-modules/package.json b/e2e/transform-linked-modules/package.json index 1bea4d7d023b..ccccdeeefc15 100644 --- a/e2e/transform-linked-modules/package.json +++ b/e2e/transform-linked-modules/package.json @@ -5,7 +5,10 @@ "/node_modules/", "/__tests__", "/ignored/", - "/jest-environment-node/" + "/jest-environment-node/", + "jest-jasmine2", + "jest-each", + "jest-circus" ], "transform": { "\\.js$": "/preprocessor.js" diff --git a/e2e/transform/babel-jest-ignored/babel.config.js b/e2e/transform/babel-jest-ignored/babel.config.js index e35eb8dc019c..8edce00000ae 100644 --- a/e2e/transform/babel-jest-ignored/babel.config.js +++ b/e2e/transform/babel-jest-ignored/babel.config.js @@ -5,4 +5,12 @@ * LICENSE file in the root directory of this source tree. */ -module.exports = {only: ['blablabla', /jest-environment-node/]}; +module.exports = { + only: [ + 'blablabla', + /jest-environment-node/, + /jest-jasmine2/, + /jest-circus/, + /jest-each/, + ], +}; diff --git a/e2e/transform/multiple-transformers/package.json b/e2e/transform/multiple-transformers/package.json index 074d79491bfc..028b24f3dc35 100644 --- a/e2e/transform/multiple-transformers/package.json +++ b/e2e/transform/multiple-transformers/package.json @@ -7,8 +7,7 @@ }, "testEnvironment": "node", "transformIgnorePatterns": [ - "/jest-environment-node/" - ] + "/jest-environment-node/", "jest-jasmine2", "jest-circus"] }, "dependencies": { "@babel/core": "^7.0.0", diff --git a/e2e/transform/transform-testrunner/__tests__/add.test.js b/e2e/transform/transform-testrunner/__tests__/add.test.js new file mode 100644 index 000000000000..10dca79b8672 --- /dev/null +++ b/e2e/transform/transform-testrunner/__tests__/add.test.js @@ -0,0 +1,10 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +it('should add two numbers', () => { + expect(1 + 1).toBe(2); +}); diff --git a/e2e/transform/transform-testrunner/babel.config.js b/e2e/transform/transform-testrunner/babel.config.js new file mode 100644 index 000000000000..5e1e38eebb8d --- /dev/null +++ b/e2e/transform/transform-testrunner/babel.config.js @@ -0,0 +1,18 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +module.exports = { + presets: [ + ['@babel/preset-typescript'], + [ + '@babel/preset-env', + { + targets: {node: 6}, + }, + ], + ], +}; diff --git a/e2e/transform/transform-testrunner/package.json b/e2e/transform/transform-testrunner/package.json new file mode 100644 index 000000000000..9386da74e3dd --- /dev/null +++ b/e2e/transform/transform-testrunner/package.json @@ -0,0 +1,10 @@ +{ + "jest": { + "rootDir": "./", + "testRunner": "/test-runner.ts" + }, + "dependencies": { + "@babel/preset-env": "^7.0.0", + "@babel/preset-typescript": "^7.0.0" + } +} diff --git a/e2e/transform/transform-testrunner/test-runner.ts b/e2e/transform/transform-testrunner/test-runner.ts new file mode 100644 index 000000000000..082ab382bf62 --- /dev/null +++ b/e2e/transform/transform-testrunner/test-runner.ts @@ -0,0 +1,34 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +import {Config} from '@jest/types'; +import {JestEnvironment} from '@jest/environment'; +import Runtime from 'jest-runtime'; +import {TestResult, createEmptyTestResult} from '@jest/test-result'; + +export default async function testRunner( + globalConfig: Config.GlobalConfig, + config: Config.ProjectConfig, + environment: JestEnvironment, + runtime: Runtime, + testPath: string +): Promise { + return { + ...createEmptyTestResult(), + numPassingTests: 1, + testFilePath: testPath, + testResults: [ + { + ancestorTitles: [], + duration: 2, + failureMessages: [], + fullName: 'sample test', + status: 'passed', + title: 'sample test', + }, + ], + } as TestResult; +} diff --git a/e2e/transform/transform-testrunner/tsconfig.json b/e2e/transform/transform-testrunner/tsconfig.json new file mode 100644 index 000000000000..174da5dc37bf --- /dev/null +++ b/e2e/transform/transform-testrunner/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "esModuleInterop": true, + "module": "commonjs", + } +} diff --git a/packages/jest-runner/package.json b/packages/jest-runner/package.json index 3060883e0e22..6cc766a06472 100644 --- a/packages/jest-runner/package.json +++ b/packages/jest-runner/package.json @@ -17,6 +17,7 @@ "@jest/console": "^26.6.2", "@jest/environment": "^26.6.2", "@jest/test-result": "^26.6.2", + "@jest/transform": "^26.6.2", "@jest/types": "^26.6.2", "@types/node": "*", "chalk": "^4.0.0", diff --git a/packages/jest-runner/src/runTest.ts b/packages/jest-runner/src/runTest.ts index 29397e086d7b..f5ff5fbedef7 100644 --- a/packages/jest-runner/src/runTest.ts +++ b/packages/jest-runner/src/runTest.ts @@ -108,10 +108,11 @@ async function runTestInternal( transformer.requireAndTranspileModule(testEnvironment), ).default; const testFramework: TestFramework = interopRequireDefault( - process.env.JEST_CIRCUS === '1' - ? // eslint-disable-next-line import/no-extraneous-dependencies - require('jest-circus/runner') - : require(config.testRunner), + transformer.requireAndTranspileModule( + process.env.JEST_CIRCUS === '1' + ? 'jest-circus/runner' + : config.testRunner, + ), ).default; const Runtime: typeof RuntimeClass = interopRequireDefault( config.moduleLoader From 2abf5283c362d914d6f162fe7aa4817da6a264fb Mon Sep 17 00:00:00 2001 From: M4rk9696 Date: Fri, 23 Aug 2019 10:11:33 +0530 Subject: [PATCH 2/5] chore: Review changes --- CHANGELOG.md | 2 +- e2e/coverage-transform-instrumented/package.json | 10 ++++------ e2e/transform/babel-jest-ignored/babel.config.js | 5 +++-- e2e/transform/multiple-transformers/package.json | 5 ++++- e2e/transform/transform-testrunner/babel.config.js | 9 ++------- e2e/transform/transform-testrunner/test-runner.ts | 10 ++++++---- yarn.lock | 1 + 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76133c3a5ff7..288fd495717f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - `[jest-snapshot]`: [**BREAKING**] Make prettier optional for inline snapshots - fall back to string replacement ([#7792](https://github.com/facebook/jest/pull/7792)) - `[jest-repl, jest-runner]` [**BREAKING**] Run transforms over environment ([#8751](https://github.com/facebook/jest/pull/8751)) - `[jest-runner]` [**BREAKING**] Run transforms over `runnner` ([#8823](https://github.com/facebook/jest/pull/8823)) +- `[jest-runner]` [**BREAKING**] Run transforms over `testRunnner` ([#8823](https://github.com/facebook/jest/pull/8823)) ### Fixes @@ -552,7 +553,6 @@ - `[@jest/test-result]` Create method to create empty `TestResult` ([#8867](https://github.com/facebook/jest/pull/8867)) - `[jest-worker]` [**BREAKING**] Return a promise from `end()`, resolving with the information whether workers exited gracefully ([#8206](https://github.com/facebook/jest/pull/8206)) - `[jest-reporters]` Transform file paths into hyperlinks ([#8980](https://github.com/facebook/jest/pull/8980)) -- `[jest-runner]` [**BREAKING**] Run transforms over `testRunnner` ([#8823](https://github.com/facebook/jest/pull/8823)) ### Fixes diff --git a/e2e/coverage-transform-instrumented/package.json b/e2e/coverage-transform-instrumented/package.json index 202aeb598700..c571de5fed97 100644 --- a/e2e/coverage-transform-instrumented/package.json +++ b/e2e/coverage-transform-instrumented/package.json @@ -4,15 +4,13 @@ "transform": { "\\.(js)$": "/preprocessor.js" }, - "transformIgnorePatterns": [ - "jest-jasmine2", - "jest-each", - "jest-circus" - ], "testRegex": "/__tests__/.*\\.(js)$", "testEnvironment": "node", "transformIgnorePatterns": [ - "/jest-environment-node/" + "jest-circus", + "jest-each", + "jest-environment-node/", + "jest-jasmine2" ], "moduleFileExtensions": [ "js" diff --git a/e2e/transform/babel-jest-ignored/babel.config.js b/e2e/transform/babel-jest-ignored/babel.config.js index 8edce00000ae..048789e0d624 100644 --- a/e2e/transform/babel-jest-ignored/babel.config.js +++ b/e2e/transform/babel-jest-ignored/babel.config.js @@ -8,9 +8,10 @@ module.exports = { only: [ 'blablabla', - /jest-environment-node/, - /jest-jasmine2/, /jest-circus/, /jest-each/, + /jest-environment-node/, + /jest-jasmine2/, + /jest-source-map/, ], }; diff --git a/e2e/transform/multiple-transformers/package.json b/e2e/transform/multiple-transformers/package.json index 028b24f3dc35..84d06db7acea 100644 --- a/e2e/transform/multiple-transformers/package.json +++ b/e2e/transform/multiple-transformers/package.json @@ -7,7 +7,10 @@ }, "testEnvironment": "node", "transformIgnorePatterns": [ - "/jest-environment-node/", "jest-jasmine2", "jest-circus"] + "/jest-environment-node/", + "jest-jasmine2", + "jest-circus" + ] }, "dependencies": { "@babel/core": "^7.0.0", diff --git a/e2e/transform/transform-testrunner/babel.config.js b/e2e/transform/transform-testrunner/babel.config.js index 5e1e38eebb8d..19dd8862b516 100644 --- a/e2e/transform/transform-testrunner/babel.config.js +++ b/e2e/transform/transform-testrunner/babel.config.js @@ -7,12 +7,7 @@ module.exports = { presets: [ - ['@babel/preset-typescript'], - [ - '@babel/preset-env', - { - targets: {node: 6}, - }, - ], + ['@babel/preset-env', {targets: {node: 'current'}}], + '@babel/preset-typescript', ], }; diff --git a/e2e/transform/transform-testrunner/test-runner.ts b/e2e/transform/transform-testrunner/test-runner.ts index 082ab382bf62..0b08cd6ca5e5 100644 --- a/e2e/transform/transform-testrunner/test-runner.ts +++ b/e2e/transform/transform-testrunner/test-runner.ts @@ -4,17 +4,17 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -import {Config} from '@jest/types'; import {JestEnvironment} from '@jest/environment'; -import Runtime from 'jest-runtime'; import {TestResult, createEmptyTestResult} from '@jest/test-result'; +import {Config} from '@jest/types'; +import Runtime from 'jest-runtime'; export default async function testRunner( globalConfig: Config.GlobalConfig, config: Config.ProjectConfig, environment: JestEnvironment, runtime: Runtime, - testPath: string + testPath: string, ): Promise { return { ...createEmptyTestResult(), @@ -26,9 +26,11 @@ export default async function testRunner( duration: 2, failureMessages: [], fullName: 'sample test', + location: null, + numPassingAsserts: 1, status: 'passed', title: 'sample test', }, ], - } as TestResult; + }; } diff --git a/yarn.lock b/yarn.lock index 9e4eafdfa214..2c6bfbee05de 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12126,6 +12126,7 @@ fsevents@~2.1.2: "@jest/console": ^26.6.2 "@jest/environment": ^26.6.2 "@jest/test-result": ^26.6.2 + "@jest/transform": ^26.6.2 "@jest/types": ^26.6.2 "@types/exit": ^0.1.30 "@types/graceful-fs": ^4.1.2 From 34c2aecc9264562da92a6d14a4d7db6303bdec52 Mon Sep 17 00:00:00 2001 From: Mark1626 Date: Sun, 15 Nov 2020 21:45:56 +0530 Subject: [PATCH 3/5] fix: Fix failing test in async regenerator --- e2e/async-regenerator/package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/e2e/async-regenerator/package.json b/e2e/async-regenerator/package.json index cc89a7733dc0..48e3c87993c4 100644 --- a/e2e/async-regenerator/package.json +++ b/e2e/async-regenerator/package.json @@ -6,6 +6,9 @@ "@babel/polyfill": "^7.2.5" }, "jest": { - "testEnvironment": "node" + "testEnvironment": "node", + "transformIgnorePatterns": [ + "jest-jasmine2" + ] } } From 3beec274e9714c1bb5ec857eb2ca9b3f6273523d Mon Sep 17 00:00:00 2001 From: Mark1626 Date: Sun, 15 Nov 2020 21:57:40 +0530 Subject: [PATCH 4/5] chore: Reorder transformIgnorePattern --- e2e/babel-plugin-jest-hoist/package.json | 6 +++--- e2e/transform-linked-modules/package.json | 6 +++--- e2e/transform/multiple-transformers/package.json | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/e2e/babel-plugin-jest-hoist/package.json b/e2e/babel-plugin-jest-hoist/package.json index b95dff321f67..eac0243cf4d4 100644 --- a/e2e/babel-plugin-jest-hoist/package.json +++ b/e2e/babel-plugin-jest-hoist/package.json @@ -9,9 +9,9 @@ "automock": true, "testEnvironment": "node", "transformIgnorePatterns": [ - "/jest-environment-node/", - "jest-jasmine2", - "jest-circus" + "jest-circus", + "jest-environment-node", + "jest-jasmine2" ] } } diff --git a/e2e/transform-linked-modules/package.json b/e2e/transform-linked-modules/package.json index ccccdeeefc15..aef81a535be6 100644 --- a/e2e/transform-linked-modules/package.json +++ b/e2e/transform-linked-modules/package.json @@ -5,10 +5,10 @@ "/node_modules/", "/__tests__", "/ignored/", - "/jest-environment-node/", - "jest-jasmine2", + "jest-circus", "jest-each", - "jest-circus" + "jest-environment-node", + "jest-jasmine2" ], "transform": { "\\.js$": "/preprocessor.js" diff --git a/e2e/transform/multiple-transformers/package.json b/e2e/transform/multiple-transformers/package.json index 84d06db7acea..e3760dfeae93 100644 --- a/e2e/transform/multiple-transformers/package.json +++ b/e2e/transform/multiple-transformers/package.json @@ -7,9 +7,9 @@ }, "testEnvironment": "node", "transformIgnorePatterns": [ - "/jest-environment-node/", - "jest-jasmine2", - "jest-circus" + "jest-circus", + "jest-environment-node", + "jest-jasmine2" ] }, "dependencies": { From 6d5e58c31582e1a3f3f27fe563ce76975209dc86 Mon Sep 17 00:00:00 2001 From: Mark1626 Date: Sun, 15 Nov 2020 22:32:39 +0530 Subject: [PATCH 5/5] fix: Add jest-circus to transformIgnorePattern --- e2e/async-regenerator/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e/async-regenerator/package.json b/e2e/async-regenerator/package.json index 48e3c87993c4..db1f1a7efbe8 100644 --- a/e2e/async-regenerator/package.json +++ b/e2e/async-regenerator/package.json @@ -8,6 +8,7 @@ "jest": { "testEnvironment": "node", "transformIgnorePatterns": [ + "jest-circus", "jest-jasmine2" ] }