From 675b8b3116915e11adfc3ef66929cd8e6c85523c 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 +- .github/workflows/nodejs.yml | 8 +- CHANGELOG.md | 1 + docs/CLI.md | 2 +- docs/Configuration.md | 6 +- docs/JestObjectAPI.md | 2 +- .../__snapshots__/showConfig.test.ts.snap | 2 +- e2e/__tests__/failureDetailsProperty.test.ts | 108 +++++++++--------- e2e/__tests__/locationInResults.test.ts | 16 +-- e2e/__tests__/nestedTestDefinitions.test.ts | 6 +- package.json | 4 +- 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 | 4 +- .../script_transformer.test.ts.snap | 8 +- .../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 +- 27 files changed, 135 insertions(+), 111 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/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index a4394c1efee3..949580f62cab 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -91,8 +91,8 @@ jobs: env: CI: true - test-circus: - name: Node LTS on ${{ matrix.os }} using jest-circus + test-jasmine: + name: Node LTS on ${{ matrix.os }} using jest-jasmine2 strategy: fail-fast: false matrix: @@ -127,7 +127,7 @@ jobs: - name: Get number of CPU cores id: cpu-cores uses: SimenB/github-actions-cpu-cores@v1 - - name: run tests using jest-circus - run: yarn jest-circus-ci --max-workers ${{ steps.cpu-cores.outputs.count }} + - name: run tests using jest-jasmine + run: yarn jest-jasmine-ci --max-workers ${{ steps.cpu-cores.outputs.count }} env: CI: true diff --git a/CHANGELOG.md b/CHANGELOG.md index 68cca5f06e33..781155053460 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)) - `[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)) diff --git a/docs/CLI.md b/docs/CLI.md index 08438abc085d..b23f0d25871e 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 1e4d164b125c..976929c0c1cf 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] @@ -1181,9 +1181,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__/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/package.json b/package.json index 24c9a930bbfe..08966c8426ae 100644 --- a/package.json +++ b/package.json @@ -98,8 +98,8 @@ "clean-all": "yarn clean-e2e && yarn build-clean && rimraf './packages/*/node_modules' && rimraf './node_modules'", "clean-e2e": "node ./scripts/cleanE2e.js", "jest": "node ./packages/jest-cli/bin/jest.js", - "jest-circus": "JEST_CIRCUS=1 yarn jest", - "jest-circus-ci": "yarn jest-circus --color --config jest.config.ci.js", + "jest-jasmine": "JEST_JASMINE=1 yarn jest", + "jest-jasmine-ci": "yarn jest-jasmine --color --config jest.config.ci.js", "jest-coverage": "yarn jest --coverage", "lint": "eslint . --cache --ext js,jsx,ts,tsx,md", "lint:prettier": "prettier '**/*.{md,yml,yaml}' 'website/static/**/*.{css,js}' --write --ignore-path .gitignore", 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 b05a85163070..33f5af18fdff 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 6cc766a06472..f4597cdb881c 100644 --- a/packages/jest-runner/package.json +++ b/packages/jest-runner/package.json @@ -40,7 +40,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 f5ff5fbedef7..ea1d6bf9e3b9 100644 --- a/packages/jest-runner/src/runTest.ts +++ b/packages/jest-runner/src/runTest.ts @@ -109,9 +109,7 @@ async function runTestInternal( ).default; const testFramework: TestFramework = interopRequireDefault( transformer.requireAndTranspileModule( - process.env.JEST_CIRCUS === '1' - ? 'jest-circus/runner' - : config.testRunner, + process.env.JEST_JASMINE === '1' ? 'jest-jasmine2' : 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 d935cd744c3e..a0a238fdab98 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 @@ -61,7 +61,7 @@ exports[`ScriptTransformer passes expected transform options to getCacheKey 1`] "testRegex": Array [ "\\\\.test\\\\.js$", ], - "testRunner": "jest-jasmine2", + "testRunner": "jest-circus/runner", "testURL": "http://localhost", "timers": "real", "transform": Array [ @@ -77,7 +77,7 @@ exports[`ScriptTransformer passes expected transform options to getCacheKey 1`] "unmockedModulePathPatterns": undefined, "watchPathIgnorePatterns": Array [], }, - "configString": "{\\"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\\":[]}", + "configString": "{\\"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\\":[]}", "coverageProvider": "babel", "instrument": true, "supportsDynamicImport": false, @@ -252,7 +252,7 @@ exports[`ScriptTransformer uses multiple preprocessors 1`] = ` const TRANSFORMED = { filename: '/fruits/banana.js', script: 'module.exports = "banana";', - config: '{"collectCoverage":false,"collectCoverageFrom":[],"coverageProvider":"babel","supportsDynamicImport":false,"supportsExportNamespaceFrom":false,"supportsStaticESM":false,"supportsTopLevelAwait":false,"instrument":false,"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":[]},"configString":"{\\"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: '{"collectCoverage":false,"collectCoverageFrom":[],"coverageProvider":"babel","supportsDynamicImport":false,"supportsExportNamespaceFrom":false,"supportsStaticESM":false,"supportsTopLevelAwait":false,"instrument":false,"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":[]},"configString":"{\\"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\\":[]}"}', }; `; @@ -269,7 +269,7 @@ exports[`ScriptTransformer uses the supplied preprocessor 1`] = ` const TRANSFORMED = { filename: '/fruits/banana.js', script: 'module.exports = "banana";', - config: '{"collectCoverage":false,"collectCoverageFrom":[],"coverageProvider":"babel","supportsDynamicImport":false,"supportsExportNamespaceFrom":false,"supportsStaticESM":false,"supportsTopLevelAwait":false,"instrument":false,"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":[]},"configString":"{\\"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: '{"collectCoverage":false,"collectCoverageFrom":[],"coverageProvider":"babel","supportsDynamicImport":false,"supportsExportNamespaceFrom":false,"supportsStaticESM":false,"supportsTopLevelAwait":false,"instrument":false,"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":[]},"configString":"{\\"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 f81132fa2215..33dbd1630baf 100644 --- a/packages/test-utils/src/config.ts +++ b/packages/test-utils/src/config.ts @@ -111,7 +111,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 f06703de94a8..f9f03244a4ee 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11757,6 +11757,7 @@ fsevents@~2.1.2: 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 @@ -12154,10 +12155,10 @@ fsevents@~2.1.2: 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