Coverage Criteria
20.4.1. Minimum Coverage
Projects must meet the following minimum coverage thresholds for TQS certification.
| Item | Minimum Threshold | Description |
|---|---|---|
| Lines | 80% | Percentage of executed code lines |
| Branches | 70% | Percentage of covered conditional branches (if/else, switch) |
| Functions | 80% | Percentage of invoked functions |
| Statements | 80% | Percentage of executed statements |
- New projects must write tests to meet the thresholds from the outset.
- Existing projects should improve coverage incrementally; however, new code must meet the thresholds without exception.
- Tests that merely invoke functions without meaningful assertions are not recognized, even if coverage numbers appear high.
20.4.2. Coverage Reports
Configure the coverage provider and report formats in vitest.config.ts.
typescript
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
coverage: {
provider: 'v8',
reporter: ['text', 'html', 'lcov'],
reportsDirectory: './coverage',
include: ['src/**/*.{ts,vue}'],
exclude: [
'src/**/*.d.ts',
'src/**/*.test.ts',
'src/**/*.spec.ts',
'src/**/index.ts',
'src/types/**',
'src/constants/**',
'src/auto-generated/**',
],
},
},
})| Provider | Characteristics |
|---|---|
v8 | Built-in V8 engine coverage, fast execution, Vitest default |
istanbul | Precise instrumentation, broad ecosystem compatibility |
| Report Format | Purpose |
|---|---|
text | Immediate review in the terminal |
html | Detailed per-file coverage review in the browser |
lcov | Integration with CI tools and external services (SonarQube, Codecov, etc.) |
- The TQS default coverage provider is
v8. - Generating all three report formats (
text,html,lcov) is recommended.
20.4.3. Exclusions
The following files are excluded from coverage measurement.
| Exclusion Target | Reason |
|---|---|
Type definition files (*.d.ts) | Not runtime code |
Constant files (constants/) | Value definitions with no logic |
Auto-generated code (auto-generated/) | Not manually maintained |
Configuration files (vite.config.ts, vitest.config.ts, etc.) | Build/test configuration only |
Re-export files (index.ts) | Perform only re-exports |
Test files (*.test.ts, *.spec.ts) | Test code itself is not a coverage target |
- Exclusion targets must be specified in the
coverage.excludearray ofvitest.config.ts. - When new exclusion targets are added, the configuration file must be updated through team consensus.
20.4.4. CI Integration
The CI pipeline must fail the build when coverage falls below the defined thresholds.
typescript
// vitest.config.ts
export default defineConfig({
test: {
coverage: {
provider: 'v8',
thresholds: {
lines: 80,
branches: 70,
functions: 80,
statements: 80,
},
},
},
})When thresholds are configured, Vitest returns a non-zero exit code if coverage falls below the specified values. The CI pipeline detects this and fails the build.
yaml
# CI pipeline example (GitHub Actions)
- name: Run tests with coverage
run: yarn test:coverage
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage/- The
thresholdsvalues must match the minimum coverage criteria defined in Section 20.4.1. - Coverage reports should be retained as CI artifacts to track history.
- Integrating with external services (Codecov, SonarQube, etc.) to visualize coverage trends is recommended.