jest
jest copied to clipboard
[Docs]: describe usage of the `seed` option within jest, mention test ordering
Page(s)
https://jestjs.io/docs/cli#--seednum
Description
https://jestjs.io/docs/cli#--seednum describes the CLI seed option, but only mentions it's usage within getSeed (with a link to https://jestjs.io/docs/jest-object#jestgetseed ).
As far as I can tell, the seed option is also used to initialze the shuffle that applies to children of a describe block here: https://github.com/jestjs/jest/blob/654dbd6f6b3d94c604221e1afd70fcfb66f9478e/packages/jest-circus/src/run.ts#L88-L90
If that is correct, it would help a lot to mention that test flakyness might be related to this shuffling, and reusing the same seed of a failed run can help reproduce that failure.
Good point! Wanna send a PR with this addition?
Yeah, I would do that, though I still need some clarification. I've only now noticed the randomize option: https://jestjs.io/docs/cli#--randomize Which does mention seed, too.
Since randomize is an option, does it mean this shuffling is disabled by default?
If so, should a random seed (not setting it explicitly) make any difference if randomize isn't used?
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Still looking for clarification on how the seed and randomize options interact. With that (see previous comment) answered, I could create a docs PR.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Shuffling of test suites happens by default.
Shuffling of tests within each describe block only happens when randomize is on.
Seed is also used for any other parts of your system that can accept a seed.
For example if you rely on fuzz testing like fast-check then getSeed can be used to specify the seed of the randomizer there and ensure replicable tests.
As an example from my usage of fast-check.
it('throws error for random string', () => {
fc.assert(
fc.property(
fc.string().filter(s => s !== 'True' && s !== 'False'),
s => {
expect(() => parseBoolean(s)).toThrow();
},
),
{ seed: jest.getSeed() },
);
});
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.