|
| 1 | +import { expect, test } from 'vitest' |
| 2 | +import { DefaultReporter } from 'vitest/reporters' |
| 3 | +import { runVitest } from '../../test-utils' |
| 4 | + |
| 5 | +test('{ silent: true } hides all console logs', async () => { |
| 6 | + const { stdout } = await runVitest({ |
| 7 | + include: ['./fixtures/console-some-failing.test.ts'], |
| 8 | + silent: true, |
| 9 | + reporters: [new LogReporter()], |
| 10 | + }) |
| 11 | + |
| 12 | + expect(stdout).not.toContain('stdout') |
| 13 | + expect(stdout).not.toContain('Log from') |
| 14 | + expect(stdout).toContain('Test Files 1 failed | 1 passed') |
| 15 | +}) |
| 16 | + |
| 17 | +test('default value of silence shows all console logs', async () => { |
| 18 | + const { stdout } = await runVitest({ |
| 19 | + include: ['./fixtures/console-some-failing.test.ts'], |
| 20 | + reporters: [new LogReporter()], |
| 21 | + }) |
| 22 | + |
| 23 | + expect(stdout.match(/stdout/g)).toHaveLength(8) |
| 24 | + |
| 25 | + expect(stdout).toContain(`\ |
| 26 | +stdout | fixtures/console-some-failing.test.ts |
| 27 | +Log from failed file |
| 28 | +
|
| 29 | +stdout | fixtures/console-some-failing.test.ts > passed test #1 |
| 30 | +Log from passed test |
| 31 | +
|
| 32 | +stdout | fixtures/console-some-failing.test.ts > failed test #1 |
| 33 | +Log from failed test |
| 34 | +
|
| 35 | +stdout | fixtures/console-some-failing.test.ts > failed suite #1 |
| 36 | +Log from failed suite |
| 37 | +
|
| 38 | +stdout | fixtures/console-some-failing.test.ts > failed suite #1 > passed test #2 |
| 39 | +Log from passed test |
| 40 | +
|
| 41 | +stdout | fixtures/console-some-failing.test.ts > failed suite #1 > failed test #2 |
| 42 | +Log from failed test |
| 43 | +
|
| 44 | +stdout | fixtures/console-some-failing.test.ts > passed suite #2 |
| 45 | +Log from passed suite |
| 46 | +
|
| 47 | +stdout | fixtures/console-some-failing.test.ts > passed suite #2 > passed test #3 |
| 48 | +Log from passed test`, |
| 49 | + ) |
| 50 | +}) |
| 51 | + |
| 52 | +test('{ silent: "silent-passed-tests" } shows all console logs from failed tests only', async () => { |
| 53 | + const { stdout } = await runVitest({ |
| 54 | + include: ['./fixtures/console-some-failing.test.ts'], |
| 55 | + silent: 'passed-only', |
| 56 | + reporters: [new LogReporter()], |
| 57 | + }) |
| 58 | + |
| 59 | + expect(stdout).toContain(`\ |
| 60 | +stdout | fixtures/console-some-failing.test.ts > failed test #1 |
| 61 | +Log from failed test |
| 62 | +
|
| 63 | +stdout | fixtures/console-some-failing.test.ts > failed suite #1 > failed test #2 |
| 64 | +Log from failed test |
| 65 | +
|
| 66 | +stdout | fixtures/console-some-failing.test.ts > failed suite #1 |
| 67 | +Log from failed suite |
| 68 | +
|
| 69 | +stdout | fixtures/console-some-failing.test.ts |
| 70 | +Log from failed file`, |
| 71 | + ) |
| 72 | + |
| 73 | + expect(stdout).not.toContain('Log from passed') |
| 74 | + expect(stdout.match(/stdout/g)).toHaveLength(4) |
| 75 | +}) |
| 76 | + |
| 77 | +class LogReporter extends DefaultReporter { |
| 78 | + isTTY = true |
| 79 | + onTaskUpdate() {} |
| 80 | +} |
0 commit comments