From 68dd53e58b871259de4022530f47b62d1510df0e Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 23 Oct 2020 17:21:19 +0200 Subject: [PATCH] feat: make jest-circus default test runner --- .circleci/config.yml | 6 +- CHANGELOG.md | 1 + docs/CLI.md | 2 +- docs/Configuration.md | 6 +- docs/JestObjectAPI.md | 2 +- .../__snapshots__/showConfig.test.ts.snap | 2 +- e2e/__tests__/circusConcurrentEach.test.ts | 9 +- e2e/__tests__/failureDetailsProperty.test.ts | 108 +++++++++--------- e2e/__tests__/locationInResults.test.ts | 16 +-- e2e/__tests__/nestedTestDefinitions.test.ts | 6 +- .../toMatchInlineSnapshotWithRetries.test.ts | 31 ++--- .../toMatchSnapshotWithRetries.test.ts | 31 ++--- packages/jest-circus/README.md | 2 + packages/jest-cli/src/cli/args.ts | 6 +- .../__tests__/__snapshots__/init.test.js.snap | 2 +- packages/jest-config/package.json | 1 + packages/jest-config/src/Defaults.ts | 2 +- packages/jest-config/src/ValidConfig.ts | 2 +- .../src/__tests__/normalize.test.js | 25 +++- packages/jest-config/src/normalize.ts | 8 +- packages/jest-runner/package.json | 2 +- packages/jest-runner/src/runTest.ts | 5 +- .../script_transformer.test.ts.snap | 6 +- .../src/__tests__/fixtures/jestConfig.ts | 2 +- packages/test-utils/src/ConditionalTest.ts | 14 +-- packages/test-utils/src/config.ts | 2 +- packages/test-utils/src/index.ts | 2 +- yarn.lock | 3 +- 28 files changed, 147 insertions(+), 157 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6738ed738e37..378809c9ddea 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,7 +27,7 @@ jobs: - store_test_results: path: reports/junit - test-jest-circus: + test-jest-jasmine: working_directory: ~/jest executor: node/default steps: @@ -37,7 +37,7 @@ jobs: install-npm: false - node/install-packages: *install - run: - command: JEST_CIRCUS=1 yarn test-ci-partial && JEST_CIRCUS=1 yarn test-leak + command: JEST_JASMINE=1 yarn test-ci-partial && JEST_JASMINE=1 yarn test-leak - store_test_results: path: reports/junit @@ -106,6 +106,6 @@ workflows: - test-node-12 - test-node-14 - test-node-15 # current - - test-jest-circus + - test-jest-jasmine - test-or-deploy-website: filters: *filter-ignore-gh-pages diff --git a/CHANGELOG.md b/CHANGELOG.md index 130cfdad2da8..1886a2c137a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### Features - `[jest-config]` [**BREAKING**] Default to Node testing environment instead of browser (JSDOM) ([#9874](https://github.com/facebook/jest/pull/9874)) +- `[jest-config]` [**BREAKING**] Use `jest-circus` as default test runner ([#10686](https://github.com/facebook/jest/pull/10686)) - `[jest-runner]` [**BREAKING**] set exit code to 1 if test logs after teardown ([#10728](https://github.com/facebook/jest/pull/10728)) ### Fixes diff --git a/docs/CLI.md b/docs/CLI.md index a2ca1f24b41a..291d266fa9a2 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -208,7 +208,7 @@ test('some test', () => { }); ``` -_Note: This option is only supported using `jest-circus`._ +_Note: This option is only supported using the default `jest-circus`. test runner_ ### `--json` diff --git a/docs/Configuration.md b/docs/Configuration.md index 585910460707..1149be734171 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -501,7 +501,7 @@ test('some test', () => { }); ``` -_Note: This option is only supported using `jest-circus`._ +_Note: This option is only supported using the default `jest-circus`. test runner_ ### `maxConcurrency` [number] @@ -1170,9 +1170,9 @@ This option allows the use of a custom results processor. This processor must be ### `testRunner` [string] -Default: `jasmine2` +Default: `jest-circus/runner` -This option allows the use of a custom test runner. The default is jasmine2. A custom test runner can be provided by specifying a path to a test runner implementation. +This option allows the use of a custom test runner. The default is `jest-circus`. A custom test runner can be provided by specifying a path to a test runner implementation. The test runner module must export a function with the following signature: diff --git a/docs/JestObjectAPI.md b/docs/JestObjectAPI.md index 5553a5d58561..c3dbeae8e808 100644 --- a/docs/JestObjectAPI.md +++ b/docs/JestObjectAPI.md @@ -672,7 +672,7 @@ jest.setTimeout(1000); // 1 second ### `jest.retryTimes()` -Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with [jest-circus](https://github.com/facebook/jest/tree/master/packages/jest-circus)! +Runs failed tests n-times until they pass or until the max number of retries is exhausted. This only works with the default [jest-circus](https://github.com/facebook/jest/tree/master/packages/jest-circus) runner! Example in a test: diff --git a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap index 9e24197f7ab0..91b0acdb0468 100644 --- a/e2e/__tests__/__snapshots__/showConfig.test.ts.snap +++ b/e2e/__tests__/__snapshots__/showConfig.test.ts.snap @@ -62,7 +62,7 @@ exports[`--showConfig outputs config info and exits 1`] = ` "/node_modules/" ], "testRegex": [], - "testRunner": "<>/jest-jasmine2/build/index.js", + "testRunner": "<>/jest-circus/runner.js", "testURL": "http://localhost", "timers": "real", "transform": [ diff --git a/e2e/__tests__/circusConcurrentEach.test.ts b/e2e/__tests__/circusConcurrentEach.test.ts index 27ef656e99b9..ca53c2605357 100644 --- a/e2e/__tests__/circusConcurrentEach.test.ts +++ b/e2e/__tests__/circusConcurrentEach.test.ts @@ -4,13 +4,13 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ +import {skipSuiteOnJasmine} from '@jest/test-utils'; import {json as runWithJson} from '../runJest'; +skipSuiteOnJasmine(); + it('works with concurrent.each', () => { - const {json} = runWithJson('circus-concurrent', [ - 'concurrent-each.test.js', - '--testRunner=jest-circus/runner', - ]); + const {json} = runWithJson('circus-concurrent', ['concurrent-each.test.js']); expect(json.numTotalTests).toBe(4); expect(json.numPassedTests).toBe(2); expect(json.numFailedTests).toBe(0); @@ -20,7 +20,6 @@ it('works with concurrent.each', () => { it('works with concurrent.only.each', () => { const {json} = runWithJson('circus-concurrent', [ 'concurrent-only-each.test.js', - '--testRunner=jest-circus/runner', ]); expect(json.numTotalTests).toBe(4); expect(json.numPassedTests).toBe(2); diff --git a/e2e/__tests__/failureDetailsProperty.test.ts b/e2e/__tests__/failureDetailsProperty.test.ts index 3e4130a0052b..48c44f919d37 100644 --- a/e2e/__tests__/failureDetailsProperty.test.ts +++ b/e2e/__tests__/failureDetailsProperty.test.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import {isJestCircusRun} from '@jest/test-utils'; +import {isJestJasmineRun} from '@jest/test-utils'; import runJest from '../runJest'; const removeStackTraces = (stdout: string) => @@ -24,59 +24,7 @@ test('that the failureDetails property is set', () => { const output = JSON.parse(removeStackTraces(stdout)); - if (isJestCircusRun()) { - expect(output).toMatchInlineSnapshot(` - Array [ - Array [ - Object { - "matcherResult": Object { - "actual": true, - "expected": false, - "name": "toBe", - "pass": false, - }, - }, - ], - Array [ - Object { - "matcherResult": Object { - "actual": true, - "expected": false, - "name": "toBe", - "pass": false, - }, - }, - ], - Array [ - Object { - "matcherResult": Object { - "actual": "Object { - \\"p1\\": \\"hello\\", - \\"p2\\": \\"world\\", - }", - "expected": "Object { - \\"p1\\": \\"hello\\", - \\"p2\\": \\"sunshine\\", - }", - "name": "toMatchInlineSnapshot", - "pass": false, - }, - }, - ], - Array [ - Object {}, - ], - Array [ - Object { - "message": "expect(received).rejects.toThrowError() - - Received promise resolved instead of rejected - Resolved to value: 1", - }, - ], - ] - `); - } else { + if (isJestJasmineRun()) { expect(output).toMatchInlineSnapshot(` Array [ Array [ @@ -213,5 +161,57 @@ test('that the failureDetails property is set', () => { ], ] `); + } else { + expect(output).toMatchInlineSnapshot(` + Array [ + Array [ + Object { + "matcherResult": Object { + "actual": true, + "expected": false, + "name": "toBe", + "pass": false, + }, + }, + ], + Array [ + Object { + "matcherResult": Object { + "actual": true, + "expected": false, + "name": "toBe", + "pass": false, + }, + }, + ], + Array [ + Object { + "matcherResult": Object { + "actual": "Object { + \\"p1\\": \\"hello\\", + \\"p2\\": \\"world\\", + }", + "expected": "Object { + \\"p1\\": \\"hello\\", + \\"p2\\": \\"sunshine\\", + }", + "name": "toMatchInlineSnapshot", + "pass": false, + }, + }, + ], + Array [ + Object {}, + ], + Array [ + Object { + "message": "expect(received).rejects.toThrowError() + + Received promise resolved instead of rejected + Resolved to value: 1", + }, + ], + ] + `); } }); diff --git a/e2e/__tests__/locationInResults.test.ts b/e2e/__tests__/locationInResults.test.ts index 25808059c29c..f3bd59d64c8b 100644 --- a/e2e/__tests__/locationInResults.test.ts +++ b/e2e/__tests__/locationInResults.test.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import {isJestCircusRun} from '@jest/test-utils'; +import {isJestJasmineRun} from '@jest/test-utils'; import {json as runWithJson} from '../runJest'; it('defaults to null for location', () => { @@ -45,39 +45,39 @@ it('adds correct location info when provided with flag', () => { }); expect(assertions[3].location).toEqual({ - column: isJestCircusRun() ? 1 : 22, + column: isJestJasmineRun() ? 22 : 1, line: 24, }); expect(assertions[4].location).toEqual({ - column: isJestCircusRun() ? 1 : 22, + column: isJestJasmineRun() ? 22 : 1, line: 24, }); // Technically the column should be 3, but callsites is not correct. // jest-circus uses stack-utils + asyncErrors which resolves this. expect(assertions[5].location).toEqual({ - column: isJestCircusRun() ? 3 : 2, + column: isJestJasmineRun() ? 2 : 3, line: 29, }); expect(assertions[6].location).toEqual({ - column: isJestCircusRun() ? 3 : 2, + column: isJestJasmineRun() ? 2 : 3, line: 33, }); expect(assertions[7].location).toEqual({ - column: isJestCircusRun() ? 3 : 2, + column: isJestJasmineRun() ? 2 : 3, line: 37, }); expect(assertions[8].location).toEqual({ - column: isJestCircusRun() ? 3 : 24, + column: isJestJasmineRun() ? 24 : 3, line: 41, }); expect(assertions[9].location).toEqual({ - column: isJestCircusRun() ? 3 : 24, + column: isJestJasmineRun() ? 24 : 3, line: 41, }); }); diff --git a/e2e/__tests__/nestedTestDefinitions.test.ts b/e2e/__tests__/nestedTestDefinitions.test.ts index b5830c8ffd35..adf43115cd76 100644 --- a/e2e/__tests__/nestedTestDefinitions.test.ts +++ b/e2e/__tests__/nestedTestDefinitions.test.ts @@ -6,7 +6,7 @@ */ import {wrap} from 'jest-snapshot-serializer-raw'; -import {isJestCircusRun} from '@jest/test-utils'; +import {isJestJasmineRun} from '@jest/test-utils'; import {extractSummary} from '../Utils'; import runJest from '../runJest'; @@ -42,7 +42,7 @@ test('print correct error message with nested test definitions inside describe', expect(cleanupRunnerStack(summary.rest)).toMatchSnapshot(); }); -(isJestCircusRun() ? test : test.skip)( +(isJestJasmineRun() ? test.skip : test)( 'print correct message when nesting describe inside it', () => { const result = runJest('nested-test-definitions', ['nestedDescribeInTest']); @@ -55,7 +55,7 @@ test('print correct error message with nested test definitions inside describe', }, ); -(isJestCircusRun() ? test : test.skip)( +(isJestJasmineRun() ? test.skip : test)( 'print correct message when nesting a hook inside it', () => { const result = runJest('nested-test-definitions', ['nestedHookInTest']); diff --git a/e2e/__tests__/toMatchInlineSnapshotWithRetries.test.ts b/e2e/__tests__/toMatchInlineSnapshotWithRetries.test.ts index ed3583e67276..9ec508524f7f 100644 --- a/e2e/__tests__/toMatchInlineSnapshotWithRetries.test.ts +++ b/e2e/__tests__/toMatchInlineSnapshotWithRetries.test.ts @@ -6,6 +6,7 @@ */ import * as path from 'path'; +import {skipSuiteOnJasmine} from '@jest/test-utils'; import {cleanup, makeTemplate, writeFiles} from '../Utils'; import runJest from '../runJest'; @@ -15,6 +16,8 @@ const TESTS_DIR = path.resolve(DIR, '__tests__'); beforeEach(() => cleanup(TESTS_DIR)); afterAll(() => cleanup(TESTS_DIR)); +skipSuiteOnJasmine(); + test('works with a single snapshot', () => { const filename = 'basic-support.test.js'; const template = makeTemplate(` @@ -39,12 +42,7 @@ test('works with a single snapshot', () => { writeFiles(TESTS_DIR, { [filename]: template(['index', '2' /* retries */]), }); - const {stderr, exitCode} = runJest(DIR, [ - '-w=1', - '--ci=false', - '--testRunner=jest-circus/runner', - filename, - ]); + const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('Received: 2'); expect(stderr).toMatch('1 snapshot failed from 1 test suite.'); expect(exitCode).toBe(1); @@ -54,12 +52,7 @@ test('works with a single snapshot', () => { writeFiles(TESTS_DIR, { [filename]: template(['index', '4' /* retries */]), }); - const {stderr, exitCode} = runJest(DIR, [ - '-w=1', - '--ci=false', - '--testRunner=jest-circus/runner', - filename, - ]); + const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('Snapshots: 1 passed, 1 total'); expect(exitCode).toBe(0); } @@ -113,12 +106,7 @@ test('works when multiple tests have snapshots but only one of them failed multi writeFiles(TESTS_DIR, { [filename]: template(['index', '2' /* retries */]), }); - const {stderr, exitCode} = runJest(DIR, [ - '-w=1', - '--ci=false', - '--testRunner=jest-circus/runner', - filename, - ]); + const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('Snapshot name: `with retries snapshots 1`'); expect(stderr).toMatch('Received: 2'); expect(stderr).toMatch('1 snapshot failed from 1 test suite.'); @@ -129,12 +117,7 @@ test('works when multiple tests have snapshots but only one of them failed multi writeFiles(TESTS_DIR, { [filename]: template(['index', '4' /* retries */]), }); - const {stderr, exitCode} = runJest(DIR, [ - '-w=1', - '--ci=false', - '--testRunner=jest-circus/runner', - filename, - ]); + const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('Snapshots: 1 passed, 1 total'); expect(exitCode).toBe(0); } diff --git a/e2e/__tests__/toMatchSnapshotWithRetries.test.ts b/e2e/__tests__/toMatchSnapshotWithRetries.test.ts index ef20f9a854c6..977ab9018251 100644 --- a/e2e/__tests__/toMatchSnapshotWithRetries.test.ts +++ b/e2e/__tests__/toMatchSnapshotWithRetries.test.ts @@ -6,6 +6,7 @@ */ import * as path from 'path'; +import {skipSuiteOnJasmine} from '@jest/test-utils'; import {cleanup, makeTemplate, writeFiles} from '../Utils'; import runJest from '../runJest'; @@ -15,6 +16,8 @@ const TESTS_DIR = path.resolve(DIR, '__tests__'); beforeEach(() => cleanup(TESTS_DIR)); afterAll(() => cleanup(TESTS_DIR)); +skipSuiteOnJasmine(); + test('works with a single snapshot', () => { const filename = 'basic-support.test.js'; const template = makeTemplate(` @@ -39,12 +42,7 @@ test('works with a single snapshot', () => { writeFiles(TESTS_DIR, { [filename]: template(['index', '2' /* retries */]), }); - const {stderr, exitCode} = runJest(DIR, [ - '-w=1', - '--ci=false', - '--testRunner=jest-circus/runner', - filename, - ]); + const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('Received: 2'); expect(stderr).toMatch('1 snapshot failed from 1 test suite.'); expect(exitCode).toBe(1); @@ -54,12 +52,7 @@ test('works with a single snapshot', () => { writeFiles(TESTS_DIR, { [filename]: template(['index', '4' /* retries */]), }); - const {stderr, exitCode} = runJest(DIR, [ - '-w=1', - '--ci=false', - '--testRunner=jest-circus/runner', - filename, - ]); + const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('Snapshots: 1 passed, 1 total'); expect(exitCode).toBe(0); } @@ -92,12 +85,7 @@ test('works when multiple tests have snapshots but only one of them failed multi writeFiles(TESTS_DIR, { [filename]: template(['index', '2' /* retries */]), }); - const {stderr, exitCode} = runJest(DIR, [ - '-w=1', - '--ci=false', - '--testRunner=jest-circus/runner', - filename, - ]); + const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('Received: 2'); expect(stderr).toMatch('1 snapshot failed from 1 test suite.'); expect(exitCode).toBe(1); @@ -107,12 +95,7 @@ test('works when multiple tests have snapshots but only one of them failed multi writeFiles(TESTS_DIR, { [filename]: template(['index', '4' /* retries */]), }); - const {stderr, exitCode} = runJest(DIR, [ - '-w=1', - '--ci=false', - '--testRunner=jest-circus/runner', - filename, - ]); + const {stderr, exitCode} = runJest(DIR, ['-w=1', '--ci=false', filename]); expect(stderr).toMatch('Snapshots: 1 passed, 1 total'); expect(exitCode).toBe(0); } diff --git a/packages/jest-circus/README.md b/packages/jest-circus/README.md index f2644d412dfd..60fe17732c08 100644 --- a/packages/jest-circus/README.md +++ b/packages/jest-circus/README.md @@ -32,6 +32,8 @@ Note, that `jest-circus` test runner would pause until a promise returned from ` ## Installation +> Note: As of Jest 27, `jest-circus` is the default test runner, so you do not have to install it to use it. + Install `jest-circus` using yarn: ```bash diff --git a/packages/jest-cli/src/cli/args.ts b/packages/jest-cli/src/cli/args.ts index 61a637eda59f..fe74a2f6c4c1 100644 --- a/packages/jest-cli/src/cli/args.ts +++ b/packages/jest-cli/src/cli/args.ts @@ -650,9 +650,9 @@ export const options = { }, testRunner: { description: - 'Allows to specify a custom test runner. The default is ' + - ' `jasmine2`. A path to a custom test runner can be provided: ' + - '`/path/to/testRunner.js`.', + 'Allows to specify a custom test runner. The default is' + + ' `jest-circus/runner`. A path to a custom test runner can be provided:' + + ' `/path/to/testRunner.js`.', type: 'string', }, testSequencer: { diff --git a/packages/jest-cli/src/init/__tests__/__snapshots__/init.test.js.snap b/packages/jest-cli/src/init/__tests__/__snapshots__/init.test.js.snap index 9656efe20bf3..05ec66cc3afc 100644 --- a/packages/jest-cli/src/init/__tests__/__snapshots__/init.test.js.snap +++ b/packages/jest-cli/src/init/__tests__/__snapshots__/init.test.js.snap @@ -281,7 +281,7 @@ module.exports = { // testResultsProcessor: undefined, // This option allows use of a custom test runner - // testRunner: \\"jasmine2\\", + // testRunner: \\"jest-circus/runner\\", // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href // testURL: \\"http://localhost\\", diff --git a/packages/jest-config/package.json b/packages/jest-config/package.json index 91d7ca643b5a..0e5203512ad2 100644 --- a/packages/jest-config/package.json +++ b/packages/jest-config/package.json @@ -30,6 +30,7 @@ "deepmerge": "^4.2.2", "glob": "^7.1.1", "graceful-fs": "^4.2.4", + "jest-circus": "^26.6.3", "jest-environment-jsdom": "^26.6.2", "jest-environment-node": "^26.6.2", "jest-get-type": "^26.3.0", diff --git a/packages/jest-config/src/Defaults.ts b/packages/jest-config/src/Defaults.ts index 0c8ef6bbf4db..82ea0b7b8394 100644 --- a/packages/jest-config/src/Defaults.ts +++ b/packages/jest-config/src/Defaults.ts @@ -61,7 +61,7 @@ const defaultOptions: Config.DefaultOptions = { testMatch: ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'], testPathIgnorePatterns: [NODE_MODULES_REGEXP], testRegex: [], - testRunner: 'jasmine2', + testRunner: 'jest-circus/runner', testSequencer: '@jest/test-sequencer', testURL: 'http://localhost', timers: 'real', diff --git a/packages/jest-config/src/ValidConfig.ts b/packages/jest-config/src/ValidConfig.ts index 712f1fb967b5..86b6aeb7e0dd 100644 --- a/packages/jest-config/src/ValidConfig.ts +++ b/packages/jest-config/src/ValidConfig.ts @@ -114,7 +114,7 @@ const initialOptions: Config.InitialOptions = { ['/__tests__/\\.test\\.[jt]sx?$', '/__tests__/\\.spec\\.[jt]sx?$'], ), testResultsProcessor: 'processor-node-module', - testRunner: 'jasmine2', + testRunner: 'circus', testSequencer: '@jest/test-sequencer', testTimeout: 5000, testURL: 'http://localhost', diff --git a/packages/jest-config/src/__tests__/normalize.test.js b/packages/jest-config/src/__tests__/normalize.test.js index f43174c43757..bbd217bfae73 100644 --- a/packages/jest-config/src/__tests__/normalize.test.js +++ b/packages/jest-config/src/__tests__/normalize.test.js @@ -33,7 +33,7 @@ let expectedPathAbs; let expectedPathAbsAnother; let virtualModuleRegexes; -beforeEach(() => (virtualModuleRegexes = [/jest-jasmine2/, /babel-jest/])); +beforeEach(() => (virtualModuleRegexes = [/jest-circus/, /babel-jest/])); const findNodeModule = jest.fn(name => { if (virtualModuleRegexes.some(regex => regex.test(name))) { return name; @@ -659,7 +659,7 @@ describe('modulePathIgnorePatterns', () => { }); describe('testRunner', () => { - it('defaults to Jasmine 2', () => { + it('defaults to Circus', () => { const {options} = normalize( { rootDir: '/root/path/foo', @@ -667,7 +667,22 @@ describe('testRunner', () => { {}, ); - expect(options.testRunner).toMatch('jasmine2'); + expect(options.testRunner).toMatch('jest-circus'); + }); + + it('resolves jasmine', () => { + const Resolver = require('jest-resolve').default; + Resolver.findNodeModule = jest.fn(name => name); + const {options} = normalize( + { + rootDir: '/root/path/foo', + }, + { + testRunner: 'jasmine2', + }, + ); + + expect(options.testRunner).toMatch('jest-jasmine2'); }); it('is overwritten by argv', () => { @@ -678,11 +693,11 @@ describe('testRunner', () => { rootDir: '/root/path/foo', }, { - testRunner: 'jasmine1', + testRunner: 'mocha', }, ); - expect(options.testRunner).toBe('jasmine1'); + expect(options.testRunner).toBe('mocha'); }); }); diff --git a/packages/jest-config/src/normalize.ts b/packages/jest-config/src/normalize.ts index 97ea8dc7bfe2..8959ebbd68f7 100644 --- a/packages/jest-config/src/normalize.ts +++ b/packages/jest-config/src/normalize.ts @@ -555,7 +555,13 @@ export default function normalize( options.roots = [options.rootDir]; } - if (!options.testRunner || options.testRunner === 'jasmine2') { + if ( + !options.testRunner || + options.testRunner === 'circus' || + options.testRunner === 'jest-circus' + ) { + options.testRunner = require.resolve('jest-circus/runner'); + } else if (options.testRunner === 'jasmine2') { options.testRunner = require.resolve('jest-jasmine2'); } diff --git a/packages/jest-runner/package.json b/packages/jest-runner/package.json index 3060883e0e22..324133d77798 100644 --- a/packages/jest-runner/package.json +++ b/packages/jest-runner/package.json @@ -39,7 +39,7 @@ "@types/exit": "^0.1.30", "@types/graceful-fs": "^4.1.2", "@types/source-map-support": "^0.5.0", - "jest-circus": "^26.6.3" + "jest-jasmine2": "^26.6.3" }, "engines": { "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" diff --git a/packages/jest-runner/src/runTest.ts b/packages/jest-runner/src/runTest.ts index 1174753dfb5d..3596f2d6d3a4 100644 --- a/packages/jest-runner/src/runTest.ts +++ b/packages/jest-runner/src/runTest.ts @@ -106,9 +106,8 @@ async function runTestInternal( require(testEnvironment), ).default; const testFramework: TestFramework = interopRequireDefault( - process.env.JEST_CIRCUS === '1' - ? // eslint-disable-next-line import/no-extraneous-dependencies - require('jest-circus/runner') + process.env.JEST_JASMINE === '1' + ? require('jest-jasmine2') : require(config.testRunner), ).default; const Runtime: typeof RuntimeClass = interopRequireDefault( diff --git a/packages/jest-transform/src/__tests__/__snapshots__/script_transformer.test.ts.snap b/packages/jest-transform/src/__tests__/__snapshots__/script_transformer.test.ts.snap index c9021bd66fb9..3180864d35a9 100644 --- a/packages/jest-transform/src/__tests__/__snapshots__/script_transformer.test.ts.snap +++ b/packages/jest-transform/src/__tests__/__snapshots__/script_transformer.test.ts.snap @@ -53,7 +53,7 @@ Object { "testRegex": Array [ "\\\\.test\\\\.js$", ], - "testRunner": "jest-jasmine2", + "testRunner": "jest-circus/runner", "testURL": "http://localhost", "timers": "real", "transform": Array [ @@ -234,7 +234,7 @@ exports[`ScriptTransformer uses multiple preprocessors 1`] = ` const TRANSFORMED = { filename: '/fruits/banana.js', script: 'module.exports = "banana";', - config: '{"automock":false,"cache":true,"cacheDirectory":"/cache/","clearMocks":false,"coveragePathIgnorePatterns":[],"cwd":"/test_root_dir/","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{},"haste":{},"injectGlobals":true,"moduleDirectories":[],"moduleFileExtensions":["js"],"moduleLoader":"/test_module_loader_path","moduleNameMapper":[],"modulePathIgnorePatterns":[],"modulePaths":[],"name":"test","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"/","roots":[],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"skipNodeResolution":false,"slowTestThreshold":5,"snapshotSerializers":[],"testEnvironment":"node","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":[],"testRegex":["\\\\.test\\\\.js$"],"testRunner":"jest-jasmine2","testURL":"http://localhost","timers":"real","transform":[["\\\\.js$","test_preprocessor",{}],["\\\\.css$","css-preprocessor",{}]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]}', + config: '{"automock":false,"cache":true,"cacheDirectory":"/cache/","clearMocks":false,"coveragePathIgnorePatterns":[],"cwd":"/test_root_dir/","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{},"haste":{},"injectGlobals":true,"moduleDirectories":[],"moduleFileExtensions":["js"],"moduleLoader":"/test_module_loader_path","moduleNameMapper":[],"modulePathIgnorePatterns":[],"modulePaths":[],"name":"test","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"/","roots":[],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"skipNodeResolution":false,"slowTestThreshold":5,"snapshotSerializers":[],"testEnvironment":"node","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":[],"testRegex":["\\\\.test\\\\.js$"],"testRunner":"jest-circus/runner","testURL":"http://localhost","timers":"real","transform":[["\\\\.js$","test_preprocessor",{}],["\\\\.css$","css-preprocessor",{}]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]}', }; `; @@ -251,7 +251,7 @@ exports[`ScriptTransformer uses the supplied preprocessor 1`] = ` const TRANSFORMED = { filename: '/fruits/banana.js', script: 'module.exports = "banana";', - config: '{"automock":false,"cache":true,"cacheDirectory":"/cache/","clearMocks":false,"coveragePathIgnorePatterns":[],"cwd":"/test_root_dir/","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{},"haste":{},"injectGlobals":true,"moduleDirectories":[],"moduleFileExtensions":["js"],"moduleLoader":"/test_module_loader_path","moduleNameMapper":[],"modulePathIgnorePatterns":[],"modulePaths":[],"name":"test","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"/","roots":[],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"skipNodeResolution":false,"slowTestThreshold":5,"snapshotSerializers":[],"testEnvironment":"node","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":[],"testRegex":["\\\\.test\\\\.js$"],"testRunner":"jest-jasmine2","testURL":"http://localhost","timers":"real","transform":[["\\\\.js$","test_preprocessor",{}]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]}', + config: '{"automock":false,"cache":true,"cacheDirectory":"/cache/","clearMocks":false,"coveragePathIgnorePatterns":[],"cwd":"/test_root_dir/","detectLeaks":false,"detectOpenHandles":false,"errorOnDeprecated":false,"extraGlobals":[],"forceCoverageMatch":[],"globals":{},"haste":{},"injectGlobals":true,"moduleDirectories":[],"moduleFileExtensions":["js"],"moduleLoader":"/test_module_loader_path","moduleNameMapper":[],"modulePathIgnorePatterns":[],"modulePaths":[],"name":"test","prettierPath":"prettier","resetMocks":false,"resetModules":false,"restoreMocks":false,"rootDir":"/","roots":[],"runner":"jest-runner","setupFiles":[],"setupFilesAfterEnv":[],"skipFilter":false,"skipNodeResolution":false,"slowTestThreshold":5,"snapshotSerializers":[],"testEnvironment":"node","testEnvironmentOptions":{},"testLocationInResults":false,"testMatch":[],"testPathIgnorePatterns":[],"testRegex":["\\\\.test\\\\.js$"],"testRunner":"jest-circus/runner","testURL":"http://localhost","timers":"real","transform":[["\\\\.js$","test_preprocessor",{}]],"transformIgnorePatterns":["/node_modules/"],"watchPathIgnorePatterns":[]}', }; `; diff --git a/packages/jest-validate/src/__tests__/fixtures/jestConfig.ts b/packages/jest-validate/src/__tests__/fixtures/jestConfig.ts index da7a4c201017..f157b5d80312 100644 --- a/packages/jest-validate/src/__tests__/fixtures/jestConfig.ts +++ b/packages/jest-validate/src/__tests__/fixtures/jestConfig.ts @@ -111,7 +111,7 @@ const validConfig = { testPathIgnorePatterns: [NODE_MODULES_REGEXP], testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.[jt]sx?$', testResultsProcessor: 'processor-node-module', - testRunner: 'jasmine2', + testRunner: 'circus', testURL: 'http://localhost', timers: 'real', transform: { diff --git a/packages/test-utils/src/ConditionalTest.ts b/packages/test-utils/src/ConditionalTest.ts index b56aca5d18cc..53e1f965e969 100644 --- a/packages/test-utils/src/ConditionalTest.ts +++ b/packages/test-utils/src/ConditionalTest.ts @@ -9,12 +9,12 @@ import semver = require('semver'); -export function isJestCircusRun(): boolean { - return process.env.JEST_CIRCUS === '1'; +export function isJestJasmineRun(): boolean { + return process.env.JEST_JASMINE === '1'; } export function skipSuiteOnJasmine(): void { - if (!isJestCircusRun()) { + if (isJestJasmineRun()) { test.only('does not work on Jasmine', () => { console.warn('[SKIP] Does not work on Jasmine'); }); @@ -22,7 +22,7 @@ export function skipSuiteOnJasmine(): void { } export function skipSuiteOnJestCircus(): void { - if (isJestCircusRun()) { + if (!isJestJasmineRun()) { test.only('does not work on jest-circus', () => { console.warn('[SKIP] Does not work on jest-circus'); }); @@ -34,12 +34,12 @@ export function onNodeVersions( testBody: () => void, ): void { const description = `on node ${versionRange}`; - if (!semver.satisfies(process.versions.node, versionRange)) { - describe.skip(description, () => { + if (semver.satisfies(process.versions.node, versionRange)) { + describe(description, () => { testBody(); }); } else { - describe(description, () => { + describe.skip(description, () => { testBody(); }); } diff --git a/packages/test-utils/src/config.ts b/packages/test-utils/src/config.ts index fbd6226809eb..ccccc0f351d5 100644 --- a/packages/test-utils/src/config.ts +++ b/packages/test-utils/src/config.ts @@ -112,7 +112,7 @@ const DEFAULT_PROJECT_CONFIG: Config.ProjectConfig = { testMatch: [], testPathIgnorePatterns: [], testRegex: ['\\.test\\.js$'], - testRunner: 'jest-jasmine2', + testRunner: 'jest-circus/runner', testURL: 'http://localhost', timers: 'real', transform: [], diff --git a/packages/test-utils/src/index.ts b/packages/test-utils/src/index.ts index b7a69b751cc1..a35e355d297b 100644 --- a/packages/test-utils/src/index.ts +++ b/packages/test-utils/src/index.ts @@ -8,7 +8,7 @@ export {alignedAnsiStyleSerializer} from './alignedAnsiStyleSerializer'; export { - isJestCircusRun, + isJestJasmineRun, skipSuiteOnJasmine, skipSuiteOnJestCircus, onNodeVersions, diff --git a/yarn.lock b/yarn.lock index 874c0baf64a9..b9813b923844 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11578,6 +11578,7 @@ fsevents@^1.2.7: deepmerge: ^4.2.2 glob: ^7.1.1 graceful-fs: ^4.2.4 + jest-circus: ^26.6.3 jest-environment-jsdom: ^26.6.2 jest-environment-node: ^26.6.2 jest-get-type: ^26.3.0 @@ -11969,10 +11970,10 @@ fsevents@^1.2.7: emittery: ^0.7.1 exit: ^0.1.2 graceful-fs: ^4.2.4 - jest-circus: ^26.6.3 jest-config: ^26.6.3 jest-docblock: ^26.0.0 jest-haste-map: ^26.6.2 + jest-jasmine2: ^26.6.3 jest-leak-detector: ^26.6.2 jest-message-util: ^26.6.2 jest-resolve: ^26.6.2