@@ -33,8 +33,8 @@ import {
33
33
runWithSuite ,
34
34
withTimeout ,
35
35
} 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'
38
38
import { getCurrentTest } from './test-state'
39
39
import { createChainable } from './utils/chain'
40
40
@@ -340,7 +340,7 @@ function createSuiteCollector(
340
340
value : context ,
341
341
enumerable : false ,
342
342
} )
343
- setFixture ( context , options . fixtures )
343
+ setTestFixture ( context , options . fixtures )
344
344
345
345
if ( handler ) {
346
346
setFn (
@@ -395,6 +395,8 @@ function createSuiteCollector(
395
395
test . type = 'test'
396
396
} )
397
397
398
+ let collectorFixtures : FixtureItem [ ] | undefined
399
+
398
400
const collector : SuiteCollector = {
399
401
type : 'collector' ,
400
402
name,
@@ -407,6 +409,19 @@ function createSuiteCollector(
407
409
task,
408
410
clear,
409
411
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
+ } ,
410
425
}
411
426
412
427
function addHook < T extends keyof SuiteHooks > ( name : T , ...fn : SuiteHooks [ T ] ) {
@@ -734,6 +749,11 @@ export function createTaskCollector(
734
749
return condition ? this : this . skip
735
750
}
736
751
752
+ taskFn . scoped = function ( fixtures : Fixtures < Record < string , any > > ) {
753
+ const collector = getCurrentSuite ( )
754
+ collector . scoped ( fixtures )
755
+ }
756
+
737
757
taskFn . extend = function ( fixtures : Fixtures < Record < string , any > > ) {
738
758
const _context = mergeContextFixtures (
739
759
fixtures ,
@@ -746,7 +766,15 @@ export function createTaskCollector(
746
766
optionsOrFn ?: TestOptions | TestFunction ,
747
767
optionsOrTest ?: number | TestOptions | TestFunction ,
748
768
) {
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 (
750
778
this ,
751
779
formatName ( name ) ,
752
780
optionsOrFn as TestOptions ,
0 commit comments