|
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'; |
2 | 4 |
|
3 | 5 | import { SilentReporter } from './silent-reporter.ts'; |
4 | 6 |
|
@@ -38,4 +40,55 @@ describe('SilentReporter', () => { |
38 | 40 | // and not 2 levels which would only reach DotReporter |
39 | 41 | }); |
40 | 42 | }); |
| 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 | + }); |
41 | 94 | }); |
0 commit comments