Skip to content
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: 16 additions & 4 deletions packages/vitest/src/node/reporters/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export abstract class BaseReporter implements Reporter {
let testsCount = 0
let failedCount = 0
let skippedCount = 0
let todoCount = 0

// delaying logs to calculate the test stats first
// which minimizes the amount of for loops
Expand All @@ -147,7 +148,7 @@ export abstract class BaseReporter implements Reporter {
const suiteState = child.state()

// Skipped suites are hidden when --hideSkippedTests, print otherwise
if (!this.ctx.config.hideSkippedTests || suiteState !== 'skipped') {
if (!this.ctx.config.hideSkippedTests || suiteState !== 'skipped' || child.task.mode === 'todo') {
this.printTestSuite(child)
}

Expand All @@ -161,10 +162,15 @@ export abstract class BaseReporter implements Reporter {
failedCount++
}
else if (testResult.state === 'skipped') {
skippedCount++
if (child.options.mode === 'todo') {
todoCount++
}
else {
skippedCount++
}
}

if (this.ctx.config.hideSkippedTests && suiteState === 'skipped') {
if (this.ctx.config.hideSkippedTests && suiteState === 'skipped' && child.options.mode !== 'todo') {
// Skipped suites are hidden when --hideSkippedTests
continue
}
Expand All @@ -185,6 +191,7 @@ export abstract class BaseReporter implements Reporter {
tests: testsCount,
failed: failedCount,
skipped: skippedCount,
todo: todoCount,
}))
logs.forEach(log => this.log(log))
}
Expand All @@ -205,7 +212,7 @@ export abstract class BaseReporter implements Reporter {
this.log(` ${padding}${c.yellow(c.dim(F_CHECK))} ${this.getTestName(test.task, separator)} ${suffix}`)
}

else if (this.ctx.config.hideSkippedTests && (testResult.state === 'skipped')) {
else if (this.ctx.config.hideSkippedTests && testResult.state === 'skipped' && test.options.mode !== 'todo') {
// Skipped tests are hidden when --hideSkippedTests
}

Expand All @@ -218,6 +225,7 @@ export abstract class BaseReporter implements Reporter {
tests: number
failed: number
skipped: number
todo: number
}): string {
let state = c.dim(`${counts.tests} test${counts.tests > 1 ? 's' : ''}`)

Expand All @@ -229,6 +237,10 @@ export abstract class BaseReporter implements Reporter {
state += c.dim(' | ') + c.yellow(`${counts.skipped} skipped`)
}

if (counts.todo) {
state += c.dim(' | ') + c.gray(`${counts.todo} todo`)
}

let suffix = c.dim('(') + state + c.dim(')') + this.getDurationPrefix(testModule.task)

const diagnostic = testModule.diagnostic()
Expand Down
1 change: 1 addition & 0 deletions packages/vitest/src/node/reporters/renderers/figures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export const F_CHECK = '✓'
export const F_CROSS = '×'
export const F_LONG_DASH = '⎯'
export const F_RIGHT_TRI = '▶'
export const F_TODO = '□'
export const F_TREE_NODE_MIDDLE = '├──'
export const F_TREE_NODE_END = '└──'
8 changes: 7 additions & 1 deletion packages/vitest/src/node/reporters/renderers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import {
F_DOWN_RIGHT,
F_LONG_DASH,
F_POINTER,
F_TODO,
} from './figures'

export const pointer: string = c.yellow(F_POINTER)
export const skipped: string = c.dim(c.gray(F_DOWN))
export const todo: string = c.dim(c.gray(F_TODO))
export const benchmarkPass: string = c.green(F_DOT)
export const testPass: string = c.green(F_CHECK)
export const taskFail: string = c.red(F_CROSS)
Expand Down Expand Up @@ -181,7 +183,11 @@ export function getStateString(
}

export function getStateSymbol(task: Task): string {
if (task.mode === 'skip' || task.mode === 'todo') {
if (task.mode === 'todo') {
return todo
}

if (task.mode === 'skip') {
return skipped
}

Expand Down
7 changes: 6 additions & 1 deletion packages/vitest/src/node/reporters/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,12 @@ export class SummaryReporter implements Reporter {
this.tests.failed++
}
else if (!result?.state || result?.state === 'skipped') {
this.tests.skipped++
if (test.options.mode === 'todo') {
this.tests.todo++
}
else {
this.tests.skipped++
}
}

this.renderer.schedule()
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/reporters/verbose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class VerboseReporter extends DefaultReporter {

const testResult = test.result()

if (this.ctx.config.hideSkippedTests && testResult.state === 'skipped') {
if (this.ctx.config.hideSkippedTests && testResult.state === 'skipped' && test.options.mode !== 'todo') {
return
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, describe, test } from 'vitest'
import { describe, test } from 'vitest'

test('passing test #1', () => {})

Expand All @@ -8,6 +8,8 @@ describe("passing suite", () => {

test.skip('skipped test #1', () => {})

test.todo('todo test #1')

describe.skip("skipped suite", () => {
test('skipped test #2', () => {})
})
8 changes: 5 additions & 3 deletions test/cli/test/reporters/default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,12 @@ describe('default reporter', async () => {
})

expect(trimReporterOutput(stdout)).toMatchInlineSnapshot(`
"✓ fixtures/reporters/pass-and-skip-test-suites.test.ts (4 tests | 2 skipped) [...]ms
"✓ fixtures/reporters/pass-and-skip-test-suites.test.ts (5 tests | 2 skipped | 1 todo) [...]ms
✓ passing test #1 [...]ms
✓ passing suite (1)
✓ passing test #2 [...]ms
↓ skipped test #1
□ todo test #1
↓ skipped suite (1)
↓ skipped test #2"
`)
Expand All @@ -183,10 +184,11 @@ describe('default reporter', async () => {
})

expect(trimReporterOutput(stdout)).toMatchInlineSnapshot(`
"✓ fixtures/reporters/pass-and-skip-test-suites.test.ts (4 tests | 2 skipped) [...]ms
"✓ fixtures/reporters/pass-and-skip-test-suites.test.ts (5 tests | 2 skipped | 1 todo) [...]ms
✓ passing test #1 [...]ms
✓ passing suite (1)
✓ passing test #2 [...]ms"
✓ passing test #2 [...]ms
□ todo test #1"
`)
})

Expand Down
4 changes: 3 additions & 1 deletion test/cli/test/reporters/verbose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ test('prints skipped tests by default', async () => {
"✓ fixtures/reporters/pass-and-skip-test-suites.test.ts > passing test #1 [...]ms
✓ fixtures/reporters/pass-and-skip-test-suites.test.ts > passing suite > passing test #2 [...]ms
↓ fixtures/reporters/pass-and-skip-test-suites.test.ts > skipped test #1
□ fixtures/reporters/pass-and-skip-test-suites.test.ts > todo test #1
↓ fixtures/reporters/pass-and-skip-test-suites.test.ts > skipped suite > skipped test #2"
`)
})
Expand All @@ -50,7 +51,8 @@ test('hides skipped tests when --hideSkippedTests', async () => {

expect(trimReporterOutput(stdout)).toMatchInlineSnapshot(`
"✓ fixtures/reporters/pass-and-skip-test-suites.test.ts > passing test #1 [...]ms
✓ fixtures/reporters/pass-and-skip-test-suites.test.ts > passing suite > passing test #2 [...]ms"
✓ fixtures/reporters/pass-and-skip-test-suites.test.ts > passing suite > passing test #2 [...]ms
□ fixtures/reporters/pass-and-skip-test-suites.test.ts > todo test #1"
`)
})

Expand Down
Loading