Skip to content

Commit 3496a01

Browse files
AriPerkkiohi-ogawa
andauthoredDec 3, 2024··
fix(reporters): show retry and repeats counts (#7004)
Co-authored-by: Hiroshi Ogawa <hi.ogawa.zz@gmail.com>
1 parent 2324375 commit 3496a01

File tree

5 files changed

+72
-6
lines changed

5 files changed

+72
-6
lines changed
 

‎packages/vitest/src/node/reporters/base.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,19 @@ export abstract class BaseReporter implements Reporter {
114114
const anyFailed = tests.some(test => test.result?.state === 'fail')
115115

116116
for (const test of tests) {
117-
const duration = test.result?.duration
117+
const { duration, retryCount, repeatCount } = test.result || {}
118+
let suffix = ''
119+
120+
if (retryCount != null && retryCount > 0) {
121+
suffix += c.yellow(` (retry x${retryCount})`)
122+
}
123+
124+
if (repeatCount != null && repeatCount > 0) {
125+
suffix += c.yellow(` (repeat x${repeatCount})`)
126+
}
118127

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

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

@@ -144,7 +152,7 @@ export abstract class BaseReporter implements Reporter {
144152
}
145153

146154
else if (this.renderSucceed || anyFailed) {
147-
this.log(` ${c.dim(getStateSymbol(test))} ${getTestName(test, c.dim(' > '))}`)
155+
this.log(` ${c.dim(getStateSymbol(test))} ${getTestName(test, c.dim(' > '))}${suffix}`)
148156
}
149157
}
150158
}
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { expect, test } from 'vitest'
2+
3+
test('repeat couple of times',{ repeats: 3 }, () => {
4+
expect(true).toBe(true)
5+
})

‎test/reporters/fixtures/retry.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { expect, test } from 'vitest'
2+
3+
let number = 0
4+
5+
test('pass after retries', () => {
6+
expect(number++).toBe(3)
7+
})

‎test/reporters/tests/default.test.ts

+23
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,27 @@ describe('default reporter', async () => {
9494
expect(stdout).toContain('✓ 2 + 3 = 5')
9595
expect(stdout).not.toContain('↓ 3 + 3 = 6')
9696
})
97+
98+
test('prints retry count', async () => {
99+
const { stdout } = await runVitest({
100+
include: ['fixtures/retry.test.ts'],
101+
reporters: [['default', { isTTY: true, summary: false }]],
102+
retry: 3,
103+
config: false,
104+
})
105+
106+
expect(stdout).toContain('1 passed')
107+
expect(stdout).toContain('✓ pass after retries (retry x3)')
108+
})
109+
110+
test('prints repeat count', async () => {
111+
const { stdout } = await runVitest({
112+
include: ['fixtures/repeats.test.ts'],
113+
reporters: [['default', { isTTY: true, summary: false }]],
114+
config: false,
115+
})
116+
117+
expect(stdout).toContain('1 passed')
118+
expect(stdout).toContain('✓ repeat couple of times (repeat x3)')
119+
})
97120
}, 120000)

‎test/reporters/tests/verbose.test.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test('duration', async () => {
88
env: { CI: '1' },
99
})
1010

11-
const output = result.stdout.replaceAll(/\d+ms/g, '[...]ms')
11+
const output = result.stdout.replace(/\d+ms/g, '[...]ms')
1212
expect(output).toContain(`
1313
✓ basic.test.ts > fast
1414
✓ basic.test.ts > slow [...]ms
@@ -49,3 +49,26 @@ test('hides skipped tests when --hideSkippedTests', async () => {
4949
expect(stdout).toContain('✓ 2 + 3 = 5')
5050
expect(stdout).not.toContain('↓ 3 + 3 = 6')
5151
})
52+
53+
test('prints retry count', async () => {
54+
const { stdout } = await runVitest({
55+
include: ['fixtures/retry.test.ts'],
56+
reporters: [['verbose', { isTTY: true, summary: false }]],
57+
retry: 3,
58+
config: false,
59+
})
60+
61+
expect(stdout).toContain('1 passed')
62+
expect(stdout).toContain('✓ pass after retries (retry x3)')
63+
})
64+
65+
test('prints repeat count', async () => {
66+
const { stdout } = await runVitest({
67+
include: ['fixtures/repeats.test.ts'],
68+
reporters: [['verbose', { isTTY: true, summary: false }]],
69+
config: false,
70+
})
71+
72+
expect(stdout).toContain('1 passed')
73+
expect(stdout).toContain('✓ repeat couple of times (repeat x3)')
74+
})

0 commit comments

Comments
 (0)
Please sign in to comment.