-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jest-circus runs children in shuffled order #12922
Changes from 36 commits
e43ca99
bbb1cf3
4c1d07c
99ac4cd
882f920
4df23a9
dc6e64f
3d09cfb
f8860e2
0bec19f
3a1d712
95590dc
14349bd
549988d
4ae8ff2
967b32e
561146c
2f95b65
50bada0
b78fdc2
3f33508
d84caa1
b5c34fe
b9c5139
1b412b4
c45244c
e1e73a0
2152031
6bb9449
164d6fa
79401d1
b6c4da4
19cf2b5
ca3a582
2007d47
9361b80
4d61ba2
a087ce6
7b4bd2b
b175652
54cc38c
974bc5b
b4e448f
816b8e6
4ba33d4
7b40ca5
ebf01d5
9172451
0797346
9c0ff4e
604499d
001d150
30b3452
8661cad
81d526b
825fdd9
7512738
888f565
a6f6982
57e9836
b844e1b
bbc70a1
d4509cb
6ce659d
7bdad9f
08ed42c
5fd2e2a
2bffe52
f5b919c
2688290
ec85fb8
94c0740
e212ed9
5946e84
ebe2485
c5145a6
4705449
af913e2
a6b4d06
e4f0b24
c4baaaa
87547f3
8bfa4c8
0202230
3a0a4f1
43d6f8b
7bd3fe1
cff3995
7c8bfc1
c3c6516
d57bf1c
1137ce1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ | |||||
|
||||||
### Features | ||||||
|
||||||
- `[jest-circus, jest-cli, jest-config, @jest/core, @jest/types, @jest-util]` Add cli feature to randomize order or tests ([#12922](https://github.com/facebook/jest/pull/12922)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
- `[jest-config]` Add `readInitialConfig` utility function ([#13356](https://github.com/facebook/jest/pull/13356)) | ||||||
- `[jest-core]` Enable testResultsProcessor to be async ([#13343](https://github.com/facebook/jest/pull/13343)) | ||||||
- `[expect, @jest/expect-utils]` Allow `isA` utility to take a type argument ([#13355](https://github.com/facebook/jest/pull/13355)) | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -318,6 +318,26 @@ If configuration files are found in the specified paths, _all_ projects specifie | |||||
|
||||||
::: | ||||||
|
||||||
### `--randomize` | ||||||
|
||||||
Shuffle the order of the tests within a file. The seed used to generate the new order will be printed to stdout. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add something along the lines of "passing the same |
||||||
|
||||||
:::tip | ||||||
jhwang98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
Additionally you can use the [`--seed`](#--seed) flag to pass the seed value: | ||||||
|
||||||
```bash | ||||||
jest --randomize --seed 1234 | ||||||
``` | ||||||
|
||||||
::: | ||||||
|
||||||
:::note | ||||||
|
||||||
This option is only supported using the default `jest-circus` test runner. | ||||||
|
||||||
::: | ||||||
|
||||||
### `--reporters` | ||||||
|
||||||
Run tests with specified reporters. [Reporter options](configuration#reporters-arraymodulename--modulename-options) are not available via CLI. Example with multiple reporters: | ||||||
|
@@ -350,6 +370,20 @@ The default regex matching works fine on small runs, but becomes slow if provide | |||||
|
||||||
::: | ||||||
|
||||||
### `--seed` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
might need to tweak the anchor in |
||||||
|
||||||
Run the tests in the order specified by the seed value. Must be used with the [`--randomize`](#--randomize) flag. | ||||||
|
||||||
```bash | ||||||
jest --randomize --seed 1234 | ||||||
``` | ||||||
|
||||||
:::note | ||||||
|
||||||
This option is only supported using the default `jest-circus` test runner. | ||||||
|
||||||
::: | ||||||
|
||||||
### `--selectProjects <project1> ... <projectN>` | ||||||
|
||||||
Run the tests of the specified projects. Jest uses the attribute `displayName` in the configuration to identify each project. If you use this option, you should provide a `displayName` to all your projects. | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`works with each 1`] = ` | ||
"PASS __tests__/each.test.js | ||
✓ test1 | ||
✓ test2 | ||
✓ test3 | ||
describe1 | ||
✓ test4 | ||
✓ test6 | ||
✓ test5 | ||
describe3 | ||
✓ test11 | ||
✓ test12 | ||
✓ test10 | ||
describe4 | ||
✓ test14 | ||
✓ test13 | ||
✓ test15 | ||
describe2 | ||
✓ test4 | ||
✓ test5 | ||
✓ test6" | ||
`; | ||
|
||
exports[`works with hooks 1`] = ` | ||
"Seed is 123 | ||
This is before all | ||
This is before each | ||
test4 | ||
This is after each | ||
This is before each | ||
test6 | ||
This is after each | ||
This is before each | ||
test5 | ||
This is after each | ||
This is before each | ||
test1 | ||
This is after each | ||
This is before each | ||
This is before each describe3 | ||
test11 | ||
This is after each | ||
This is before each | ||
This is before each describe3 | ||
test12 | ||
This is after each | ||
This is before each | ||
This is before each describe3 | ||
test14 | ||
This is after each | ||
This is before each | ||
This is before each describe3 | ||
test13 | ||
This is after each | ||
This is before each | ||
This is before each describe3 | ||
test15 | ||
This is after each | ||
This is before each | ||
This is before each describe3 | ||
test10 | ||
This is after each | ||
This is before each | ||
test7 | ||
This is after each | ||
This is before each | ||
test8 | ||
This is after each | ||
This is before each | ||
test9 | ||
This is after each | ||
This is after all describe2 | ||
This is before each | ||
test2 | ||
This is after each | ||
This is before each | ||
test3 | ||
This is after each | ||
This is after all" | ||
`; | ||
|
||
exports[`works with passing tests 1`] = ` | ||
"PASS __tests__/success.test.js | ||
✓ test1 | ||
✓ test2 | ||
✓ test3 | ||
describe1 | ||
✓ test4 | ||
✓ test6 | ||
✓ test5 | ||
describe3 | ||
✓ test11 | ||
✓ test12 | ||
✓ test10 | ||
describe4 | ||
✓ test14 | ||
✓ test13 | ||
✓ test15 | ||
describe2 | ||
✓ test7 | ||
✓ test8 | ||
✓ test9" | ||
`; | ||
|
||
exports[`works with snapshots 1`] = ` | ||
"PASS __tests__/snapshots.test.js | ||
✓ test1 | ||
✓ test2 | ||
✓ test3 | ||
describe1 | ||
✓ test4 | ||
✓ test6 | ||
✓ test5 | ||
describe3 | ||
✓ test11 | ||
✓ test12 | ||
✓ test10 | ||
describe4 | ||
✓ test14 | ||
✓ test13 | ||
✓ test15 | ||
describe2 | ||
✓ test4 | ||
✓ test5 | ||
✓ test6" | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import * as path from 'path'; | ||
SimenB marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import {skipSuiteOnJasmine} from '@jest/test-utils'; | ||
import {extractSummary} from '../Utils'; | ||
import runJest from '../runJest'; | ||
|
||
skipSuiteOnJasmine(); | ||
|
||
const dir = path.resolve(__dirname, '../randomize'); | ||
|
||
test('works with passing tests', () => { | ||
const result = runJest(dir, [ | ||
'success.test.js', | ||
'--randomize', | ||
'--seed', | ||
'123', | ||
]); | ||
const {rest} = extractSummary(result.stderr); | ||
expect(rest).toMatchSnapshot(); | ||
}); | ||
|
||
test('works with each', () => { | ||
const result = runJest(dir, ['each.test.js', '--randomize', '--seed', '123']); | ||
const {rest} = extractSummary(result.stderr); | ||
expect(rest).toMatchSnapshot(); | ||
}); | ||
|
||
test('works with hooks', () => { | ||
const result = runJest(dir, [ | ||
'hooks.test.js', | ||
'--randomize', | ||
'--seed', | ||
'123', | ||
]); | ||
// Change in formatting could change this one | ||
expect(result.stdout).toMatchSnapshot(); | ||
}); | ||
|
||
test('works with snapshots', () => { | ||
const result = runJest(dir, [ | ||
'snapshots.test.js', | ||
'--randomize', | ||
'--seed', | ||
'123', | ||
]); | ||
const {rest} = extractSummary(result.stderr); | ||
expect(rest).toMatchSnapshot(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`describe1 test4 1`] = `4`; | ||
|
||
exports[`describe1 test5 1`] = `5`; | ||
|
||
exports[`describe1 test6 1`] = `6`; | ||
|
||
exports[`describe2 test4 1`] = `4`; | ||
|
||
exports[`describe2 test5 1`] = `5`; | ||
|
||
exports[`describe2 test6 1`] = `6`; | ||
|
||
exports[`describe3 describe4 test13 1`] = `13`; | ||
|
||
exports[`describe3 describe4 test14 1`] = `14`; | ||
|
||
exports[`describe3 describe4 test15 1`] = `15`; | ||
|
||
exports[`describe3 test10 1`] = `10`; | ||
|
||
exports[`describe3 test11 1`] = `11`; | ||
|
||
exports[`describe3 test12 1`] = `12`; | ||
|
||
exports[`test1 1`] = `1`; | ||
|
||
exports[`test2 1`] = `2`; | ||
|
||
exports[`test3 1`] = `3`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
it.each([1, 2, 3])('test%d', () => { | ||
expect(true).toBe(true); | ||
}); | ||
|
||
describe.each([1, 2])('describe%d', () => { | ||
it.each([4, 5, 6])('test%d', () => { | ||
expect(true).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('describe3', () => { | ||
it.each([10, 11, 12])('test%d', () => { | ||
expect(true).toBe(true); | ||
}); | ||
|
||
describe('describe4', () => { | ||
it.each([13, 14, 15])('test%d', () => { | ||
expect(true).toBe(true); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
beforeAll(() => { | ||
process.stdout.write('This is before all\n'); | ||
}); | ||
|
||
beforeEach(() => { | ||
process.stdout.write('This is before each\n'); | ||
}); | ||
|
||
afterEach(() => { | ||
process.stdout.write('This is after each\n'); | ||
}); | ||
|
||
afterAll(() => { | ||
process.stdout.write('This is after all\n'); | ||
}); | ||
|
||
it('test1', () => { | ||
process.stdout.write('test1\n'); | ||
}); | ||
|
||
it('test2', () => { | ||
process.stdout.write('test2\n'); | ||
}); | ||
|
||
it('test3', () => { | ||
process.stdout.write('test3\n'); | ||
}); | ||
|
||
describe('describe1', () => { | ||
it('test4', () => { | ||
process.stdout.write('test4\n'); | ||
}); | ||
|
||
it('test5', () => { | ||
process.stdout.write('test5\n'); | ||
}); | ||
|
||
it('test6', () => { | ||
process.stdout.write('test6\n'); | ||
}); | ||
}); | ||
|
||
describe('describe2', () => { | ||
afterAll(() => { | ||
process.stdout.write('This is after all describe2\n'); | ||
}); | ||
|
||
it('test7', () => { | ||
process.stdout.write('test7\n'); | ||
}); | ||
|
||
it('test8', () => { | ||
process.stdout.write('test8\n'); | ||
}); | ||
|
||
it('test9', () => { | ||
process.stdout.write('test9\n'); | ||
}); | ||
}); | ||
|
||
describe('describe3', () => { | ||
beforeEach(() => { | ||
process.stdout.write('This is before each describe3\n'); | ||
}); | ||
|
||
it('test10', () => { | ||
process.stdout.write('test10\n'); | ||
}); | ||
|
||
it('test11', () => { | ||
process.stdout.write('test11\n'); | ||
}); | ||
|
||
it('test12', () => { | ||
process.stdout.write('test12\n'); | ||
}); | ||
|
||
describe('describe4', () => { | ||
it('test13', () => { | ||
process.stdout.write('test13\n'); | ||
}); | ||
|
||
it('test14', () => { | ||
process.stdout.write('test14\n'); | ||
}); | ||
|
||
it('test15', () => { | ||
process.stdout.write('test15\n'); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can probably split this up into multiple entries. One for "new arguments
seed
andrandomize
" underchore
and one for circus with the randomizing underfeatures