Skip to content

Commit 3f74088

Browse files
committed
Fix continue to fix formatting
1 parent a580b8f commit 3f74088

File tree

3 files changed

+59
-35
lines changed

3 files changed

+59
-35
lines changed

lib/vitest-reporter/build/coverage-reporter.cjs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
"use strict";
1+
'use strict';
22

33
// src/coverage-reporter.cts
4-
var fs = require("fs");
5-
var { ReportBase } = require("istanbul-lib-report");
4+
var fs = require('fs');
5+
var { ReportBase } = require('istanbul-lib-report');
6+
67
function isFull(metrics) {
78
return metrics.statements.pct === 100 && metrics.branches.pct === 100 && metrics.functions.pct === 100 && metrics.lines.pct === 100;
89
}
@@ -38,7 +39,7 @@ function getUncoveredLines(node) {
3839
}, []);
3940
return ranges;
4041
}
41-
var headers = ["Statements", "Branches", "Functions", "Lines"];
42+
var headers = ['Statements', 'Branches', 'Functions', 'Lines'];
4243
module.exports = class GithubActionsCoverageReporter extends ReportBase {
4344
skipEmpty;
4445
skipFull;
@@ -52,20 +53,20 @@ module.exports = class GithubActionsCoverageReporter extends ReportBase {
5253
}
5354
onStart(_node, context) {
5455
if (!process.env.GITHUB_STEP_SUMMARY) {
55-
console.log("Reporter not being executed in Github Actions environment");
56+
console.log('Reporter not being executed in Github Actions environment');
5657
return;
5758
}
58-
this.cw = fs.createWriteStream(process.env.GITHUB_STEP_SUMMARY, { encoding: "utf-8", flags: "a" });
59+
this.cw = fs.createWriteStream(process.env.GITHUB_STEP_SUMMARY, { encoding: 'utf-8', flags: 'a' });
5960
this.watermarks = context.watermarks;
60-
this.cw.write("<h3>Test Coverage</h3>");
61-
this.cw.write("<table><thead><tr>");
62-
for (const heading of ["File", ...headers, "Uncovered Lines"]) {
61+
this.cw.write('<h3>Test Coverage</h3>');
62+
this.cw.write('<table><thead><tr>');
63+
for (const heading of ['File', ...headers, 'Uncovered Lines']) {
6364
this.cw.write(`<th>${heading}</th>`);
6465
}
65-
this.cw.write("</tr></thead><tbody>");
66+
this.cw.write('</tr></thead><tbody>');
6667
}
6768
onSummary(node) {
68-
const nodeName = node.getRelativeName() || "All Files";
69+
const nodeName = node.getRelativeName() || 'All Files';
6970
const rawMetrics = node.getCoverageSummary(false);
7071
const isEmpty = rawMetrics.isEmpty();
7172
if (this.skipEmpty && isEmpty) {
@@ -102,26 +103,26 @@ module.exports = class GithubActionsCoverageReporter extends ReportBase {
102103
for (const fileName of fileNames) {
103104
const metrics = this.results[fileName];
104105
this.cw.write(`<tr><td><code>${fileName}</code></td>`);
105-
this.cw.write(this.formatter(metrics.statements, "statements"));
106-
this.cw.write(this.formatter(metrics.branches, "branches"));
107-
this.cw.write(this.formatter(metrics.functions, "functions"));
108-
this.cw.write(this.formatter(metrics.lines, "lines"));
106+
this.cw.write(this.formatter(metrics.statements, 'statements'));
107+
this.cw.write(this.formatter(metrics.branches, 'branches'));
108+
this.cw.write(this.formatter(metrics.functions, 'functions'));
109+
this.cw.write(this.formatter(metrics.lines, 'lines'));
109110
if (metrics.uncoveredLines.length > 0) {
110-
this.cw.write("<td><details><summary>Expand</summary><ul>");
111+
this.cw.write('<td><details><summary>Expand</summary><ul>');
111112
for (const range of metrics.uncoveredLines) {
112113
if (range.length === 1) {
113114
this.cw.write(`<li>${range[0]}</li>`);
114115
} else {
115116
this.cw.write(`<li>${range[0]}-${range[1]}</li>`);
116117
}
117118
}
118-
this.cw.write("</ul></details></td>");
119+
this.cw.write('</ul></details></td>');
119120
} else {
120-
this.cw.write("<td></td>");
121+
this.cw.write('<td></td>');
121122
}
122-
this.cw.write("</tr>");
123+
this.cw.write('</tr>');
123124
}
124-
this.cw.write("</tbody></table>");
125+
this.cw.write('</tbody></table>');
125126
this.cw.close();
126127
}
127128
};

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

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11
// src/test-reporter.ts
2-
import fs from "fs";
2+
import fs from 'fs';
3+
34
function* formatTestCase(testCase, prefixes) {
45
const passed = testCase.ok();
56
const diagnostics = testCase.diagnostic();
6-
const durationStr = diagnostics ? `${diagnostics.duration}ms` : "";
7+
const durationStr = diagnostics ? `${diagnostics.duration.toFixed(0)}ms` : '';
78
if (prefixes.length > 0) {
8-
yield `- ${passed ? "\u2705" : "\u274C"} ${prefixes.join(" > ")} > ${testCase.name} ${durationStr}`;
9+
yield `- ${passed ? '\u2705' : '\u274C'} ${prefixes.join(' > ')} > ${testCase.name} ${durationStr}
10+
`;
911
} else {
10-
yield `- ${passed ? "\u2705" : "\u274C"} ${testCase.name} ${durationStr}`;
12+
yield `- ${passed ? '\u2705' : '\u274C'} ${testCase.name} ${durationStr}
13+
`;
1114
}
1215
}
1316
function* formatTestSuite(suite, prefixes) {
1417
const suiteName = suite.name;
1518
for (const child of suite.children) {
16-
if (child.type === "suite") {
19+
if (child.type === 'suite') {
1720
yield* formatTestSuite(child, [...prefixes, suiteName]);
1821
} else {
1922
yield* formatTestCase(child, [...prefixes, suiteName]);
2023
}
2124
}
2225
}
2326
function getTestCount(item) {
24-
if (item.type === "test") return 1;
27+
if (item.type === 'test') return 1;
2528
let output = 0;
2629
for (const child of item.children) {
2730
output += getTestCount(child);
@@ -34,22 +37,32 @@ var GithubActionsSummaryReporter = class {
3437
onInit(vitest) {
3538
this.vitest = vitest;
3639
if (process.env.GITHUB_STEP_SUMMARY) {
37-
this.writeStream = fs.createWriteStream(process.env.GITHUB_STEP_SUMMARY, { encoding: "utf-8", flags: "a" });
40+
this.writeStream = fs.createWriteStream(process.env.GITHUB_STEP_SUMMARY, { encoding: 'utf-8', flags: 'a' });
3841
}
3942
}
4043
onTestRunEnd(modules) {
4144
if (!this.writeStream) return;
42-
this.writeStream.write("<h3>Test Results</h3>");
45+
this.writeStream.write('### Test Results');
4346
for (const testModule of modules) {
4447
const passed = testModule.ok();
4548
const testCount = getTestCount(testModule);
46-
this.writeStream.write(`${passed ? "\u2705" : "\u274C"} (fileName) (${testCount} test${testCount === 1 ? "" : "s"})
49+
this.writeStream.write(`${passed ? '\u2705' : '\u274C'} (fileName) (${testCount} test${testCount === 1 ? '' : 's'})
4750
`);
4851
for (const child of testModule.children) {
49-
const formatter = child.type === "suite" ? formatTestSuite(child, []) : formatTestCase(child, []);
50-
const line = Array.from(formatter).join("");
52+
const formatter = child.type === 'suite' ? formatTestSuite(child, []) : formatTestCase(child, []);
53+
const line = Array.from(formatter).join('');
5154
this.writeStream.write(line);
5255
}
56+
const diagnostics = testModule.diagnostic();
57+
const totalDuration = diagnostics.duration.toFixed(0);
58+
this.writeStream.write('\n\n');
59+
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+
`);
5366
}
5467
this.writeStream.close();
5568
}

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import type { Reporter, TestCase, TestModule, TestSuite, Vitest } from 'vitest/n
44
function* formatTestCase(testCase: TestCase, prefixes: string[]) {
55
const passed = testCase.ok();
66
const diagnostics = testCase.diagnostic();
7-
const durationStr = diagnostics ? `${diagnostics.duration}ms` : '';
7+
const durationStr = diagnostics ? `${diagnostics.duration.toFixed(0)}ms` : '';
88

99
if (prefixes.length > 0) {
10-
yield `- ${passed ? '✅' : '❌'} ${prefixes.join(' > ')} > ${testCase.name} ${durationStr}`;
10+
yield `- ${passed ? '✅' : '❌'} ${prefixes.join(' > ')} > ${testCase.name} ${durationStr}\n`;
1111
} else {
12-
yield `- ${passed ? '✅' : '❌'} ${testCase.name} ${durationStr}`;
12+
yield `- ${passed ? '✅' : '❌'} ${testCase.name} ${durationStr}\n`;
1313
}
1414
}
1515

@@ -51,7 +51,7 @@ export default class GithubActionsSummaryReporter implements Reporter {
5151
onTestRunEnd(modules: readonly TestModule[]) {
5252
if (!this.writeStream) return;
5353

54-
this.writeStream.write('<h3>Test Results</h3>');
54+
this.writeStream.write('### Test Results');
5555
for (const testModule of modules) {
5656
const passed = testModule.ok();
5757
const testCount = getTestCount(testModule);
@@ -63,6 +63,16 @@ export default class GithubActionsSummaryReporter implements Reporter {
6363
const line = Array.from(formatter).join('');
6464
this.writeStream.write(line);
6565
}
66+
67+
const diagnostics = testModule.diagnostic();
68+
const totalDuration = diagnostics.duration.toFixed(0);
69+
70+
this.writeStream.write('\n\n');
71+
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`);
6676
}
6777

6878
this.writeStream.close();

0 commit comments

Comments
 (0)