Skip to content

Commit 8181e06

Browse files
authored
fix: hideSkippedTests should not hide test.todo (fix #9562) (#9781)
1 parent d9af844 commit 8181e06

File tree

8 files changed

+42
-12
lines changed

8 files changed

+42
-12
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export abstract class BaseReporter implements Reporter {
134134
let testsCount = 0
135135
let failedCount = 0
136136
let skippedCount = 0
137+
let todoCount = 0
137138

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

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

@@ -161,10 +162,15 @@ export abstract class BaseReporter implements Reporter {
161162
failedCount++
162163
}
163164
else if (testResult.state === 'skipped') {
164-
skippedCount++
165+
if (child.options.mode === 'todo') {
166+
todoCount++
167+
}
168+
else {
169+
skippedCount++
170+
}
165171
}
166172

167-
if (this.ctx.config.hideSkippedTests && suiteState === 'skipped') {
173+
if (this.ctx.config.hideSkippedTests && suiteState === 'skipped' && child.options.mode !== 'todo') {
168174
// Skipped suites are hidden when --hideSkippedTests
169175
continue
170176
}
@@ -185,6 +191,7 @@ export abstract class BaseReporter implements Reporter {
185191
tests: testsCount,
186192
failed: failedCount,
187193
skipped: skippedCount,
194+
todo: todoCount,
188195
}))
189196
logs.forEach(log => this.log(log))
190197
}
@@ -205,7 +212,7 @@ export abstract class BaseReporter implements Reporter {
205212
this.log(` ${padding}${c.yellow(c.dim(F_CHECK))} ${this.getTestName(test.task, separator)} ${suffix}`)
206213
}
207214

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

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

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

240+
if (counts.todo) {
241+
state += c.dim(' | ') + c.gray(`${counts.todo} todo`)
242+
}
243+
232244
let suffix = c.dim('(') + state + c.dim(')') + this.getDurationPrefix(testModule.task)
233245

234246
const diagnostic = testModule.diagnostic()

packages/vitest/src/node/reporters/renderers/figures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export const F_CHECK = '✓'
88
export const F_CROSS = '×'
99
export const F_LONG_DASH = '⎯'
1010
export const F_RIGHT_TRI = '▶'
11+
export const F_TODO = '□'
1112
export const F_TREE_NODE_MIDDLE = '├──'
1213
export const F_TREE_NODE_END = '└──'

packages/vitest/src/node/reporters/renderers/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ import {
1414
F_DOWN_RIGHT,
1515
F_LONG_DASH,
1616
F_POINTER,
17+
F_TODO,
1718
} from './figures'
1819

1920
export const pointer: string = c.yellow(F_POINTER)
2021
export const skipped: string = c.dim(c.gray(F_DOWN))
22+
export const todo: string = c.dim(c.gray(F_TODO))
2123
export const benchmarkPass: string = c.green(F_DOT)
2224
export const testPass: string = c.green(F_CHECK)
2325
export const taskFail: string = c.red(F_CROSS)
@@ -181,7 +183,11 @@ export function getStateString(
181183
}
182184

183185
export function getStateSymbol(task: Task): string {
184-
if (task.mode === 'skip' || task.mode === 'todo') {
186+
if (task.mode === 'todo') {
187+
return todo
188+
}
189+
190+
if (task.mode === 'skip') {
185191
return skipped
186192
}
187193

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,12 @@ export class SummaryReporter implements Reporter {
221221
this.tests.failed++
222222
}
223223
else if (!result?.state || result?.state === 'skipped') {
224-
this.tests.skipped++
224+
if (test.options.mode === 'todo') {
225+
this.tests.todo++
226+
}
227+
else {
228+
this.tests.skipped++
229+
}
225230
}
226231

227232
this.renderer.schedule()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class VerboseReporter extends DefaultReporter {
1818

1919
const testResult = test.result()
2020

21-
if (this.ctx.config.hideSkippedTests && testResult.state === 'skipped') {
21+
if (this.ctx.config.hideSkippedTests && testResult.state === 'skipped' && test.options.mode !== 'todo') {
2222
return
2323
}
2424

test/cli/fixtures/reporters/pass-and-skip-test-suites.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, describe, test } from 'vitest'
1+
import { describe, test } from 'vitest'
22

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

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

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

11+
test.todo('todo test #1')
12+
1113
describe.skip("skipped suite", () => {
1214
test('skipped test #2', () => {})
1315
})

test/cli/test/reporters/default.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,12 @@ describe('default reporter', async () => {
164164
})
165165

166166
expect(trimReporterOutput(stdout)).toMatchInlineSnapshot(`
167-
"✓ fixtures/reporters/pass-and-skip-test-suites.test.ts (4 tests | 2 skipped) [...]ms
167+
"✓ fixtures/reporters/pass-and-skip-test-suites.test.ts (5 tests | 2 skipped | 1 todo) [...]ms
168168
✓ passing test #1 [...]ms
169169
✓ passing suite (1)
170170
✓ passing test #2 [...]ms
171171
↓ skipped test #1
172+
□ todo test #1
172173
↓ skipped suite (1)
173174
↓ skipped test #2"
174175
`)
@@ -183,10 +184,11 @@ describe('default reporter', async () => {
183184
})
184185

185186
expect(trimReporterOutput(stdout)).toMatchInlineSnapshot(`
186-
"✓ fixtures/reporters/pass-and-skip-test-suites.test.ts (4 tests | 2 skipped) [...]ms
187+
"✓ fixtures/reporters/pass-and-skip-test-suites.test.ts (5 tests | 2 skipped | 1 todo) [...]ms
187188
✓ passing test #1 [...]ms
188189
✓ passing suite (1)
189-
✓ passing test #2 [...]ms"
190+
✓ passing test #2 [...]ms
191+
□ todo test #1"
190192
`)
191193
})
192194

test/cli/test/reporters/verbose.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ test('prints skipped tests by default', async () => {
3636
"✓ fixtures/reporters/pass-and-skip-test-suites.test.ts > passing test #1 [...]ms
3737
✓ fixtures/reporters/pass-and-skip-test-suites.test.ts > passing suite > passing test #2 [...]ms
3838
↓ fixtures/reporters/pass-and-skip-test-suites.test.ts > skipped test #1
39+
□ fixtures/reporters/pass-and-skip-test-suites.test.ts > todo test #1
3940
↓ fixtures/reporters/pass-and-skip-test-suites.test.ts > skipped suite > skipped test #2"
4041
`)
4142
})
@@ -50,7 +51,8 @@ test('hides skipped tests when --hideSkippedTests', async () => {
5051

5152
expect(trimReporterOutput(stdout)).toMatchInlineSnapshot(`
5253
"✓ fixtures/reporters/pass-and-skip-test-suites.test.ts > passing test #1 [...]ms
53-
✓ fixtures/reporters/pass-and-skip-test-suites.test.ts > passing suite > passing test #2 [...]ms"
54+
✓ fixtures/reporters/pass-and-skip-test-suites.test.ts > passing suite > passing test #2 [...]ms
55+
□ fixtures/reporters/pass-and-skip-test-suites.test.ts > todo test #1"
5456
`)
5557
})
5658

0 commit comments

Comments
 (0)