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 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/vitest/src/node/reporters/default.ts
Expand Up @@ -8,6 +8,11 @@ export class DefaultReporter extends BaseReporter {
renderer?: ReturnType<typeof createListRenderer>
rendererOptions: ListRendererOptions = {} as any

onPathsCollected(paths: string[] = []) {
if (paths.length === 1)
this.rendererOptions.renderSucceed = true
}
sheremet-va marked this conversation as resolved.
Show resolved Hide resolved

async onTestRemoved(trigger?: string) {
await this.stopListRender()
this.ctx.logger.clearScreen(c.yellow('Test removed...') + (trigger ? c.dim(` [ ${this.relative(trigger)} ]\n`) : ''), true)
Expand Down
26 changes: 26 additions & 0 deletions test/reporters/fixtures/default/a.test.ts
@@ -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
@@ -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
@@ -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)
})
})
})
37 changes: 37 additions & 0 deletions test/reporters/tests/default.test.ts
@@ -0,0 +1,37 @@
import { resolve } from 'pathe'
import { describe, expect, test } from 'vitest'
import { runVitest } from '../../test-utils'
import { DefaultReporter } from '../../../packages/vitest/src/node/reporters/default'

class MockDefaultReporter extends DefaultReporter {
isTTY = true
}

const root = resolve(__dirname, '../fixtures')
async function run(fileFilter: string[]) {
return await runVitest({
deps: {
inline: ['std-env'],
},
root,
reporters: new MockDefaultReporter(),
config: false,
}, fileFilter)
}

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')
}, 120000)

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')
}, 120000)
})