Skip to content

Commit 6db9f52

Browse files
fix(reporter): allow dot reporter to work in non interactive terminals (#7994)
Co-authored-by: Ari Perkkiö <[email protected]>
1 parent 5297f32 commit 6db9f52

File tree

2 files changed

+15
-60
lines changed

2 files changed

+15
-60
lines changed

packages/vitest/src/node/reporters/dot.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { File, Test } from '@vitest/runner'
2+
import type { Writable } from 'node:stream'
23
import type { Vitest } from '../core'
34
import type { TestCase, TestModule } from './reported-tasks'
45
import c from 'tinyrainbow'
@@ -30,11 +31,8 @@ export class DotReporter extends BaseReporter {
3031
}
3132
}
3233

33-
printTestModule(testModule: TestModule): void {
34-
if (!this.isTTY) {
35-
super.printTestModule(testModule)
36-
}
37-
}
34+
// Ignore default logging of base reporter
35+
printTestModule(): void {}
3836

3937
onWatcherRerun(files: string[], trigger?: string): void {
4038
this.tests.clear()
@@ -47,6 +45,9 @@ export class DotReporter extends BaseReporter {
4745
const finalLog = formatTests(Array.from(this.tests.values()))
4846
this.ctx.logger.log(finalLog)
4947
}
48+
else {
49+
this.ctx.logger.log()
50+
}
5051

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

7273
onTestCaseResult(test: TestCase): void {
74+
const result = test.result().state
75+
76+
// On non-TTY the finished tests are printed immediately
77+
if (!this.isTTY && result !== 'pending') {
78+
(this.ctx.logger.outputStream as Writable).write(formatTests([result]))
79+
}
80+
7381
super.onTestCaseResult(test)
7482

7583
this.finishedTests.add(test.id)
76-
this.tests.set(test.id, test.result().state || 'skipped')
84+
this.tests.set(test.id, result || 'skipped')
7785
this.renderer?.schedule()
7886
}
7987

test/reporters/tests/dot.test.ts

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { describe, expect, test } from 'vitest'
22
import { runVitest } from '../../test-utils'
33

4-
describe('{ isTTY: true }', () => {
5-
const isTTY = true
6-
4+
describe.each([true, false])('{ isTTY: %s }', (isTTY) => {
75
test('renders successful tests', async () => {
86
const { stdout, stderr } = await runVitest({
97
include: ['./fixtures/ok.test.ts'],
@@ -45,54 +43,3 @@ describe('{ isTTY: true }', () => {
4543
expect(stderr).toContain('')
4644
})
4745
})
48-
49-
describe('{ isTTY: false }', () => {
50-
const isTTY = false
51-
52-
test('renders successful tests', async () => {
53-
const { stdout, stderr } = await runVitest({
54-
include: ['./fixtures/ok.test.ts'],
55-
reporters: [['dot', { isTTY }]],
56-
typecheck: undefined,
57-
})
58-
59-
expect(stdout).toContain('✓ fixtures/ok.test.ts')
60-
expect(stdout).toContain('Test Files 1 passed (1)')
61-
expect(stdout).not.toContain('·')
62-
63-
expect(stderr).toBe('')
64-
})
65-
66-
test('renders failing tests', async () => {
67-
const { stdout, stderr } = await runVitest({
68-
include: ['./fixtures/some-failing.test.ts'],
69-
reporters: [['dot', { isTTY }]],
70-
typecheck: undefined,
71-
})
72-
73-
expect(stdout).toContain('❯ fixtures/some-failing.test.ts (2 tests | 1 failed)')
74-
expect(stdout).toContain('✓ 2 + 3 = 5')
75-
expect(stdout).toContain('× 3 + 3 = 7')
76-
expect(stdout).not.toContain('\n·x\n')
77-
78-
expect(stdout).toContain('Test Files 1 failed (1)')
79-
expect(stdout).toContain('Tests 1 failed | 1 passed')
80-
81-
expect(stderr).toContain('AssertionError: expected 6 to be 7 // Object.is equality')
82-
})
83-
84-
test('renders skipped tests', async () => {
85-
const { stdout, stderr } = await runVitest({
86-
include: ['./fixtures/all-skipped.test.ts'],
87-
reporters: [['dot', { isTTY }]],
88-
typecheck: undefined,
89-
})
90-
91-
expect(stdout).toContain('↓ fixtures/all-skipped.test.ts (2 tests | 2 skipped)')
92-
expect(stdout).toContain('Test Files 1 skipped (1)')
93-
expect(stdout).toContain('Tests 1 skipped | 1 todo')
94-
expect(stdout).not.toContain('\n--\n')
95-
96-
expect(stderr).toContain('')
97-
})
98-
})

0 commit comments

Comments
 (0)