Skip to content

Commit 6ddcd6a

Browse files
committed
Update inaccurate test counts
1 parent d192b0d commit 6ddcd6a

File tree

1 file changed

+43
-11
lines changed

1 file changed

+43
-11
lines changed

lib/vitest-reporter/src/test-reporter.ts

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,43 @@ function formatRow(...items: string[]) {
4646
return `<tr>${tds.join('')}</tr>\n`;
4747
}
4848

49-
function getTestCount(item: TestModule | TestSuite | TestCase): [passed: number, failed: number] {
49+
interface TestCount {
50+
failed: number;
51+
passed: number;
52+
skipped: number;
53+
}
54+
55+
function getTestCount(item: TestModule | TestSuite | TestCase): TestCount {
5056
if (item.type === 'test') {
51-
return item.ok() ? [1, 0] : [0, 1];
57+
switch (item.result().state) {
58+
case 'failed':
59+
return { failed: 1, passed: 0, skipped: 0 };
60+
case 'passed':
61+
return { failed: 0, passed: 1, skipped: 0 };
62+
case 'skipped':
63+
return { failed: 0, passed: 0, skipped: 1 };
64+
default:
65+
throw new Error('Should not get here');
66+
}
5267
}
5368

5469
let passed = 0;
5570
let failed = 0;
71+
let skipped = 0;
5672

5773
for (const child of item.children) {
58-
const [passCount, failCount] = getTestCount(child);
74+
const {
75+
failed: failCount,
76+
passed: passCount,
77+
skipped: skipCount
78+
} = getTestCount(child);
79+
5980
passed += passCount;
6081
failed += failCount;
82+
skipped += skipCount;
6183
}
6284

63-
return [passed, failed];
85+
return { failed, passed, skipped };
6486
}
6587

6688
/**
@@ -89,8 +111,12 @@ export default class GithubActionsSummaryReporter implements Reporter {
89111
// @ts-expect-error idk where else to get the file information from
90112
const file: RunnerTestFile = testModule.task;
91113
const relpath = pathlib.relative(testModule.project.config.root, file.filepath);
92-
const [passCount, failCount] = getTestCount(testModule);
93-
const testCount = passCount + failCount;
114+
const {
115+
failed: failCount,
116+
passed: passCount,
117+
skipped: skipCount
118+
} = getTestCount(testModule);
119+
const testCount = passCount + failCount + skipCount;
94120

95121
this.writeStream.write(`<h3>${getIcon(passed)} <code>${relpath}</code> (${testCount} test${testCount === 1 ? '' : 's'})</h3>\n`);
96122

@@ -114,13 +140,19 @@ export default class GithubActionsSummaryReporter implements Reporter {
114140
this.writeStream.write(`<h4>Summary for <code>${relpath}</code></h4>\n`);
115141
this.writeStream.write('<table>\n');
116142

117-
if (failCount > 0) {
118-
const testCountStr = `${failCount} Failed | ${passCount} passed (${testCount})`;
119-
this.writeStream.write(formatRow('Tests', testCountStr));
120-
} else {
121-
this.writeStream.write(formatRow('Tests', `${passCount} passed`));
143+
function* formatSummary() {
144+
if (failCount > 0) {
145+
yield `${failCount} Failed`;
146+
}
147+
148+
if (skipCount > 0) {
149+
yield `${skipCount} Skipped`;
150+
}
151+
152+
yield `${passCount} Passed`;
122153
}
123154

155+
this.writeStream.write(formatRow('Tests', Array.from(formatSummary()).join(' | ')));
124156
this.writeStream.write(formatRow('Start at', `${hours}:${minutes}:${seconds}`));
125157
this.writeStream.write(formatRow('Duration', `${totalDuration}ms`));
126158
this.writeStream.write('</table>');

0 commit comments

Comments
 (0)