Skip to content

Commit ec4525f

Browse files
committed
Add --summary flag support to coverage script
Add --summary flag to hide detailed test output and coverage tables, showing only the final coverage summary. Filter --summary from vitest args to prevent unknown option error. When --summary is set, skip displaying test results and coverage tables while still showing the coverage summary section.
1 parent c414d63 commit ec4525f

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

scripts/cover.mjs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const { values } = parseArgs({
1818
options: {
1919
'code-only': { type: 'boolean', default: false },
2020
'type-only': { type: 'boolean', default: false },
21+
summary: { type: 'boolean', default: false },
2122
},
2223
strict: false,
2324
})
@@ -26,7 +27,7 @@ printHeader('Test Coverage')
2627

2728
// Run vitest with coverage enabled, capturing output
2829
// Filter out custom flags that vitest doesn't understand
29-
const customFlags = ['--code-only', '--type-only']
30+
const customFlags = ['--code-only', '--type-only', '--summary']
3031
const vitestArgs = [
3132
'exec',
3233
'vitest',
@@ -83,7 +84,7 @@ try {
8384
const testSummaryMatch = output.match(
8485
/Test Files\s+\d+[^\n]*\n[\s\S]*?Duration\s+[\d.]+m?s[^\n]*/,
8586
)
86-
if (testSummaryMatch) {
87+
if (!values.summary && testSummaryMatch) {
8788
console.log()
8889
console.log(testSummaryMatch[0])
8990
console.log()
@@ -96,13 +97,15 @@ try {
9697
const allFilesMatch = output.match(/All files\s+\|\s+([\d.]+)\s+\|[^\n]*/)
9798

9899
if (coverageHeaderMatch && allFilesMatch) {
99-
console.log(' % Coverage report from v8')
100-
console.log(coverageHeaderMatch[1])
101-
console.log(coverageHeaderMatch[2])
102-
console.log(coverageHeaderMatch[1])
103-
console.log(allFilesMatch[0])
104-
console.log(coverageHeaderMatch[1])
105-
console.log()
100+
if (!values.summary) {
101+
console.log(' % Coverage report from v8')
102+
console.log(coverageHeaderMatch[1])
103+
console.log(coverageHeaderMatch[2])
104+
console.log(coverageHeaderMatch[1])
105+
console.log(allFilesMatch[0])
106+
console.log(coverageHeaderMatch[1])
107+
console.log()
108+
}
106109

107110
const codeCoveragePercent = Number.parseFloat(allFilesMatch[1])
108111
console.log(' Coverage Summary')
@@ -153,20 +156,22 @@ try {
153156
)
154157

155158
// Display output
156-
if (testSummaryMatch) {
159+
if (!values.summary && testSummaryMatch) {
157160
console.log()
158161
console.log(testSummaryMatch[0])
159162
console.log()
160163
}
161164

162165
if (coverageHeaderMatch && allFilesMatch) {
163-
console.log(' % Coverage report from v8')
164-
console.log(coverageHeaderMatch[1])
165-
console.log(coverageHeaderMatch[2])
166-
console.log(coverageHeaderMatch[1])
167-
console.log(allFilesMatch[0])
168-
console.log(coverageHeaderMatch[1])
169-
console.log()
166+
if (!values.summary) {
167+
console.log(' % Coverage report from v8')
168+
console.log(coverageHeaderMatch[1])
169+
console.log(coverageHeaderMatch[2])
170+
console.log(coverageHeaderMatch[1])
171+
console.log(allFilesMatch[0])
172+
console.log(coverageHeaderMatch[1])
173+
console.log()
174+
}
170175

171176
// Display cumulative summary
172177
if (typeCoverageMatch) {

0 commit comments

Comments
 (0)