Skip to content

Commit ba9b51c

Browse files
authored
fix(reporter): --hideSkippedTests should hide suites too (#7695)
1 parent 9695d73 commit ba9b51c

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ export abstract class BaseReporter implements Reporter {
149149
this.log(` ${title} ${task.name} ${suffix}`)
150150

151151
for (const suite of suites) {
152+
if (this.ctx.config.hideSkippedTests && (suite.mode === 'skip' || suite.result?.state === 'skip')) {
153+
// Skipped suites are hidden when --hideSkippedTests
154+
continue
155+
}
156+
152157
const tests = suite.tasks.filter(task => task.type === 'test')
153158

154159
if (!('filepath' in suite)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { expect, describe, test } from 'vitest'
2+
3+
test('passing test #1', () => {})
4+
5+
describe("passing suite", () => {
6+
test('passing test #2', () => {})
7+
})
8+
9+
test.skip('skipped test #1', () => {})
10+
11+
describe.skip("skipped suite", () => {
12+
test('skipped test #2', () => {})
13+
})

test/reporters/tests/default.test.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,33 @@ describe('default reporter', async () => {
130130

131131
test('prints skipped tests by default when a single file is run', async () => {
132132
const { stdout } = await runVitest({
133-
include: ['fixtures/all-passing-or-skipped.test.ts'],
133+
include: ['fixtures/pass-and-skip-test-suites.test.ts'],
134134
reporters: [['default', { isTTY: true, summary: false }]],
135135
config: 'fixtures/vitest.config.ts',
136136
})
137137

138-
expect(stdout).toContain('✓ fixtures/all-passing-or-skipped.test.ts (2 tests | 1 skipped)')
139-
expect(stdout).toContain('✓ 2 + 3 = 5')
140-
expect(stdout).toContain('↓ 3 + 3 = 6')
138+
expect(trimReporterOutput(stdout)).toMatchInlineSnapshot(`
139+
"✓ fixtures/pass-and-skip-test-suites.test.ts (4 tests | 2 skipped) [...]ms
140+
✓ passing test #1 [...]ms
141+
↓ skipped test #1
142+
✓ passing suite > passing test #2 [...]ms
143+
↓ skipped suite > skipped test #2"
144+
`)
141145
})
142146

143147
test('hides skipped tests when --hideSkippedTests and a single file is run', async () => {
144148
const { stdout } = await runVitest({
145-
include: ['fixtures/all-passing-or-skipped.test.ts'],
149+
include: ['fixtures/pass-and-skip-test-suites.test.ts'],
146150
reporters: [['default', { isTTY: true, summary: false }]],
147151
hideSkippedTests: true,
148152
config: false,
149153
})
150154

151-
expect(stdout).toContain('✓ fixtures/all-passing-or-skipped.test.ts (2 tests | 1 skipped)')
152-
expect(stdout).toContain('✓ 2 + 3 = 5')
153-
expect(stdout).not.toContain('↓ 3 + 3 = 6')
155+
expect(trimReporterOutput(stdout)).toMatchInlineSnapshot(`
156+
"✓ fixtures/pass-and-skip-test-suites.test.ts (4 tests | 2 skipped) [...]ms
157+
✓ passing test #1 [...]ms
158+
✓ passing suite > passing test #2 [...]ms"
159+
`)
154160
})
155161

156162
test('prints retry count', async () => {

test/reporters/tests/verbose.test.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,35 @@ test('prints error properties', async () => {
2727

2828
test('prints skipped tests by default', async () => {
2929
const { stdout } = await runVitest({
30-
include: ['fixtures/all-passing-or-skipped.test.ts'],
30+
include: ['fixtures/pass-and-skip-test-suites.test.ts'],
3131
reporters: [['verbose', { isTTY: true, summary: false }]],
3232
config: false,
3333
})
3434

3535
expect(trimReporterOutput(stdout)).toMatchInlineSnapshot(`
36-
"✓ fixtures/all-passing-or-skipped.test.ts (2 tests | 1 skipped) [...]ms
37-
✓ 2 + 3 = 5 [...]ms
38-
↓ 3 + 3 = 6"
36+
"✓ fixtures/pass-and-skip-test-suites.test.ts (4 tests | 2 skipped) [...]ms
37+
✓ passing test #1 [...]ms
38+
↓ skipped test #1
39+
✓ passing suite (1)
40+
✓ passing test #2 [...]ms
41+
↓ skipped suite (1)
42+
↓ skipped test #2"
3943
`)
4044
})
4145

4246
test('hides skipped tests when --hideSkippedTests', async () => {
4347
const { stdout } = await runVitest({
44-
include: ['fixtures/all-passing-or-skipped.test.ts'],
48+
include: ['fixtures/pass-and-skip-test-suites.test.ts'],
4549
reporters: [['verbose', { isTTY: true, summary: false }]],
4650
hideSkippedTests: true,
4751
config: false,
4852
})
4953

5054
expect(trimReporterOutput(stdout)).toMatchInlineSnapshot(`
51-
"✓ fixtures/all-passing-or-skipped.test.ts (2 tests | 1 skipped) [...]ms
52-
✓ 2 + 3 = 5 [...]ms"
55+
"✓ fixtures/pass-and-skip-test-suites.test.ts (4 tests | 2 skipped) [...]ms
56+
✓ passing test #1 [...]ms
57+
✓ passing suite (1)
58+
✓ passing test #2 [...]ms"
5359
`)
5460
})
5561

0 commit comments

Comments
 (0)