Test Coverage

Measures the percentage of code executed during tests. Vitest and Jest generate coverage reports with --coverage flag.

Syntax

testing
vitest run --coverage
jest --coverage

Example

testing
// vitest.config.ts
export default defineConfig({
  test: {
    coverage: {
      provider: "v8",
      reporter: ["text", "html", "lcov"],
      thresholds: {
        lines: 80,
        functions: 80,
        branches: 70,
        statements: 80,
      },
    },
  },
});