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 15, 2020
1 parent 0a0ac60 commit bb2c4e2
Show file tree
Hide file tree
Showing 25 changed files with 130 additions and 104 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
2 changes: 2 additions & 0 deletions packages/jest-circus/README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit bb2c4e2

Please sign in to comment.