@@ -33,8 +33,8 @@ import {
3333 runWithSuite ,
3434 withTimeout ,
3535} from './context'
36- import { mergeContextFixtures , withFixtures } from './fixture'
37- import { getHooks , setFixture , setFn , setHooks } from './map'
36+ import { mergeContextFixtures , mergeScopedFixtures , withFixtures } from './fixture'
37+ import { getHooks , setFn , setHooks , setTestFixture } from './map'
3838import { getCurrentTest } from './test-state'
3939import { createChainable } from './utils/chain'
4040
@@ -340,7 +340,7 @@ function createSuiteCollector(
340340 value : context ,
341341 enumerable : false ,
342342 } )
343- setFixture ( context , options . fixtures )
343+ setTestFixture ( context , options . fixtures )
344344
345345 if ( handler ) {
346346 setFn (
@@ -395,6 +395,8 @@ function createSuiteCollector(
395395 test . type = 'test'
396396 } )
397397
398+ let collectorFixtures : FixtureItem [ ] | undefined
399+
398400 const collector : SuiteCollector = {
399401 type : 'collector' ,
400402 name,
@@ -407,6 +409,19 @@ function createSuiteCollector(
407409 task,
408410 clear,
409411 on : addHook ,
412+ fixtures ( ) {
413+ return collectorFixtures
414+ } ,
415+ scoped ( fixtures ) {
416+ const parsed = mergeContextFixtures (
417+ fixtures ,
418+ { fixtures : collectorFixtures } ,
419+ ( key : string ) => getRunner ( ) . injectValue ?.( key ) ,
420+ )
421+ if ( parsed . fixtures ) {
422+ collectorFixtures = parsed . fixtures
423+ }
424+ } ,
410425 }
411426
412427 function addHook < T extends keyof SuiteHooks > ( name : T , ...fn : SuiteHooks [ T ] ) {
@@ -734,6 +749,11 @@ export function createTaskCollector(
734749 return condition ? this : this . skip
735750 }
736751
752+ taskFn . scoped = function ( fixtures : Fixtures < Record < string , any > > ) {
753+ const collector = getCurrentSuite ( )
754+ collector . scoped ( fixtures )
755+ }
756+
737757 taskFn . extend = function ( fixtures : Fixtures < Record < string , any > > ) {
738758 const _context = mergeContextFixtures (
739759 fixtures ,
@@ -746,7 +766,15 @@ export function createTaskCollector(
746766 optionsOrFn ?: TestOptions | TestFunction ,
747767 optionsOrTest ?: number | TestOptions | TestFunction ,
748768 ) {
749- getCurrentSuite ( ) . test . fn . call (
769+ const collector = getCurrentSuite ( )
770+ const scopedFixtures = collector . fixtures ( )
771+ if ( scopedFixtures ) {
772+ this . fixtures = mergeScopedFixtures (
773+ this . fixtures || [ ] ,
774+ scopedFixtures ,
775+ )
776+ }
777+ collector . test . fn . call (
750778 this ,
751779 formatName ( name ) ,
752780 optionsOrFn as TestOptions ,
0 commit comments