Skip to content

fix(reporter): allow dot reporter to work in non interactive terminals #7994

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

Merged
merged 5 commits into from
Jun 4, 2025
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
20 changes: 14 additions & 6 deletions packages/vitest/src/node/reporters/dot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { File, Test } from '@vitest/runner'
import type { Writable } from 'node:stream'
import type { Vitest } from '../core'
import type { TestCase, TestModule } from './reported-tasks'
import c from 'tinyrainbow'
Expand Down Expand Up @@ -30,11 +31,8 @@ export class DotReporter extends BaseReporter {
}
}

printTestModule(testModule: TestModule): void {
if (!this.isTTY) {
super.printTestModule(testModule)
}
}
// Ignore default logging of base reporter
printTestModule(): void {}

onWatcherRerun(files: string[], trigger?: string): void {
this.tests.clear()
Expand All @@ -47,6 +45,9 @@ export class DotReporter extends BaseReporter {
const finalLog = formatTests(Array.from(this.tests.values()))
this.ctx.logger.log(finalLog)
}
else {
this.ctx.logger.log()
}

this.tests.clear()
this.renderer?.finish()
Expand All @@ -70,10 +71,17 @@ export class DotReporter extends BaseReporter {
}

onTestCaseResult(test: TestCase): void {
const result = test.result().state

// On non-TTY the finished tests are printed immediately
if (!this.isTTY && result !== 'pending') {
(this.ctx.logger.outputStream as Writable).write(formatTests([result]))
}

super.onTestCaseResult(test)

this.finishedTests.add(test.id)
this.tests.set(test.id, test.result().state || 'skipped')
this.tests.set(test.id, result || 'skipped')
this.renderer?.schedule()
}

Expand Down
55 changes: 1 addition & 54 deletions test/reporters/tests/dot.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { describe, expect, test } from 'vitest'
import { runVitest } from '../../test-utils'

describe('{ isTTY: true }', () => {
const isTTY = true

describe.each([true, false])('{ isTTY: %s }', (isTTY) => {
test('renders successful tests', async () => {
const { stdout, stderr } = await runVitest({
include: ['./fixtures/ok.test.ts'],
Expand Down Expand Up @@ -45,54 +43,3 @@ describe('{ isTTY: true }', () => {
expect(stderr).toContain('')
})
})

describe('{ isTTY: false }', () => {
const isTTY = false

test('renders successful tests', async () => {
const { stdout, stderr } = await runVitest({
include: ['./fixtures/ok.test.ts'],
reporters: [['dot', { isTTY }]],
typecheck: undefined,
})

expect(stdout).toContain('✓ fixtures/ok.test.ts')
expect(stdout).toContain('Test Files 1 passed (1)')
expect(stdout).not.toContain('·')

expect(stderr).toBe('')
})

test('renders failing tests', async () => {
const { stdout, stderr } = await runVitest({
include: ['./fixtures/some-failing.test.ts'],
reporters: [['dot', { isTTY }]],
typecheck: undefined,
})

expect(stdout).toContain('❯ fixtures/some-failing.test.ts (2 tests | 1 failed)')
expect(stdout).toContain('✓ 2 + 3 = 5')
expect(stdout).toContain('× 3 + 3 = 7')
expect(stdout).not.toContain('\n·x\n')

expect(stdout).toContain('Test Files 1 failed (1)')
expect(stdout).toContain('Tests 1 failed | 1 passed')

expect(stderr).toContain('AssertionError: expected 6 to be 7 // Object.is equality')
})

test('renders skipped tests', async () => {
const { stdout, stderr } = await runVitest({
include: ['./fixtures/all-skipped.test.ts'],
reporters: [['dot', { isTTY }]],
typecheck: undefined,
})

expect(stdout).toContain('↓ fixtures/all-skipped.test.ts (2 tests | 2 skipped)')
expect(stdout).toContain('Test Files 1 skipped (1)')
expect(stdout).toContain('Tests 1 skipped | 1 todo')
expect(stdout).not.toContain('\n--\n')

expect(stderr).toContain('')
})
})
Loading