File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
packages/runner/src/utils Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+ } )
You can’t perform that action at this time.
0 commit comments