question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bail option to skip all subsequent tests

See original GitHub issue

Clear and concise description of the problem

Depending on the kind of tests we run, it can be interesting to have a fail-fast feature and exit as soon as a test is failing.

I’m not the only one needing such feature apparently: https://github.com/vitest-dev/vitest/discussions/964

Jest has bail for this purpose.

Suggested solution

As Vitest tries to smooth the transition from Jest, I think the bail option is a sensible name.

But Jest implementation is incomplete/weird, it’s only skipping the next test suites (describe blocks), but it continues to run the other tests within the same test suite.

I think the default should be to bail by test case and not by test suite.

# Skip all the subsequent tests after n test failures (default 1)
--bail <n>

I’m not sure what could be the API if we want to deal with both test cases and test suites, maybe adding a --bail-scope <test|suite> (default test)? 🤔

Alternative

No response

Additional context

Here are related issues about it:

Validations

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:11
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
jtuchelcommented, Dec 13, 2022

May I ask if there is any news?

As already mentioned Jest provides a --bail flag And Playwright provides a --max-failures -x flag

It would save a lot of time in CI pipelines 😃

4reactions
jgouxcommented, Jun 10, 2022
  1. test failed without describe
test('test 1', () => {/* code that fails */})
test('test 2', () => {/* other test */})

skip test 2 in both test and suite scopes.

  1. test failed inside describe
describe('describe 1', () => {
  test('test 1', () => {/* code that fails */})
  test('test 2', () => {/* other test */})
})

describe('describe 2', () => {
  test('test 1', () => {/* other test */})
  test('test 2', () => {/* other test */})
})

skip all the tests in test scope skip only "describe 1"."test 2" in suite scope

  1. test failed inside nested describe
describe('describe 1', () => {
  describe('describe 2', () => {
    test('test 1', () => {/* code that fails */})
    test('test 2', () => {/* other test */})
  })

  test('test 1', () => {/* other test */})
  test('test 2', () => {/* other test */})
})

skip all the tests in test scope skip only "describe 2"."test 2" in suite scope

  1. test fails in one spec
// spec1.spec.ts
test('test 1', () => {/* code that fails */})
// spec2.spec.ts
test('test 2', () => {/* other test */})

skip all the tests in test scope skip only other tests in spec1.spec.ts in suite scope

I think the rule should be:

  • using --bail-scope test, you see the whole tests as a flatten structure, if one test fail, no matter where it fails (in another file, in a describe, whatever) we skip everything else and display the report.
  • using --bail-scope suite, you skip the subsequent tests in the same “unit” as the failed test. Keep in mind that this “unit” can be logical, if you have 2 describe blocks named the same in two different test files, they are the same “unit”. Also, it’s more predictable to stop at the closest “unit”, if you have nested describe, I don’t think you want to skip the tests in the parent describe.
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I intercept perl Test::More's BAIL_OUT() and ...
If you BAIL_OUT("reason") you get more useful output, but all tests get aborted, not just the current test script. Is there a sensible...
Read more >
Revoking Bail: Go to Jail and Lose Your Bond
When a defendant's bail is revoked for failing to appear or violating a bail condition, any money put up for bond can be...
Read more >
Jest — Fail Early (And Stop Testing If One Test Fails)
By default, Jest runs all your tests and shows their result in the console. Yet, Jest comes with a bail option allowing you...
Read more >
Unconditional Bonds After Release in MN
Many defendants don't realize they have the option to convert their conditional bail into an unconditional bail. If your current life circumstances make...
Read more >
Organizing Test Suite
The default is 0 , meaning that it always runs all tests specs it can find. Please see Options Page for additional information...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found