|
| 1 | +import { expect } from 'vitest' |
| 2 | +import { captureStdout, coverageTest, isV8Provider, normalizeURL, runVitest, test } from '../utils' |
| 3 | +import { sum } from '../fixtures/src/math' |
| 4 | + |
| 5 | +test('report is not generated when tests fail', async () => { |
| 6 | + const stdout = captureStdout() |
| 7 | + |
| 8 | + const { exitCode } = await runVitest({ |
| 9 | + include: [normalizeURL(import.meta.url)], |
| 10 | + coverage: { |
| 11 | + all: false, |
| 12 | + include: ['**/fixtures/src/math.ts'], |
| 13 | + reporter: 'text', |
| 14 | + }, |
| 15 | + }, { throwOnError: false }) |
| 16 | + |
| 17 | + expect(stdout()).toBe('') |
| 18 | + expect(exitCode).toBe(1) |
| 19 | +}) |
| 20 | + |
| 21 | +test('report is generated when tests fail and { reportOnFailure: true }', async () => { |
| 22 | + const stdout = captureStdout() |
| 23 | + |
| 24 | + const { exitCode } = await runVitest({ |
| 25 | + include: [normalizeURL(import.meta.url)], |
| 26 | + coverage: { |
| 27 | + all: false, |
| 28 | + include: ['**/fixtures/src/math.ts'], |
| 29 | + reporter: 'text', |
| 30 | + reportOnFailure: true, |
| 31 | + }, |
| 32 | + }, { throwOnError: false }) |
| 33 | + |
| 34 | + if (isV8Provider()) { |
| 35 | + expect(stdout()).toMatchInlineSnapshot(` |
| 36 | + "----------|---------|----------|---------|---------|------------------- |
| 37 | + File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
| 38 | + ----------|---------|----------|---------|---------|------------------- |
| 39 | + All files | 50 | 100 | 25 | 50 | |
| 40 | + math.ts | 50 | 100 | 25 | 50 | 6-7,10-11,14-15 |
| 41 | + ----------|---------|----------|---------|---------|------------------- |
| 42 | + " |
| 43 | + `) |
| 44 | + } |
| 45 | + else { |
| 46 | + expect(stdout()).toMatchInlineSnapshot(` |
| 47 | + "----------|---------|----------|---------|---------|------------------- |
| 48 | + File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
| 49 | + ----------|---------|----------|---------|---------|------------------- |
| 50 | + All files | 25 | 100 | 25 | 25 | |
| 51 | + math.ts | 25 | 100 | 25 | 25 | 6-14 |
| 52 | + ----------|---------|----------|---------|---------|------------------- |
| 53 | + " |
| 54 | + `) |
| 55 | + } |
| 56 | + |
| 57 | + expect(exitCode).toBe(1) |
| 58 | +}) |
| 59 | + |
| 60 | +coverageTest('failing test', () => { |
| 61 | + expect(sum(1, 2)).toBe(4) |
| 62 | +}) |
0 commit comments