@@ -34,7 +34,6 @@ import {
3434 HOOK_FAILURE_EXPR ,
3535 INTERNAL_SPEC_PROPERTIES ,
3636 INTERNAL_SUITE_PROPERTIES ,
37- TEST_ISOLATION_CONFIGURATION_OPTION ,
3837} from "./constants" ;
3938
4039import {
@@ -66,6 +65,12 @@ import { getTags } from "./helpers/environment";
6665
6766import { ICaseHookParameter , IStepHookParameter } from "./public-member-types" ;
6867
68+ import {
69+ isExclusivelySuiteConfiguration ,
70+ isNotExclusivelySuiteConfiguration ,
71+ tagsToOptions ,
72+ } from "./helpers/options" ;
73+
6974type Node = ReturnType < typeof parse > ;
7075
7176type TestStepIds = Map < string , Map < string , string > > ;
@@ -288,13 +293,7 @@ function createStepDescription({
288293
289294function createFeature ( context : CompositionContext , feature : messages . Feature ) {
290295 const suiteOptions = Object . fromEntries (
291- collectTagNames ( feature . tags )
292- . filter ( looksLikeOptions )
293- . map ( tagToCypressOptions )
294- . filter (
295- ( [ property ] ) =>
296- property === ( TEST_ISOLATION_CONFIGURATION_OPTION as string )
297- )
296+ tagsToOptions ( feature . tags ) . filter ( isExclusivelySuiteConfiguration )
298297 ) as Cypress . TestConfigOverrides ;
299298
300299 describe ( feature . name || "<unamed feature>" , suiteOptions , ( ) => {
@@ -358,13 +357,7 @@ function createRule(context: CompositionContext, rule: messages.Rule) {
358357 }
359358
360359 const suiteOptions = Object . fromEntries (
361- collectTagNames ( rule . tags )
362- . filter ( looksLikeOptions )
363- . map ( tagToCypressOptions )
364- . filter (
365- ( [ property ] ) =>
366- property === ( TEST_ISOLATION_CONFIGURATION_OPTION as string )
367- )
360+ tagsToOptions ( rule . tags ) . filter ( isExclusivelySuiteConfiguration )
368361 ) as Cypress . TestConfigOverrides ;
369362
370363 describe ( rule . name || "<unamed rule>" , suiteOptions , ( ) => {
@@ -458,51 +451,33 @@ function createPickle(context: CompositionContext, pickle: messages.Pickle) {
458451 "Expected a scenario to have a examples property"
459452 ) ;
460453
461- const tagsDefinedOnThisScenarioTagNameAstIdMap = scenario . tags . reduce (
462- ( acc , tag ) => {
463- acc [ tag . name ] = tag . id ;
464- return acc ;
465- } ,
466- { } as Record < string , string >
467- ) ;
468-
469- for ( const example of scenario . examples ) {
470- example . tags . forEach ( ( tag ) => {
471- tagsDefinedOnThisScenarioTagNameAstIdMap [ tag . name ] = tag . id ;
472- } ) ;
473- }
454+ const testSpecificOptions = tagsToOptions ( [
455+ ...scenario . tags ,
456+ ...scenario . examples . flatMap ( ( example ) => example . tags ) ,
457+ ] ) ;
474458
475- for ( const tag of pickle . tags ) {
476- if (
477- looksLikeOptions ( tag . name ) &&
478- tagsDefinedOnThisScenarioTagNameAstIdMap [ tag . name ] === tag . astNodeId &&
479- Object . keys ( tagToCypressOptions ( tag . name ) ) . every (
480- ( key ) => key === TEST_ISOLATION_CONFIGURATION_OPTION
481- )
482- ) {
459+ for ( const entry of testSpecificOptions ) {
460+ if ( isExclusivelySuiteConfiguration ( entry ) ) {
483461 throw new Error (
484- `Tag ${ tag . name } can only be used on a Feature or a Rule`
462+ `Tag ${ entry [ 0 ] } can only be used on a Feature or a Rule`
485463 ) ;
486464 }
487465 }
488466
489- const suiteOptions = Object . fromEntries (
467+ const inheritedTestOptions = Object . fromEntries (
490468 tags
491469 . filter ( looksLikeOptions )
492470 . map ( tagToCypressOptions )
493- . filter (
494- ( [ property ] ) =>
495- property !== ( TEST_ISOLATION_CONFIGURATION_OPTION as string )
496- )
471+ . filter ( isNotExclusivelySuiteConfiguration )
497472 ) as Cypress . TestConfigOverrides ;
498473
499- if ( suiteOptions . env ) {
500- Object . assign ( suiteOptions . env , internalEnv ) ;
474+ if ( inheritedTestOptions . env ) {
475+ Object . assign ( inheritedTestOptions . env , internalEnv ) ;
501476 } else {
502- suiteOptions . env = internalEnv ;
477+ inheritedTestOptions . env = internalEnv ;
503478 }
504479
505- it ( scenarioName , suiteOptions , function ( ) {
480+ it ( scenarioName , inheritedTestOptions , function ( ) {
506481 const { remainingSteps, testCaseStartedId } =
507482 retrieveInternalSpecProperties ( ) ;
508483
0 commit comments