Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { describe, expect, it } from 'vitest';
import type { File as VitestFile } from '@vitest/runner';
import { describe, expect, it, vi } from 'vitest';
import { DotReporter } from 'vitest/reporters';

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

Expand Down Expand Up @@ -38,4 +40,55 @@ describe('SilentReporter', () => {
// and not 2 levels which would only reach DotReporter
});
});

describe('reportSummary', () => {
it('writes "All tests pass." when all tests pass', () => {
const reporter = new SilentReporter();
const writeSpy = vi
.spyOn(process.stdout, 'write')
.mockImplementation(() => true);

const passingFile = {
result: { state: 'pass' },
tasks: [],
} as unknown as VitestFile;
reporter.reportSummary([passingFile], []);

expect(writeSpy).toHaveBeenCalledWith('All tests pass.\n');
writeSpy.mockRestore();
});

it('calls super.reportSummary when a file fails', () => {
const reporter = new SilentReporter();
const superSpy = vi
.spyOn(DotReporter.prototype, 'reportSummary')
.mockImplementation(() => undefined);

const failingFile = {
result: { state: 'fail' },
tasks: [],
} as unknown as VitestFile;
reporter.reportSummary([failingFile], []);

expect(superSpy).toHaveBeenCalledWith([failingFile], []);
superSpy.mockRestore();
});

it('calls super.reportSummary when there are errors', () => {
const reporter = new SilentReporter();
const superSpy = vi
.spyOn(DotReporter.prototype, 'reportSummary')
.mockImplementation(() => undefined);

const passingFile = {
result: { state: 'pass' },
tasks: [],
} as unknown as VitestFile;
const error = new Error('unhandled');
reporter.reportSummary([passingFile], [error]);

expect(superSpy).toHaveBeenCalledWith([passingFile], [error]);
superSpy.mockRestore();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ export class SilentReporter extends DotReporter {

if (hasFailed || errors.length > 0) {
super.reportSummary(files, errors);
} else {
process.stdout.write('All tests pass.\n');
}
// Silent when all pass
}
}

Expand Down
Loading