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?
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With