Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(reporters): show full test suite when testing 1 spec file at a time #3543

Merged
merged 23 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/vitest/src/node/reporters/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ import { createListRenderer } from './renderers/listRenderer'
export class DefaultReporter extends BaseReporter {
renderer?: ReturnType<typeof createListRenderer>
rendererOptions: ListRendererOptions = {} as any
private renderSucceedDefault?: boolean

onPathsCollected(paths: string[] = []) {
if (this.isTTY) {
if (this.renderSucceedDefault === undefined)
this.renderSucceedDefault = !!this.rendererOptions.renderSucceed

if (this.renderSucceedDefault !== true)
this.rendererOptions.renderSucceed = paths.length <= 1
}
}
sheremet-va marked this conversation as resolved.
Show resolved Hide resolved

async onTestRemoved(trigger?: string) {
await this.stopListRender()
Expand Down
5 changes: 5 additions & 0 deletions test/reporters/fixtures/default/MockReporter.ts
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
}
26 changes: 26 additions & 0 deletions test/reporters/fixtures/default/a.test.ts
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)
})
})
})
26 changes: 26 additions & 0 deletions test/reporters/fixtures/default/b1.test.ts
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)
})
})
})
26 changes: 26 additions & 0 deletions test/reporters/fixtures/default/b2.test.ts
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)
})
})
})
10 changes: 10 additions & 0 deletions test/reporters/fixtures/default/vitest.config.ts
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',
},
})
57 changes: 57 additions & 0 deletions test/reporters/tests/default.test.ts
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)