Skip to content

Commit 5b9ec23

Browse files
rekmarksclaude
andcommitted
feat(repo-tools): output "All tests pass." on silent reporter success
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 405dd55 commit 5b9ec23

2 files changed

Lines changed: 56 additions & 2 deletions

File tree

packages/repo-tools/src/vitest-reporters/silent-reporter.test.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { describe, expect, it } from 'vitest';
1+
import type { File as VitestFile } from '@vitest/runner';
2+
import { describe, expect, it, vi } from 'vitest';
3+
import { DotReporter } from 'vitest/reporters';
24

35
import { SilentReporter } from './silent-reporter.ts';
46

@@ -38,4 +40,55 @@ describe('SilentReporter', () => {
3840
// and not 2 levels which would only reach DotReporter
3941
});
4042
});
43+
44+
describe('reportSummary', () => {
45+
it('writes "All tests pass." when all tests pass', () => {
46+
const reporter = new SilentReporter();
47+
const writeSpy = vi
48+
.spyOn(process.stdout, 'write')
49+
.mockImplementation(() => true);
50+
51+
const passingFile = {
52+
result: { state: 'pass' },
53+
tasks: [],
54+
} as unknown as VitestFile;
55+
reporter.reportSummary([passingFile], []);
56+
57+
expect(writeSpy).toHaveBeenCalledWith('All tests pass.\n');
58+
writeSpy.mockRestore();
59+
});
60+
61+
it('calls super.reportSummary when a file fails', () => {
62+
const reporter = new SilentReporter();
63+
const superSpy = vi
64+
.spyOn(DotReporter.prototype, 'reportSummary')
65+
.mockImplementation(() => undefined);
66+
67+
const failingFile = {
68+
result: { state: 'fail' },
69+
tasks: [],
70+
} as unknown as VitestFile;
71+
reporter.reportSummary([failingFile], []);
72+
73+
expect(superSpy).toHaveBeenCalledWith([failingFile], []);
74+
superSpy.mockRestore();
75+
});
76+
77+
it('calls super.reportSummary when there are errors', () => {
78+
const reporter = new SilentReporter();
79+
const superSpy = vi
80+
.spyOn(DotReporter.prototype, 'reportSummary')
81+
.mockImplementation(() => undefined);
82+
83+
const passingFile = {
84+
result: { state: 'pass' },
85+
tasks: [],
86+
} as unknown as VitestFile;
87+
const error = new Error('unhandled');
88+
reporter.reportSummary([passingFile], [error]);
89+
90+
expect(superSpy).toHaveBeenCalledWith([passingFile], [error]);
91+
superSpy.mockRestore();
92+
});
93+
});
4194
});

packages/repo-tools/src/vitest-reporters/silent-reporter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ export class SilentReporter extends DotReporter {
8585

8686
if (hasFailed || errors.length > 0) {
8787
super.reportSummary(files, errors);
88+
} else {
89+
process.stdout.write('All tests pass.\n');
8890
}
89-
// Silent when all pass
9091
}
9192
}
9293

0 commit comments

Comments
 (0)