From ba9b51cccc49888b48cc4570ee064bd39b47e723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Wed, 19 Mar 2025 08:16:04 +0200 Subject: [PATCH] fix(reporter): `--hideSkippedTests` should hide suites too (#7695) --- packages/vitest/src/node/reporters/base.ts | 5 +++++ .../pass-and-skip-test-suites.test.ts | 13 +++++++++++ test/reporters/tests/default.test.ts | 22 ++++++++++++------- test/reporters/tests/verbose.test.ts | 20 +++++++++++------ 4 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 test/reporters/fixtures/pass-and-skip-test-suites.test.ts diff --git a/packages/vitest/src/node/reporters/base.ts b/packages/vitest/src/node/reporters/base.ts index bd06708d2..2aa3e10e6 100644 --- a/packages/vitest/src/node/reporters/base.ts +++ b/packages/vitest/src/node/reporters/base.ts @@ -149,6 +149,11 @@ export abstract class BaseReporter implements Reporter { this.log(` ${title} ${task.name} ${suffix}`) for (const suite of suites) { + if (this.ctx.config.hideSkippedTests && (suite.mode === 'skip' || suite.result?.state === 'skip')) { + // Skipped suites are hidden when --hideSkippedTests + continue + } + const tests = suite.tasks.filter(task => task.type === 'test') if (!('filepath' in suite)) { diff --git a/test/reporters/fixtures/pass-and-skip-test-suites.test.ts b/test/reporters/fixtures/pass-and-skip-test-suites.test.ts new file mode 100644 index 000000000..9ba94f250 --- /dev/null +++ b/test/reporters/fixtures/pass-and-skip-test-suites.test.ts @@ -0,0 +1,13 @@ +import { expect, describe, test } from 'vitest' + +test('passing test #1', () => {}) + +describe("passing suite", () => { + test('passing test #2', () => {}) +}) + +test.skip('skipped test #1', () => {}) + +describe.skip("skipped suite", () => { + test('skipped test #2', () => {}) +}) \ No newline at end of file diff --git a/test/reporters/tests/default.test.ts b/test/reporters/tests/default.test.ts index f15ae48cd..ff947520f 100644 --- a/test/reporters/tests/default.test.ts +++ b/test/reporters/tests/default.test.ts @@ -130,27 +130,33 @@ describe('default reporter', async () => { test('prints skipped tests by default when a single file is run', async () => { const { stdout } = await runVitest({ - include: ['fixtures/all-passing-or-skipped.test.ts'], + include: ['fixtures/pass-and-skip-test-suites.test.ts'], reporters: [['default', { isTTY: true, summary: false }]], config: 'fixtures/vitest.config.ts', }) - expect(stdout).toContain('✓ fixtures/all-passing-or-skipped.test.ts (2 tests | 1 skipped)') - expect(stdout).toContain('✓ 2 + 3 = 5') - expect(stdout).toContain('↓ 3 + 3 = 6') + expect(trimReporterOutput(stdout)).toMatchInlineSnapshot(` + "✓ fixtures/pass-and-skip-test-suites.test.ts (4 tests | 2 skipped) [...]ms + ✓ passing test #1 [...]ms + ↓ skipped test #1 + ✓ passing suite > passing test #2 [...]ms + ↓ skipped suite > skipped test #2" + `) }) test('hides skipped tests when --hideSkippedTests and a single file is run', async () => { const { stdout } = await runVitest({ - include: ['fixtures/all-passing-or-skipped.test.ts'], + include: ['fixtures/pass-and-skip-test-suites.test.ts'], reporters: [['default', { isTTY: true, summary: false }]], hideSkippedTests: true, config: false, }) - expect(stdout).toContain('✓ fixtures/all-passing-or-skipped.test.ts (2 tests | 1 skipped)') - expect(stdout).toContain('✓ 2 + 3 = 5') - expect(stdout).not.toContain('↓ 3 + 3 = 6') + expect(trimReporterOutput(stdout)).toMatchInlineSnapshot(` + "✓ fixtures/pass-and-skip-test-suites.test.ts (4 tests | 2 skipped) [...]ms + ✓ passing test #1 [...]ms + ✓ passing suite > passing test #2 [...]ms" + `) }) test('prints retry count', async () => { diff --git a/test/reporters/tests/verbose.test.ts b/test/reporters/tests/verbose.test.ts index 6cca0204f..a1982f15d 100644 --- a/test/reporters/tests/verbose.test.ts +++ b/test/reporters/tests/verbose.test.ts @@ -27,29 +27,35 @@ test('prints error properties', async () => { test('prints skipped tests by default', async () => { const { stdout } = await runVitest({ - include: ['fixtures/all-passing-or-skipped.test.ts'], + include: ['fixtures/pass-and-skip-test-suites.test.ts'], reporters: [['verbose', { isTTY: true, summary: false }]], config: false, }) expect(trimReporterOutput(stdout)).toMatchInlineSnapshot(` - "✓ fixtures/all-passing-or-skipped.test.ts (2 tests | 1 skipped) [...]ms - ✓ 2 + 3 = 5 [...]ms - ↓ 3 + 3 = 6" + "✓ fixtures/pass-and-skip-test-suites.test.ts (4 tests | 2 skipped) [...]ms + ✓ passing test #1 [...]ms + ↓ skipped test #1 + ✓ passing suite (1) + ✓ passing test #2 [...]ms + ↓ skipped suite (1) + ↓ skipped test #2" `) }) test('hides skipped tests when --hideSkippedTests', async () => { const { stdout } = await runVitest({ - include: ['fixtures/all-passing-or-skipped.test.ts'], + include: ['fixtures/pass-and-skip-test-suites.test.ts'], reporters: [['verbose', { isTTY: true, summary: false }]], hideSkippedTests: true, config: false, }) expect(trimReporterOutput(stdout)).toMatchInlineSnapshot(` - "✓ fixtures/all-passing-or-skipped.test.ts (2 tests | 1 skipped) [...]ms - ✓ 2 + 3 = 5 [...]ms" + "✓ fixtures/pass-and-skip-test-suites.test.ts (4 tests | 2 skipped) [...]ms + ✓ passing test #1 [...]ms + ✓ passing suite (1) + ✓ passing test #2 [...]ms" `) }) -- 2.51.2