Skip to content

Commit

Permalink
feat: make jest-circus default test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Nov 26, 2020
1 parent e442dec commit 675b8b3
Show file tree
Hide file tree
Showing 27 changed files with 135 additions and 111 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Expand Up @@ -27,7 +27,7 @@ jobs:
- store_test_results:
path: reports/junit

test-jest-circus:
test-jest-jasmine:
working_directory: ~/jest
executor: node/default
steps:
Expand All @@ -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

Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions .github/workflows/nodejs.yml
Expand Up @@ -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:
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion docs/CLI.md
Expand Up @@ -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`

Expand Down
6 changes: 3 additions & 3 deletions docs/Configuration.md
Expand Up @@ -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]

Expand Down Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion docs/JestObjectAPI.md
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion e2e/__tests__/__snapshots__/showConfig.test.ts.snap
Expand Up @@ -62,7 +62,7 @@ exports[`--showConfig outputs config info and exits 1`] = `
"/node_modules/"
],
"testRegex": [],
"testRunner": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-jasmine2/build/index.js",
"testRunner": "<<REPLACED_JEST_PACKAGES_DIR>>/jest-circus/runner.js",
"testURL": "http://localhost",
"timers": "real",
"transform": [
Expand Down
108 changes: 54 additions & 54 deletions e2e/__tests__/failureDetailsProperty.test.ts
Expand Up @@ -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) =>
Expand All @@ -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 [
Expand Down Expand Up @@ -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",
},
],
]
`);
}
});
16 changes: 8 additions & 8 deletions e2e/__tests__/locationInResults.test.ts
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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,
});
});
6 changes: 3 additions & 3 deletions e2e/__tests__/nestedTestDefinitions.test.ts
Expand Up @@ -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';

Expand Down Expand Up @@ -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']);
Expand All @@ -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']);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-circus/README.md
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-cli/src/cli/args.ts
Expand Up @@ -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: ' +
'`<rootDir>/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:' +
' `<rootDir>/path/to/testRunner.js`.',
type: 'string',
},
testSequencer: {
Expand Down
Expand Up @@ -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\\",
Expand Down
1 change: 1 addition & 0 deletions packages/jest-config/package.json
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/Defaults.ts
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/jest-config/src/ValidConfig.ts
Expand Up @@ -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',
Expand Down

0 comments on commit 675b8b3

Please sign in to comment.