Skip to content

Commit a580b8f

Browse files
committed
Try another reporter implementation
1 parent e40606d commit a580b8f

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// src/test-reporter.ts
22
import fs from "fs";
3-
import { BasicReporter } from "vitest/reporters";
43
function* formatTestCase(testCase, prefixes) {
54
const passed = testCase.ok();
65
const diagnostics = testCase.diagnostic();
@@ -29,7 +28,7 @@ function getTestCount(item) {
2928
}
3029
return output;
3130
}
32-
var GithubActionsSummaryReporter = class extends BasicReporter {
31+
var GithubActionsSummaryReporter = class {
3332
writeStream = null;
3433
vitest = null;
3534
onInit(vitest) {
@@ -38,15 +37,13 @@ var GithubActionsSummaryReporter = class extends BasicReporter {
3837
this.writeStream = fs.createWriteStream(process.env.GITHUB_STEP_SUMMARY, { encoding: "utf-8", flags: "a" });
3938
}
4039
}
41-
onTestRunEnd(files) {
40+
onTestRunEnd(modules) {
4241
if (!this.writeStream) return;
4342
this.writeStream.write("<h3>Test Results</h3>");
44-
for (const file of files) {
45-
const testModule = this.vitest.state.getReportedEntity(file);
46-
if (testModule === void 0) continue;
43+
for (const testModule of modules) {
4744
const passed = testModule.ok();
4845
const testCount = getTestCount(testModule);
49-
this.writeStream.write(`${passed ? "\u2705" : "\u274C"} \`${file.filepath}\` (${testCount} test${testCount === 1 ? "" : "s"})
46+
this.writeStream.write(`${passed ? "\u2705" : "\u274C"} (fileName) (${testCount} test${testCount === 1 ? "" : "s"})
5047
`);
5148
for (const child of testModule.children) {
5249
const formatter = child.type === "suite" ? formatTestSuite(child, []) : formatTestCase(child, []);

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import fs from 'fs';
2-
import type { RunnerTestFile, TestCase, TestModule, TestSuite, Vitest } from 'vitest/node';
3-
import { BasicReporter } from 'vitest/reporters';
2+
import type { Reporter, TestCase, TestModule, TestSuite, Vitest } from 'vitest/node';
43

54
function* formatTestCase(testCase: TestCase, prefixes: string[]) {
65
const passed = testCase.ok();
@@ -37,7 +36,7 @@ function getTestCount(item: TestModule | TestSuite | TestCase): number {
3736
return output;
3837
}
3938

40-
export default class GithubActionsSummaryReporter extends BasicReporter {
39+
export default class GithubActionsSummaryReporter implements Reporter {
4140
private writeStream: fs.WriteStream | null = null;
4241
private vitest: Vitest | null = null;
4342

@@ -49,18 +48,15 @@ export default class GithubActionsSummaryReporter extends BasicReporter {
4948
}
5049
}
5150

52-
onTestRunEnd(files: RunnerTestFile[]) {
51+
onTestRunEnd(modules: readonly TestModule[]) {
5352
if (!this.writeStream) return;
5453

5554
this.writeStream.write('<h3>Test Results</h3>');
56-
for (const file of files) {
57-
const testModule = this.vitest!.state.getReportedEntity(file) as TestModule;
58-
if (testModule === undefined) continue;
59-
55+
for (const testModule of modules) {
6056
const passed = testModule.ok();
6157
const testCount = getTestCount(testModule);
6258

63-
this.writeStream.write(`${passed ? '✅' : '❌'} \`${file.filepath}\` (${testCount} test${testCount === 1 ? '' : 's'}) \n`);
59+
this.writeStream.write(`${passed ? '✅' : '❌'} (fileName) (${testCount} test${testCount === 1 ? '' : 's'}) \n`);
6460

6561
for (const child of testModule.children) {
6662
const formatter = child.type === 'suite' ? formatTestSuite(child, []) : formatTestCase(child, []);

0 commit comments

Comments
 (0)