jest icon indicating copy to clipboard operation
jest copied to clipboard

[Docs]: describe usage of the `seed` option within jest, mention test ordering

Open jzaefferer opened this issue 1 year ago • 8 comments

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.

jzaefferer avatar May 08 '24 13:05 jzaefferer

Good point! Wanna send a PR with this addition?

SimenB avatar May 12 '24 19:05 SimenB

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?

jzaefferer avatar May 13 '24 12:05 jzaefferer

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.

github-actions[bot] avatar Jun 12 '24 13:06 github-actions[bot]

Still looking for clarification on how the seed and randomize options interact. With that (see previous comment) answered, I could create a docs PR.

jzaefferer avatar Jun 12 '24 15:06 jzaefferer

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.

github-actions[bot] avatar Jul 12 '24 16:07 github-actions[bot]

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.

jhwang98 avatar Jul 18 '24 06:07 jhwang98

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() },
    );
  });

jhwang98 avatar Jul 18 '24 06:07 jhwang98

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.

github-actions[bot] avatar Aug 17 '24 07:08 github-actions[bot]

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.

github-actions[bot] avatar Sep 16 '24 07:09 github-actions[bot]

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.

github-actions[bot] avatar Sep 16 '24 07:09 github-actions[bot]

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.

github-actions[bot] avatar Oct 18 '24 00:10 github-actions[bot]