Running tests in a specific order
See original GitHub issue🚀 Feature Proposal
Allow define which files should run before others.
Motivation
Some times, we need to define a specific test to be ran before others. As we want to maintain different test cases
in different files, would be essential define the order for some tests. This case implies on environment tests when we are using Jest with other frameworks, like Selenium, for example.
Example
I need to test an email client (browser-oriented). As Jest is a robust framework, we’ll use it with Selenium for environment
, unit
and integration
coverage. The following tests are focused only in environment coverage with Selenium. The tests are:
- Add an account and make sure that it was added successfully;
- Check messages in the account;
- Perform other actions (Open an message, download file, perform filtering, etc);
- Remove the account.
The idea is to define in the Jest settings an array containing the file names and the order of files that should be ran firstly. For example:
{
runFirstly: [
'A.test.js',
'B.test.js',
'C.test.js',
'D.test.js'
}
So, the that would run firstly would be A.test.js
, B.test.js
, etc.
Once these tests are done, then
jest could run other tests sequentially or not.
Pitch
Why does this feature belong in the Jest core platform?
Because we already have a feature that run sequentially --runInBand
but we don’t have a way to define which files should run firstly.
I believe that the way that I described before, is goes beyond the --runInBand
feature, allowing define files that must ran first and then, keep the tests according the default behavior of Jest.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:115
- Comments:48 (8 by maintainers)
Top GitHub Comments
I got a hold on this by creating files of the functions then importing them in the main tests.spec.js describing all the tests in order and assigning them with the imported functions:
@zGrav @sandorvasas @lukeapage work around would be to have an index file, call it
index.spec.js
, that dictates the order in which you’d execute:just make sure that there are no other related tests that match against the jest default
testMatch
unless o/w custom defined