-
-
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 14 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 |
---|---|---|
|
@@ -1139,6 +1139,11 @@ export default async function normalize( | |
newOptions.shard = parseShardPair(argv.shard); | ||
} | ||
|
||
if (argv.randomize) { | ||
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. we should always set |
||
// at time of writing we use mulberry32 pseudorandom number generator so 32 bits | ||
newOptions.seed = argv.seed ?? Math.floor(Math.random() * Math.pow(2, 32)); | ||
} | ||
|
||
return { | ||
hasDeprecationWarnings, | ||
options: newOptions, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,9 +276,14 @@ const runWithoutWatch = async ( | |
filter?: Filter, | ||
) => { | ||
const startRun = async (): Promise<void | null> => { | ||
if (globalConfig.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. thoughts on having |
||
outputStream.write(`Seed is ${globalConfig.seed}\n`); | ||
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. hmm, I wonder if it makes sense to have the reporters print this? in Or maybe as part of 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. It changes how the tests are run so I'd say it makes sense as part of The I'll see how easy it is to add the seed to 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.
very true! actually removed by |
||
} | ||
|
||
if (!globalConfig.listTests) { | ||
preRunMessagePrint(outputStream); | ||
} | ||
|
||
jhwang98 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return runJest({ | ||
changedFilesPromise, | ||
contexts, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,4 @@ export {default as pluralize} from './pluralize'; | |
export {default as formatTime} from './formatTime'; | ||
export {default as tryRealpath} from './tryRealpath'; | ||
export {default as requireOrImportModule} from './requireOrImportModule'; | ||
export {default as shuffleArray, rngBuilder} from './shuffleArray'; | ||
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. Could we move this into |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,24 @@ | ||||||
import Prando from 'prando'; | ||||||
|
||||||
export const rngBuilder: (seed: number) => { next: () => number } = (seed: number) => new Prando(seed); | ||||||
|
||||||
// Fisher-Yates shuffle | ||||||
// This is performed in-place | ||||||
export default function shuffleArray<T>( | ||||||
array: Array<T>, | ||||||
random: () => number = Math.random, | ||||||
): Array<T> { | ||||||
const length = array == null ? 0 : array.length; | ||||||
if (!length) { | ||||||
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
|
||||||
return []; | ||||||
} | ||||||
let index = -1; | ||||||
const lastIndex = length - 1; | ||||||
while (++index < length) { | ||||||
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. should this be a |
||||||
const rand = index + Math.floor(random() * (lastIndex - index + 1)); | ||||||
const value = array[index]; | ||||||
array[index] = array[rand]; | ||||||
array[rand] = value; | ||||||
} | ||||||
return array; | ||||||
} |
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.
extract the
undefined | (() => number)
into atype