|
| 1 | +import path from 'pathe' |
| 2 | +import { describe, expect, test } from 'vitest' |
| 3 | +import { runVitestCli } from '../../test-utils' |
| 4 | + |
| 5 | +const resolve = (id = '') => path.resolve(__dirname, '../fixtures/default', id) |
| 6 | +async function run(fileFilter: string[], watch = false, ...args: string[]) { |
| 7 | + return runVitestCli( |
| 8 | + ...fileFilter, |
| 9 | + '--root', |
| 10 | + resolve(), |
| 11 | + watch ? '--watch' : '--run', |
| 12 | + ...args, |
| 13 | + ) |
| 14 | +} |
| 15 | + |
| 16 | +describe('default reporter', async () => { |
| 17 | + test('normal', async () => { |
| 18 | + const { stdout } = await run(['b1.test.ts', 'b2.test.ts']) |
| 19 | + expect(stdout).contain('✓ b2 test') |
| 20 | + expect(stdout).not.contain('✓ nested b1 test') |
| 21 | + expect(stdout).contain('× b failed test') |
| 22 | + }) |
| 23 | + |
| 24 | + test('show full test suite when only one file', async () => { |
| 25 | + const { stdout } = await run(['a.test.ts']) |
| 26 | + expect(stdout).contain('✓ a1 test') |
| 27 | + expect(stdout).contain('✓ nested a3 test') |
| 28 | + expect(stdout).contain('× a failed test') |
| 29 | + expect(stdout).contain('nested a failed 1 test') |
| 30 | + }) |
| 31 | + |
| 32 | + test('rerun should undo', async () => { |
| 33 | + const vitest = await run([], true, '-t', 'passed') |
| 34 | + |
| 35 | + // one file |
| 36 | + vitest.write('p') |
| 37 | + await vitest.waitForStdout('Input filename pattern') |
| 38 | + vitest.write('a\n') |
| 39 | + await vitest.waitForStdout('Filename pattern: a') |
| 40 | + await vitest.waitForStdout('Waiting for file changes') |
| 41 | + expect(vitest.stdout).contain('✓ a1 test') |
| 42 | + expect(vitest.stdout).contain('✓ nested a3 test') |
| 43 | + |
| 44 | + // rerun and two files |
| 45 | + vitest.write('p') |
| 46 | + await vitest.waitForStdout('Input filename pattern') |
| 47 | + vitest.write('b\n') |
| 48 | + await vitest.waitForStdout('Filename pattern: b') |
| 49 | + await vitest.waitForStdout('PASS Waiting for file changes...') |
| 50 | + expect(vitest.stdout).toContain('RERUN') |
| 51 | + expect(vitest.stdout).toContain('b1.test.ts') |
| 52 | + expect(vitest.stdout).toContain('b2.test.ts') |
| 53 | + expect(vitest.stdout).not.toContain('nested b1 test') |
| 54 | + expect(vitest.stdout).not.toContain('b1 test') |
| 55 | + expect(vitest.stdout).not.toContain('b2 test') |
| 56 | + }) |
| 57 | +}, 120000) |
0 commit comments