Skip to content

Commit 90cf4d3

Browse files
committed
Fix test formatter
1 parent 48952f4 commit 90cf4d3

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

.github/actions/src/__tests__/git.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ vi.mock(import('lodash/memoize.js'), () => ({
88

99
const mockedExecOutput = vi.spyOn(exec, 'getExecOutput');
1010

11-
describe('Test checkForChanges', () => {
11+
describe(git.checkForChanges, () => {
1212
function mockChanges(value: boolean) {
1313
mockedExecOutput.mockResolvedValueOnce({
1414
exitCode: value ? 1 : 0, stdout: '', stderr: ''

.github/actions/src/info/__tests__/sorter.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, expect, test } from 'vitest';
22
import { topoSortPackages } from '../sorter.js';
33

4-
describe('Test topoSorter', () => {
4+
describe(topoSortPackages, () => {
55
test('Without a cycle', () => {
66
const result = topoSortPackages({
77
'@sourceacademy/0': {

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ function* formatTestSuite(suite) {
2323
}
2424
yield '</ul>\n';
2525
}
26+
function formatRow(...items) {
27+
const tds = items.map((item) => `<td>${item}</td>`);
28+
return `<tr>${tds.join('')}</tr>
29+
`;
30+
}
2631
function getTestCount(item) {
2732
if (item.type === 'test') return 1;
2833
let output = 0;
@@ -44,15 +49,10 @@ var GithubActionsSummaryReporter = class {
4449
if (!this.writeStream) return;
4550
this.writeStream.write('## Test Results\n');
4651
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;
5352
const passed = testModule.ok();
53+
const fileName = testModule.location ?? 'undefined`';
5454
const testCount = getTestCount(testModule);
55-
this.writeStream.write(`${passed ? '\u2705' : '\u274C'} (fileName) (${testCount} test${testCount === 1 ? '' : 's'})
55+
this.writeStream.write(`${passed ? '\u2705' : '\u274C'} \`${fileName}\` (${testCount} test${testCount === 1 ? '' : 's'})
5656
`);
5757
this.writeStream.write('<ul>');
5858
for (const child of testModule.children) {
@@ -64,12 +64,13 @@ var GithubActionsSummaryReporter = class {
6464
const diagnostics = testModule.diagnostic();
6565
const totalDuration = diagnostics.duration.toFixed(0);
6666
this.writeStream.write('\n\n');
67-
this.writeStream.write('#### Summary\n');
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`));
67+
this.writeStream.write(`#### Summary for \`${fileName}\`
68+
`);
69+
this.writeStream.write('<table>\n');
70+
this.writeStream.write(formatRow('Test Files', ''));
71+
this.writeStream.write(formatRow('Tests', testCount.toString()));
72+
this.writeStream.write(formatRow('Start at', ''));
73+
this.writeStream.write(formatRow('Duration', `${totalDuration}ms`));
7374
this.writeStream.write('</table>');
7475
}
7576
this.writeStream.close();

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ function* formatTestSuite(suite: TestSuite): Generator<string> {
2828
yield '</ul>\n';
2929
}
3030

31+
function formatRow(...items: string[]) {
32+
const tds = items.map(item => `<td>${item}</td>`);
33+
return `<tr>${tds.join('')}</tr>\n`;
34+
}
35+
3136
function getTestCount(item: TestModule | TestSuite | TestCase): number {
3237
if (item.type === 'test') return 1;
3338

@@ -57,9 +62,10 @@ export default class GithubActionsSummaryReporter implements Reporter {
5762
this.writeStream.write('## Test Results\n');
5863
for (const testModule of modules) {
5964
const passed = testModule.ok();
65+
const fileName: string = testModule.location ?? 'undefined`';
6066
const testCount = getTestCount(testModule);
6167

62-
this.writeStream.write(`${passed ? '✅' : '❌'} (fileName) (${testCount} test${testCount === 1 ? '' : 's'}) \n`);
68+
this.writeStream.write(`${passed ? '✅' : '❌'} \`${fileName}\` (${testCount} test${testCount === 1 ? '' : 's'}) \n`);
6369

6470
this.writeStream.write('<ul>');
6571
for (const child of testModule.children) {
@@ -73,14 +79,8 @@ export default class GithubActionsSummaryReporter implements Reporter {
7379
const totalDuration = diagnostics.duration.toFixed(0);
7480

7581
this.writeStream.write('\n\n');
76-
this.writeStream.write('#### Summary\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-
82+
this.writeStream.write(`#### Summary for \`${fileName}\`\n`);
83+
this.writeStream.write('<table>\n');
8484
this.writeStream.write(formatRow('Test Files', ''));
8585
this.writeStream.write(formatRow('Tests', testCount.toString()));
8686
this.writeStream.write(formatRow('Start at', ''));

0 commit comments

Comments
 (0)