-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reporters): show full test suite when testing 1 spec file at a t…
…ime (#3543)
- Loading branch information
Showing
7 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { DefaultReporter } from '../../../../packages/vitest/src/node/reporters/default' | ||
|
||
export default class MockDefaultReporter extends DefaultReporter { | ||
isTTY = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { describe, expect, test } from 'vitest' | ||
|
||
describe('a passed', () => { | ||
test.each([1, 2, 3])('a%d test', (d) => { | ||
expect(d).toBe(d) | ||
}) | ||
describe('nested a', () => { | ||
test.each([1, 2, 3])('nested a%d test', (d) => { | ||
expect(d).toBe(d) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('a failed', () => { | ||
test.each([1, 2, 3])('a failed %d test', (d) => { | ||
expect(d).toBe(d) | ||
}) | ||
test('a failed test', () => { | ||
expect(1).toBe(2) | ||
}) | ||
describe('nested a failed', () => { | ||
test.each([1, 2, 3])('nested a failed %d test', (d) => { | ||
expect(d).toBe(d) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { describe, expect, test } from 'vitest' | ||
|
||
describe('b1 passed', () => { | ||
test.each([1, 2, 3])('b%d test', (d) => { | ||
expect(d).toBe(d) | ||
}) | ||
describe('nested b', () => { | ||
test.each([1, 2, 3])('nested b%d test', (d) => { | ||
expect(d).toBe(d) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('b1 failed', () => { | ||
test.each([1, 2, 3])('b%d test', (d) => { | ||
expect(d).toBe(d) | ||
}) | ||
test('b failed test', () => { | ||
expect(1).toBe(2) | ||
}) | ||
describe('nested b', () => { | ||
test.each([1, 2, 3])('nested b%d test', (d) => { | ||
expect(d).toBe(d) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { describe, expect, test } from 'vitest' | ||
|
||
describe('b2 passed', () => { | ||
test.each([1, 2, 3])('b%d test', (d) => { | ||
expect(d).toBe(d) | ||
}) | ||
describe('nested b', () => { | ||
test.each([1, 2, 3])('nested b%d test', (d) => { | ||
expect(d).toBe(d) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('b2 failed', () => { | ||
test.each([1, 2, 3])('b%d test', (d) => { | ||
expect(d).toBe(d) | ||
}) | ||
test('b failed test', () => { | ||
expect(1).toBe(2) | ||
}) | ||
describe('nested b', () => { | ||
test.each([1, 2, 3])('nested b%d test', (d) => { | ||
expect(d).toBe(d) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineConfig } from 'vitest/config' | ||
|
||
process.stdin.isTTY = true | ||
process.stdin.setRawMode = () => process.stdin | ||
|
||
export default defineConfig({ | ||
test: { | ||
reporters: './MockReporter', | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import path from 'pathe' | ||
import { describe, expect, test } from 'vitest' | ||
import { runVitestCli } from '../../test-utils' | ||
|
||
const resolve = (id = '') => path.resolve(__dirname, '../fixtures/default', id) | ||
async function run(fileFilter: string[], watch = false, ...args: string[]) { | ||
return runVitestCli( | ||
...fileFilter, | ||
'--root', | ||
resolve(), | ||
watch ? '--watch' : '--run', | ||
...args, | ||
) | ||
} | ||
|
||
describe('default reporter', async () => { | ||
test('normal', async () => { | ||
const { stdout } = await run(['b1.test.ts', 'b2.test.ts']) | ||
expect(stdout).contain('✓ b2 test') | ||
expect(stdout).not.contain('✓ nested b1 test') | ||
expect(stdout).contain('× b failed test') | ||
}) | ||
|
||
test('show full test suite when only one file', async () => { | ||
const { stdout } = await run(['a.test.ts']) | ||
expect(stdout).contain('✓ a1 test') | ||
expect(stdout).contain('✓ nested a3 test') | ||
expect(stdout).contain('× a failed test') | ||
expect(stdout).contain('nested a failed 1 test') | ||
}) | ||
|
||
test('rerun should undo', async () => { | ||
const vitest = await run([], true, '-t', 'passed') | ||
|
||
// one file | ||
vitest.write('p') | ||
await vitest.waitForStdout('Input filename pattern') | ||
vitest.write('a\n') | ||
await vitest.waitForStdout('Filename pattern: a') | ||
await vitest.waitForStdout('Waiting for file changes') | ||
expect(vitest.stdout).contain('✓ a1 test') | ||
expect(vitest.stdout).contain('✓ nested a3 test') | ||
|
||
// rerun and two files | ||
vitest.write('p') | ||
await vitest.waitForStdout('Input filename pattern') | ||
vitest.write('b\n') | ||
await vitest.waitForStdout('Filename pattern: b') | ||
await vitest.waitForStdout('PASS Waiting for file changes...') | ||
expect(vitest.stdout).toContain('RERUN') | ||
expect(vitest.stdout).toContain('b1.test.ts') | ||
expect(vitest.stdout).toContain('b2.test.ts') | ||
expect(vitest.stdout).not.toContain('nested b1 test') | ||
expect(vitest.stdout).not.toContain('b1 test') | ||
expect(vitest.stdout).not.toContain('b2 test') | ||
}) | ||
}, 120000) |