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
option to run Jest in band and sort tests alphabetically #4032
Comments
No, Jest should absolutely not make any guarantees about the order in which it runs tests, and especially not publicly exposed. Tests are run the way Jest wants to run them, and integration tests should be able to account for them. We shouldn't add features to make testing Jest itself easier. |
fair enough. Testing features in production code is not the best practice :) |
What are the features for this purpose? Could you please cite them? |
@DanZeuss not sure what you mean, but we solved the problem eventually by parsing the output and sorting it later |
@aaronabramov I thought there were a way to define the ordering, or filenames that should run firstly. |
@cpojer are there any published best practices for writing integration test suites with Jest that rely on a specific order of operations? |
Not sure what you mean, but you can have jest output json and parse that. You can look at the integration tests in this repo for inspiration |
How do we sequence these events with Jest without making one huge test with tons of |
Tests inside of a single file is executed in definition order |
Thanks for the quick response. :)
is 1,2,3,4 guaranteed? is there a way to guarantee 1,2,3,4,5,6 ? |
We do not guarantee between |
I do some integration testing with puppeteer within jest. Having the ability to guarantee the order of your tests is paramount in some cases. I have noticed this pattern works:
export default () => {
describe('First', () => {
test('First', () => {})
})
}
export default () => {
describe('Second', () => {
test('Second', () => {})
})
}
export default () => {
describe('Third', () => {
test('Third', () => {})
})
}
import first from './first.specpartial'
import second from './second.specpartial'
import third from './third.specpartial'
first()
second()
third()
$ export BABEL_ENV=test NODE_ENV=test && jest --verbose --runInBand
PASS utils/test.spec.js
First
✓ First (2ms)
Second
✓ Second
Third
✓ Third (1ms) |
@markpradhan how did u get em to run? i can't seem to following your approach
always get |
@rostgoat can you post one of the imported test files as well? |
yessir
|
Because you are exporting as default. Try running a simple test in |
good point, u were totally right! my also, good catch on export default, totally missed that thanks 👍 |
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. |
the fact that Jest executes tests in different order was always a pain when testing.
can we implement an option (at least internally) to disable sorting by test running time and sort them alphabetically?
Projects using Jest might also benefit from it (debugging CI is a pain sometimes when you don't know which test is run when)
The text was updated successfully, but these errors were encountered: