Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/vitest/src/utils/coverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class BaseCoverageProvider {
const thresholdsToUpdate: [Threshold, number][] = []

for (const key of THRESHOLD_KEYS) {
const threshold = thresholds[key] || 100
const threshold = thresholds[key] ?? 100
const actual = Math.min(...summaries.map(summary => summary[key].pct))

if (actual > threshold)
Expand All @@ -45,7 +45,7 @@ export class BaseCoverageProvider {

for (const [threshold, newValue] of thresholdsToUpdate) {
// Find the exact match from the configuration file and replace the value
const previousThreshold = (thresholds[threshold] || 100).toString()
const previousThreshold = (thresholds[threshold] ?? 100).toString()
const pattern = new RegExp(`(${threshold}\\s*:\\s*)${previousThreshold.replace('.', '\\.')}`)
const matches = originalConfig.match(pattern)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ test('thresholdAutoUpdate updates thresholds', async () => {
const match = configContents.match(new RegExp(`${threshold}: (?<coverage>[\\d|\\.]+)`))
const coverage = match?.groups?.coverage || '0'

// Configuration has fixed value of 1.01 set for each threshold
// Configuration has fixed value of 1.01 and 0 set for each threshold
expect(Number.parseInt(coverage)).toBeGreaterThan(1.01)
}

// Update thresholds back to fixed values
const updatedConfig = configContents.replace(/(branches|functions|lines|statements): ([\d|\.])+/g, '$1: 1.01')
const updatedConfig = configContents
.replace(/(branches|statements): ([\d|\.])+/g, '$1: 1.01')
.replace(/(functions|lines): ([\d|\.])+/g, '$1: 0')
fs.writeFileSync(configFilename, updatedConfig)
})

Expand Down
4 changes: 2 additions & 2 deletions test/coverage-test/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export default defineConfig({

// These will be updated by tests and reseted back by generic.report.test.ts
thresholdAutoUpdate: true,
functions: 1.01,
functions: 0,
branches: 1.01,
lines: 1.01,
lines: 0,
statements: 1.01,
},
setupFiles: [
Expand Down