javascriptautomated-testsvitestfail-fast

How to make vitest fail fast after first known test failure


I am using Vitest for testing and would like it to fail fast upon first error. The reason is that I'm using it within git bisect and don't need to waste time on the whole test run once there is an error.

I haven’t found an equivalent in Vitest. How can I configure Vitest or work around this to achieve similar functionality?


Solution

  • The option is called --bail, passing --bail=1 makes vitest fail after first failure:

    vitest --bail=1
    

    From the docs:

    bail
    Type: number
    Default: 0
    CLI: --bail=<value>

    Stop test execution when given number of tests have failed.

    By default Vitest will run all of your test cases even if some of them fail. This may not be desired for CI builds where you are only interested in 100% successful builds and would like to stop test execution as early as possible when test failures occur. The bail option can be used to speed up CI runs by preventing it from running more tests when failures have occurred.

    from https://vitest.dev/config/#bail