Skip to content

Commit 48952f4

Browse files
committed
Fix formatting again
1 parent 3f74088 commit 48952f4

File tree

2 files changed

+56
-35
lines changed

2 files changed

+56
-35
lines changed

lib/vitest-reporter/build/test-reporter.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
// src/test-reporter.ts
22
import fs from 'fs';
33

4-
function* formatTestCase(testCase, prefixes) {
4+
function* formatTestCase(testCase) {
55
const passed = testCase.ok();
66
const diagnostics = testCase.diagnostic();
77
const durationStr = diagnostics ? `${diagnostics.duration.toFixed(0)}ms` : '';
8-
if (prefixes.length > 0) {
9-
yield `- ${passed ? '\u2705' : '\u274C'} ${prefixes.join(' > ')} > ${testCase.name} ${durationStr}
8+
yield `${passed ? '\u2705' : '\u274C'} ${testCase.name} ${durationStr}
109
`;
11-
} else {
12-
yield `- ${passed ? '\u2705' : '\u274C'} ${testCase.name} ${durationStr}
13-
`;
14-
}
1510
}
16-
function* formatTestSuite(suite, prefixes) {
11+
function* formatTestSuite(suite) {
1712
const suiteName = suite.name;
13+
const passed = suite.ok();
14+
yield `${passed ? '\u2705' : '\u274C'} ${suiteName}<ul>`;
1815
for (const child of suite.children) {
1916
if (child.type === 'suite') {
20-
yield* formatTestSuite(child, [...prefixes, suiteName]);
17+
yield* formatTestSuite(child);
2118
} else {
22-
yield* formatTestCase(child, [...prefixes, suiteName]);
19+
yield '<li>';
20+
yield* formatTestCase(child);
21+
yield '</li>';
2322
}
2423
}
24+
yield '</ul>\n';
2525
}
2626
function getTestCount(item) {
2727
if (item.type === 'test') return 1;
@@ -42,27 +42,35 @@ var GithubActionsSummaryReporter = class {
4242
}
4343
onTestRunEnd(modules) {
4444
if (!this.writeStream) return;
45-
this.writeStream.write('### Test Results');
45+
this.writeStream.write('## Test Results\n');
4646
for (const testModule of modules) {
47+
const formatRow2 = function(...items) {
48+
const tds = items.map((item) => `<td>${item}</td>`);
49+
return `<tr>${tds.join('')}</tr>
50+
`;
51+
};
52+
var formatRow = formatRow2;
4753
const passed = testModule.ok();
4854
const testCount = getTestCount(testModule);
4955
this.writeStream.write(`${passed ? '\u2705' : '\u274C'} (fileName) (${testCount} test${testCount === 1 ? '' : 's'})
5056
`);
57+
this.writeStream.write('<ul>');
5158
for (const child of testModule.children) {
52-
const formatter = child.type === 'suite' ? formatTestSuite(child, []) : formatTestCase(child, []);
59+
const formatter = child.type === 'suite' ? formatTestSuite(child) : formatTestCase(child);
5360
const line = Array.from(formatter).join('');
54-
this.writeStream.write(line);
61+
this.writeStream.write(`<li>${line}</li>`);
5562
}
63+
this.writeStream.write('</ul>');
5664
const diagnostics = testModule.diagnostic();
5765
const totalDuration = diagnostics.duration.toFixed(0);
5866
this.writeStream.write('\n\n');
5967
this.writeStream.write('#### Summary\n');
60-
this.writeStream.write('Test Files\n');
61-
this.writeStream.write(` Tests ${testCount}
62-
`);
63-
this.writeStream.write(' Start at\n');
64-
this.writeStream.write(` Duration: ${totalDuration}ms
65-
`);
68+
this.writeStream.write('<table>');
69+
this.writeStream.write(formatRow2('Test Files', ''));
70+
this.writeStream.write(formatRow2('Tests', testCount.toString()));
71+
this.writeStream.write(formatRow2('Start at', ''));
72+
this.writeStream.write(formatRow2('Duration', `${totalDuration}ms`));
73+
this.writeStream.write('</table>');
6674
}
6775
this.writeStream.close();
6876
}

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

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
import fs from 'fs';
22
import type { Reporter, TestCase, TestModule, TestSuite, Vitest } from 'vitest/node';
33

4-
function* formatTestCase(testCase: TestCase, prefixes: string[]) {
4+
function* formatTestCase(testCase: TestCase) {
55
const passed = testCase.ok();
66
const diagnostics = testCase.diagnostic();
77
const durationStr = diagnostics ? `${diagnostics.duration.toFixed(0)}ms` : '';
88

9-
if (prefixes.length > 0) {
10-
yield `- ${passed ? '✅' : '❌'} ${prefixes.join(' > ')} > ${testCase.name} ${durationStr}\n`;
11-
} else {
12-
yield `- ${passed ? '✅' : '❌'} ${testCase.name} ${durationStr}\n`;
13-
}
9+
yield `${passed ? '✅' : '❌'} ${testCase.name} ${durationStr}\n`;
1410
}
1511

16-
function* formatTestSuite(suite: TestSuite, prefixes: string[]): Generator<string> {
12+
function* formatTestSuite(suite: TestSuite): Generator<string> {
1713
const suiteName = suite.name;
14+
const passed = suite.ok();
15+
16+
yield `${passed ? '✅' : '❌'} ${suiteName}<ul>`;
1817

1918
for (const child of suite.children) {
2019
if (child.type === 'suite') {
21-
yield* formatTestSuite(child, [...prefixes, suiteName]);
20+
yield* formatTestSuite(child);
2221
} else {
23-
yield* formatTestCase(child, [...prefixes, suiteName]);
22+
yield '<li>';
23+
yield* formatTestCase(child);
24+
yield '</li>';
2425
}
2526
}
27+
28+
yield '</ul>\n';
2629
}
2730

2831
function getTestCount(item: TestModule | TestSuite | TestCase): number {
@@ -51,28 +54,38 @@ export default class GithubActionsSummaryReporter implements Reporter {
5154
onTestRunEnd(modules: readonly TestModule[]) {
5255
if (!this.writeStream) return;
5356

54-
this.writeStream.write('### Test Results');
57+
this.writeStream.write('## Test Results\n');
5558
for (const testModule of modules) {
5659
const passed = testModule.ok();
5760
const testCount = getTestCount(testModule);
5861

5962
this.writeStream.write(`${passed ? '✅' : '❌'} (fileName) (${testCount} test${testCount === 1 ? '' : 's'}) \n`);
6063

64+
this.writeStream.write('<ul>');
6165
for (const child of testModule.children) {
62-
const formatter = child.type === 'suite' ? formatTestSuite(child, []) : formatTestCase(child, []);
66+
const formatter = child.type === 'suite' ? formatTestSuite(child) : formatTestCase(child);
6367
const line = Array.from(formatter).join('');
64-
this.writeStream.write(line);
68+
this.writeStream.write(`<li>${line}</li>`);
6569
}
70+
this.writeStream.write('</ul>');
6671

6772
const diagnostics = testModule.diagnostic();
6873
const totalDuration = diagnostics.duration.toFixed(0);
6974

7075
this.writeStream.write('\n\n');
7176
this.writeStream.write('#### Summary\n');
72-
this.writeStream.write('Test Files\n');
73-
this.writeStream.write(` Tests ${testCount}\n`);
74-
this.writeStream.write(' Start at\n');
75-
this.writeStream.write(` Duration: ${totalDuration}ms\n`);
77+
this.writeStream.write('<table>');
78+
79+
function formatRow(...items: string[]) {
80+
const tds = items.map(item => `<td>${item}</td>`);
81+
return `<tr>${tds.join('')}</tr>\n`;
82+
}
83+
84+
this.writeStream.write(formatRow('Test Files', ''));
85+
this.writeStream.write(formatRow('Tests', testCount.toString()));
86+
this.writeStream.write(formatRow('Start at', ''));
87+
this.writeStream.write(formatRow('Duration', `${totalDuration}ms`));
88+
this.writeStream.write('</table>');
7689
}
7790

7891
this.writeStream.close();

0 commit comments

Comments
 (0)