Light Mode

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 55d5dad

Browse files
authored
fix(runner): respect nested test.only within describe.only (fix #9021) (#9213)
1 parent 79cf623 commit 55d5dad

File tree

2 files changed

+28
-1
lines changed
  • packages/runner/src/utils
    • collect.ts
  • test/core/test
    • nested-only.test.ts

2 files changed

+28
-1
lines changed

packages/runner/src/utils/collect.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ export function interpretTaskModes(
2020
const traverseSuite = (suite: Suite, parentIsOnly?: boolean, parentMatchedWithLocation?: boolean) => {
2121
const suiteIsOnly = parentIsOnly || suite.mode === 'only'
2222

23+
// Check if any tasks in this suite have `.only` - if so, only those should run
24+
const hasSomeTasksOnly = onlyMode && suite.tasks.some(
25+
t => t.mode === 'only' || (t.type === 'suite' && someTasksAreOnly(t)),
26+
)
27+
2328
suite.tasks.forEach((t) => {
2429
// Check if either the parent suite or the task itself are marked as included
25-
const includeTask = suiteIsOnly || t.mode === 'only'
30+
// If there are tasks with `.only` in this suite, only include those (not all tasks from describe.only)
31+
const includeTask = hasSomeTasksOnly
32+
? (t.mode === 'only' || (t.type === 'suite' && someTasksAreOnly(t)))
33+
: (suiteIsOnly || t.mode === 'only')
2634
if (onlyMode) {
2735
if (t.type === 'suite' && (includeTask || someTasksAreOnly(t))) {
2836
// Don't skip this suite

test/core/test/nested-only.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, it } from 'vitest'
2+
3+
describe('nested only behavior', () => {
4+
describe.only('describe.only with nested test.only', () => {
5+
it.only('should be the only test that runs', () => {
6+
expect(true).toBe(true)
7+
})
8+
9+
it('should NOT run because the previous test has test.only', () => {
10+
throw new Error('This test should not run')
11+
})
12+
})
13+
14+
describe('another suite', () => {
15+
it('should not run - outside describe.only', () => {
16+
throw new Error('This test should not run')
17+
})
18+
})
19+
})

0 commit comments

Comments
(0)