-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: make sequencer public, add option to run tests in random order #1582
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
feat: make sequencer public, add option to run tests in random order #1582
Conversation
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
0173eca
to
827e106
Compare
docs/api/index.md
Outdated
Vitest provides a way to run all tests in random order via CLI flag [`--random`](/guide/cli) or config option [`sequence.random`](/config/#sequence-random), but if you want to have only part of your test suite to run tests in random order, you can mark it with this flag. | ||
|
||
```ts | ||
describe.random('suite', () => { |
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.
If so, should we also support repeat
for describe
? For example:
describe.repeat(10).random('repect 10 times randomly', () => {
// ...
})
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.
How is this has anything to do with random? 👀
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.
No necessary in this PR, just an idea. Using random feels more unstable to identify the ordering bug (like sometimes the change passes the CI because the order does not hit the bug, but will later). Running random tests multiple times could reduce such scenarios and make the tests more stable.
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.
No necessary in this PR, just an idea. Using random feels more unstable to identify the ordering bug (like sometimes the change passes the CI because the order does not hit the bug, but will later). Running random tests multiple times could reduce such scenarios and make the tests more stable.
Sure, but this also should be done on the global level, yes? This PR adds vitest --random
, so there should also be vitest --random --repeat 10
.
It's also not clear what should be done on error. Do we fail the suite when it hits the first error? Do we show summary of all 10 runs? I think if we want to add this, it's better be done in other PR, and if/when people will ask for it.
I really want to switch to @vitest/browser
, but all this enhancements PRs stop me 😄
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.
Sure we could do that later 👍
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.
The feature looks good to me. But do you think shuffle
would be better than random
?
Well, it's |
I mean the term
Refs: |
Sure, let's name it shuffle instead. |
@antfu renamed :) |
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
Closes #1570
TODO
This PR adds a few new options to config:
--shuffle
to CLI flagssequence
to optionssequencer
allows users to overwrite builtin logic for sharding and sortingshuffle
allows tests to be run in random orderseed
makes random order more deterministicAlso added
shuffle
flag todescribe
block to make only part of suite random. I've noticed we have some tests rely on running in the same order, so I though this option might be helpful.