diff --git a/packages/vitest/src/node/reporters/base.ts b/packages/vitest/src/node/reporters/base.ts index 10664b7fcad2..8d938b6a729c 100644 --- a/packages/vitest/src/node/reporters/base.ts +++ b/packages/vitest/src/node/reporters/base.ts @@ -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 @@ -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}`, ) } @@ -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}`) } } } diff --git a/test/reporters/fixtures/repeats.test.ts b/test/reporters/fixtures/repeats.test.ts new file mode 100644 index 000000000000..96e465aa78e2 --- /dev/null +++ b/test/reporters/fixtures/repeats.test.ts @@ -0,0 +1,5 @@ +import { expect, test } from 'vitest' + +test('repeat couple of times',{ repeats: 3 }, () => { + expect(true).toBe(true) +}) diff --git a/test/reporters/fixtures/retry.test.ts b/test/reporters/fixtures/retry.test.ts new file mode 100644 index 000000000000..4a096aebbb7a --- /dev/null +++ b/test/reporters/fixtures/retry.test.ts @@ -0,0 +1,7 @@ +import { expect, test } from 'vitest' + +let number = 0 + +test('pass after retries', () => { + expect(number++).toBe(3) +}) diff --git a/test/reporters/tests/default.test.ts b/test/reporters/tests/default.test.ts index 7fac2612734e..23b3dcafedf5 100644 --- a/test/reporters/tests/default.test.ts +++ b/test/reporters/tests/default.test.ts @@ -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) diff --git a/test/reporters/tests/verbose.test.ts b/test/reporters/tests/verbose.test.ts index 7c760147ca5e..c3258a4b6e38 100644 --- a/test/reporters/tests/verbose.test.ts +++ b/test/reporters/tests/verbose.test.ts @@ -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 @@ -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)') +})