diff --git a/CHANGELOG.md b/CHANGELOG.md index e2d47d1a5316..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 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/async-regenerator/package.json b/e2e/async-regenerator/package.json index cc89a7733dc0..db1f1a7efbe8 100644 --- a/e2e/async-regenerator/package.json +++ b/e2e/async-regenerator/package.json @@ -6,6 +6,10 @@ "@babel/polyfill": "^7.2.5" }, "jest": { - "testEnvironment": "node" + "testEnvironment": "node", + "transformIgnorePatterns": [ + "jest-circus", + "jest-jasmine2" + ] } } diff --git a/e2e/babel-plugin-jest-hoist/package.json b/e2e/babel-plugin-jest-hoist/package.json index c498b7ef21bf..eac0243cf4d4 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-circus", + "jest-environment-node", + "jest-jasmine2" ] } } diff --git a/e2e/coverage-transform-instrumented/package.json b/e2e/coverage-transform-instrumented/package.json index 3bb4016f58a2..c571de5fed97 100644 --- a/e2e/coverage-transform-instrumented/package.json +++ b/e2e/coverage-transform-instrumented/package.json @@ -7,7 +7,10 @@ "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-linked-modules/package.json b/e2e/transform-linked-modules/package.json index 1bea4d7d023b..aef81a535be6 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-circus", + "jest-each", + "jest-environment-node", + "jest-jasmine2" ], "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..048789e0d624 100644 --- a/e2e/transform/babel-jest-ignored/babel.config.js +++ b/e2e/transform/babel-jest-ignored/babel.config.js @@ -5,4 +5,13 @@ * LICENSE file in the root directory of this source tree. */ -module.exports = {only: ['blablabla', /jest-environment-node/]}; +module.exports = { + only: [ + 'blablabla', + /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 074d79491bfc..e3760dfeae93 100644 --- a/e2e/transform/multiple-transformers/package.json +++ b/e2e/transform/multiple-transformers/package.json @@ -7,7 +7,9 @@ }, "testEnvironment": "node", "transformIgnorePatterns": [ - "/jest-environment-node/" + "jest-circus", + "jest-environment-node", + "jest-jasmine2" ] }, "dependencies": { 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..19dd8862b516 --- /dev/null +++ b/e2e/transform/transform-testrunner/babel.config.js @@ -0,0 +1,13 @@ +/** + * 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-env', {targets: {node: 'current'}}], + '@babel/preset-typescript', + ], +}; 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..0b08cd6ca5e5 --- /dev/null +++ b/e2e/transform/transform-testrunner/test-runner.ts @@ -0,0 +1,36 @@ +/** + * 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 {JestEnvironment} from '@jest/environment'; +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, +): Promise { + return { + ...createEmptyTestResult(), + numPassingTests: 1, + testFilePath: testPath, + testResults: [ + { + ancestorTitles: [], + duration: 2, + failureMessages: [], + fullName: 'sample test', + location: null, + numPassingAsserts: 1, + status: 'passed', + title: 'sample test', + }, + ], + }; +} 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 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