-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Bug: --bail flag does not bail #2867
Comments
Reported the bug here: jestjs/jest#2867
|
That's not my use case, I need it to exit the test suite immediately upon the first failing test. This is what Mocha's Seems like Jest should either change the behaviour to match the docs or change the docs to match the behaviour. My experiences lead me to advocate the former as it is the specification that the implementation must satisfy. |
Please feel free to change Jest/our fork of Jasmine to implement this feature but this is never how bail worked for Jest. I'd be open to merge a PR if you'd like to change behavior here. |
I don't think the link made it into the message, can you post again? |
I didn't add a link. This change would have to be made somewhere in jest-jasmine2 or jasmine itself. |
@JoshCheek did you end up implementing a jasmine extension to fail fast? |
Actually I was able to get this to work via my import * as failFast from 'jasmine-fail-fast'
/**
* Fail after the first test in a single test suite fails. This is NOT the same as jest's
* --bail option, which works across test suites
*/
if (process.env.FAIL_FAST) {
// Jasmine definition from @types/jest does not have `getEnv` for some reason
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/jest/index.d.ts
// However this empirically works with jest 22.3.0. So we'll cast to any for now
const jasmineEnv = (jasmine as any).getEnv()
jasmineEnv.addReporter(failFast.init())
} |
Thanks to tonyxiao, here's how I managed to "fix" // setup.ts
import * as failFast from 'jasmine-fail-fast'
if (JSON.parse(process.env.npm_config_argv).original.includes('--bail')) {
const jasmineEnv = (jasmine as any).getEnv()
jasmineEnv.addReporter(failFast.init())
} |
Adding my two cents 🤑:
const failFast = require("jasmine-fail-fast");
if (process.argv.includes("--bail")) {
const jasmineEnv = jasmine.getEnv();
jasmineEnv.addReporter(failFast.init());
} Works like a charm! 🎉 |
The solution above works, but when running jest with a glob, I think executing with Instead, I've wrapped the |
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. |
Do you want to request a feature or report a bug?
Report a bug.
What is the current behavior?
The
--bail
flag does not stop running tests after the first failure.Steps to reproduce
What is the expected behavior?
Exit the test suite immediately upon the first failing test, the one named "2: fail".
What is the actual behaviour?
It runs the full test suite.
Demo
Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
No configuration outside the repo I linked above..
$ npm run exec jest -- --version v18.1.0 $ node --version v7.2.1 $ npm --version 3.10.9 $ system_profiler SPSoftwareDataType Software: System Software Overview: System Version: OS X 10.11.6 (15G1004) Kernel Version: Darwin 15.6.0 Boot Volume: Macintosh HD Boot Mode: Normal Computer Name: Josh’s MacBook Air (2) User Name: Josh Cheek (josh) Secure Virtual Memory: Enabled System Integrity Protection: Enabled Time since boot: 19 days 12:03
The text was updated successfully, but these errors were encountered: