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
10 changes: 9 additions & 1 deletion packages/runner/src/utils/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,17 @@ export function interpretTaskModes(
const traverseSuite = (suite: Suite, parentIsOnly?: boolean, parentMatchedWithLocation?: boolean) => {
const suiteIsOnly = parentIsOnly || suite.mode === 'only'

// Check if any tasks in this suite have `.only` - if so, only those should run
const hasSomeTasksOnly = onlyMode && suite.tasks.some(
t => t.mode === 'only' || (t.type === 'suite' && someTasksAreOnly(t)),
)

suite.tasks.forEach((t) => {
// Check if either the parent suite or the task itself are marked as included
const includeTask = suiteIsOnly || t.mode === 'only'
// If there are tasks with `.only` in this suite, only include those (not all tasks from describe.only)
const includeTask = hasSomeTasksOnly
? (t.mode === 'only' || (t.type === 'suite' && someTasksAreOnly(t)))
: (suiteIsOnly || t.mode === 'only')
if (onlyMode) {
if (t.type === 'suite' && (includeTask || someTasksAreOnly(t))) {
// Don't skip this suite
Expand Down
19 changes: 19 additions & 0 deletions test/core/test/nested-only.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, expect, it } from 'vitest'

describe('nested only behavior', () => {
describe.only('describe.only with nested test.only', () => {
it.only('should be the only test that runs', () => {
expect(true).toBe(true)
})

it('should NOT run because the previous test has test.only', () => {
throw new Error('This test should not run')
})
})

describe('another suite', () => {
it('should not run - outside describe.only', () => {
throw new Error('This test should not run')
})
})
})
Loading