Skip to content

Commit

Permalink
fix(reporters): check --hideSkippedTests in base reporter (#6988)
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio authored Dec 1, 2024
1 parent 1fa16f9 commit 721a5b8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/vitest/src/node/reporters/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ export abstract class BaseReporter implements Reporter {
)
}

else if (this.ctx.config.hideSkippedTests && (test.mode === 'skip' || test.result?.state === 'skip')) {
// Skipped tests are hidden when --hideSkippedTests
}

// also print skipped tests that have notes
else if (test.result?.state === 'skip' && test.result.note) {
this.log(` ${getStateSymbol(test)} ${getTestName(test)}${c.dim(c.gray(` [${test.result.note}]`))}`)
Expand Down
25 changes: 25 additions & 0 deletions test/reporters/tests/default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,29 @@ describe('default reporter', async () => {
expect(result.stderr).not.toContain(`Serialized Error`)
expect(result.stderr).not.toContain(`status: 'not found'`)
})

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'],
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')
})

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'],
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')
})
}, 120000)
25 changes: 25 additions & 0 deletions test/reporters/tests/verbose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,28 @@ test('prints error properties', async () => {

expect(result.stderr).toContain(`Serialized Error: { code: 404, status: 'not found' }`)
})

test('prints skipped tests by default', async () => {
const { stdout } = await runVitest({
include: ['fixtures/all-passing-or-skipped.test.ts'],
reporters: [['verbose', { isTTY: true, summary: false }]],
config: false,
})

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')
})

test('hides skipped tests when --hideSkippedTests', async () => {
const { stdout } = await runVitest({
include: ['fixtures/all-passing-or-skipped.test.ts'],
reporters: [['verbose', { 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')
})

0 comments on commit 721a5b8

Please sign in to comment.