Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vitest test coverage does not fail when threshold is not met

i want my test coverage to fail if the thresholds are not met

export default defineConfig({
  plugins: [vue()],
  test: {
    environment: "happy-dom",
    exclude: [...configDefaults.exclude, "**/tests/e2e/*"],
    coverage: {
      reporter: ['text', 'json', 'html'],
      lines: 80,
      functions: 80,
      branches: 80,
      statements: 80,
    }
  },

even though i get the error message, it still shows pass

File                    | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
------------------------|---------|----------|---------|---------|-------------------
All files               |     100 |    33.33 |     100 |     100 |                   
 components/base/button |     100 |    33.33 |     100 |     100 |                   
  Button.vue            |     100 |    33.33 |     100 |     100 | 36-53             
 config                 |     100 |      100 |     100 |     100 |                   
  index.ts              |     100 |      100 |     100 |     100 |                   
------------------------|---------|----------|---------|---------|-------------------
ERROR: Coverage for branches (33.33%) does not meet global threshold (80%)

 PASS  Waiting for file changes...
       press h to show help, press q to quit

any help?

like image 978
Tambua Rex Avatar asked Oct 28 '25 03:10

Tambua Rex


1 Answers

If you are seeing this in 2024 and using [email protected] the previous solution won't work for you.thresholds should be an object instead.
See code below:

{
  test: {
    ...your other configurations
    coverage: {
      ...your other configurations
      thresholds: {
        lines: 80,
        functions: 80,
        branches: 80,
        statements: 80
      }
    }
  }
}

See documentation here: coverage.thresholds[glob-pattern]

like image 198
angcl.nyc Avatar answered Oct 30 '25 17:10

angcl.nyc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!