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 7 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)
})
})
})
24 changes: 24 additions & 0 deletions test/reporters/tests/default.test.ts
@@ -0,0 +1,24 @@
import { resolve } from 'pathe'
import { describe, expect, test } from 'vitest'
import { runVitest } from '../../test-utils'

const root = resolve(__dirname, '../fixtures')
const run = async (fileFilter: string[]) => await runVitest({ root, reporters: 'default', config: false }, fileFilter)

describe.skipIf(process.env.CI)('default reporter', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I even need to explain why you shouldn't skip tests in CI?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function only works with TTY, but CI will cause isTTY to be false

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mock it then 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, yes, I forgot that I could use this very useful method.😅

process.stdout.isTTY = true
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)
})