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 4, 2020
1 parent 2fa34c4 commit 68dd53e
Show file tree
Hide file tree
Showing 28 changed files with 147 additions and 157 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
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))

### Fixes
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 @@ -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:

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
9 changes: 4 additions & 5 deletions e2e/__tests__/circusConcurrentEach.test.ts
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
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
31 changes: 7 additions & 24 deletions e2e/__tests__/toMatchInlineSnapshotWithRetries.test.ts
Expand Up @@ -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';

Expand All @@ -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(`
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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.');
Expand All @@ -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);
}
Expand Down

0 comments on commit 68dd53e

Please sign in to comment.