Reputation: 749
I am fairly new to Jest. Using version 16.0.1.
I have a test suite with 3 tests. I'm focused on one of these tests which is failing. My understanding is that Jest should attempt failing tests before running non-failing tests (as per Jest homepage: "Jest runs previously failed tests first. Together with --bail it provides useful signal quickly."
I can't seem to get this working. I'm running Jest with the following options:
node_modules\jest-cli\bin\jest.js --runInBand --bail
The --runInBand ensures that everything is in a single process (useful for debugging).
However, my tests are all being run! What I see in the debugger is that each test is run to completion before the following code is executed:
_bailIfNeeded(aggregatedResults, watcher) {
if (this._config.bail && aggregatedResults.numFailedTests !== 0) {
if (watcher.isWatchMode()) {
watcher.setState({ interrupted: true });
} else {
this._dispatcher.onRunComplete(this._config, aggregatedResults);
process.exit(1);
}
}
}}
I've ordered my tests so that the failing test is run first, but it is not causing the process to exit (or rather this is happening too late, after the other tests are run).
Also, I cannot see where/how Jest records the status of failed tests, so am not sure if or how this feature works. If I move my failing test to the end of the test suite, the other tests are run first even though they are passing, so I must be missing something.
For completeness, my test file looks like this:
describe('My test suite', () => {
it('Test 1', () => {
fail("Failing!");
});
it('Test 2', () => {
// Passing
});
it('Test 3', () => {
// Passing
});
});
Any help much appreciated.
Upvotes: 1
Views: 1714
Reputation: 439
I know this is >1 year ago, but --bail
applies to running multiple test files. So, if you split this test up into three files, you would see the results you are expecting.
Upvotes: 2