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 Oct 23, 2020
1 parent 1535af7 commit ecffde4
Show file tree
Hide file tree
Showing 28 changed files with 147 additions and 156 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 @@ -121,6 +121,6 @@ workflows:
- test-node-13
- 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 @@ -2,6 +2,7 @@

### Features

- `[*]` [**BREAKING**] Use `jest-circus` as default test runner ([#10686](https://github.com/facebook/jest/pull/10686))
- `[jest-core]` Add `findRelatedTests` and `nonFlagArgs` in allowed config options for `updateConfigAndRun` in watch plugins ([#10659](https://github.com/facebook/jest/pull/10659))

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
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 @@ -480,7 +480,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 @@ -1149,9 +1149,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 @@ -677,7 +677,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
9 changes: 4 additions & 5 deletions e2e/__tests__/circusConcurrentEach.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
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 runJest from '../runJest';
import {extractSummary} from '../Utils';

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
Loading

0 comments on commit ecffde4

Please sign in to comment.