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

fix(reporters): show retry and repeats counts #7004

Merged
merged 2 commits into from
Dec 3, 2024
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
18 changes: 13 additions & 5 deletions packages/vitest/src/node/reporters/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,19 @@ export abstract class BaseReporter implements Reporter {
const anyFailed = tests.some(test => test.result?.state === 'fail')

for (const test of tests) {
const duration = test.result?.duration
const { duration, retryCount, repeatCount } = test.result || {}
let suffix = ''

if (retryCount != null && retryCount > 0) {
suffix += c.yellow(` (retry x${retryCount})`)
}

if (repeatCount != null && repeatCount > 0) {
suffix += c.yellow(` (repeat x${repeatCount})`)
}

if (test.result?.state === 'fail') {
const suffix = this.getDurationPrefix(test)
this.log(c.red(` ${taskFail} ${getTestName(test, c.dim(' > '))}${suffix}`))
this.log(c.red(` ${taskFail} ${getTestName(test, c.dim(' > '))}${this.getDurationPrefix(test)}`) + suffix)

test.result?.errors?.forEach((e) => {
// print short errors, full errors will be at the end in summary
Expand All @@ -130,7 +138,7 @@ export abstract class BaseReporter implements Reporter {
else if (duration && duration > this.ctx.config.slowTestThreshold) {
this.log(
` ${c.yellow(c.dim(F_CHECK))} ${getTestName(test, c.dim(' > '))}`
+ ` ${c.yellow(Math.round(duration) + c.dim('ms'))}`,
+ ` ${c.yellow(Math.round(duration) + c.dim('ms'))}${suffix}`,
)
}

Expand All @@ -144,7 +152,7 @@ export abstract class BaseReporter implements Reporter {
}

else if (this.renderSucceed || anyFailed) {
this.log(` ${c.dim(getStateSymbol(test))} ${getTestName(test, c.dim(' > '))}`)
this.log(` ${c.dim(getStateSymbol(test))} ${getTestName(test, c.dim(' > '))}${suffix}`)
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/reporters/fixtures/repeats.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { expect, test } from 'vitest'

test('repeat couple of times',{ repeats: 3 }, () => {
expect(true).toBe(true)
})
7 changes: 7 additions & 0 deletions test/reporters/fixtures/retry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { expect, test } from 'vitest'

let number = 0

test('pass after retries', () => {
expect(number++).toBe(3)
})
23 changes: 23 additions & 0 deletions test/reporters/tests/default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,27 @@ describe('default reporter', async () => {
expect(stdout).toContain('✓ 2 + 3 = 5')
expect(stdout).not.toContain('↓ 3 + 3 = 6')
})

test('prints retry count', async () => {
const { stdout } = await runVitest({
include: ['fixtures/retry.test.ts'],
reporters: [['default', { isTTY: true, summary: false }]],
retry: 3,
config: false,
})

expect(stdout).toContain('1 passed')
expect(stdout).toContain('✓ pass after retries (retry x3)')
})

test('prints repeat count', async () => {
const { stdout } = await runVitest({
include: ['fixtures/repeats.test.ts'],
reporters: [['default', { isTTY: true, summary: false }]],
config: false,
})

expect(stdout).toContain('1 passed')
expect(stdout).toContain('✓ repeat couple of times (repeat x3)')
})
}, 120000)
25 changes: 24 additions & 1 deletion test/reporters/tests/verbose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test('duration', async () => {
env: { CI: '1' },
})

const output = result.stdout.replaceAll(/\d+ms/g, '[...]ms')
const output = result.stdout.replace(/\d+ms/g, '[...]ms')
expect(output).toContain(`
✓ basic.test.ts > fast
✓ basic.test.ts > slow [...]ms
Expand Down Expand Up @@ -49,3 +49,26 @@ test('hides skipped tests when --hideSkippedTests', async () => {
expect(stdout).toContain('✓ 2 + 3 = 5')
expect(stdout).not.toContain('↓ 3 + 3 = 6')
})

test('prints retry count', async () => {
const { stdout } = await runVitest({
include: ['fixtures/retry.test.ts'],
reporters: [['verbose', { isTTY: true, summary: false }]],
retry: 3,
config: false,
})

expect(stdout).toContain('1 passed')
expect(stdout).toContain('✓ pass after retries (retry x3)')
})

test('prints repeat count', async () => {
const { stdout } = await runVitest({
include: ['fixtures/repeats.test.ts'],
reporters: [['verbose', { isTTY: true, summary: false }]],
config: false,
})

expect(stdout).toContain('1 passed')
expect(stdout).toContain('✓ repeat couple of times (repeat x3)')
})
Loading