javascript - vitest testtäckning misslyckas inte när tröskeln inte uppnås


jag vill att mitt testtäckning ska misslyckas om tröskelvärdena inte uppfylls

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,
    }
  },

även om jag får felmeddelandet visar det fortfarande 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

någon hjälp?

Svar #1

Om du ser detta år 2024 och använder [email kommer den tidigare lösningen inte att fungera för dig. thresholds bör istället vara ett objekt.
Se koden nedan:

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

Se dokumentation här: coverage.thresholds[glob-mönster]