@@ -31,11 +31,21 @@ class StepDefinitionRegistry {
3131 this . options . parameterTypeRegistry
3232 ) ;
3333 }
34- this . definitions . push ( { implementation, expression } ) ;
34+
35+ this . definitions . push ( {
36+ implementation,
37+ expression,
38+ featureName : window . currentFeatureName || "___GLOBAL_EXECUTION___"
39+ } ) ;
3540 } ;
3641
37- this . resolve = ( type , text ) =>
38- this . definitions . filter ( ( { expression } ) => expression . match ( text ) ) [ 0 ] ;
42+ this . resolve = ( type , text , runningFeatureName ) =>
43+ this . definitions . filter (
44+ ( { expression, featureName } ) =>
45+ expression . match ( text ) &&
46+ ( runningFeatureName === featureName ||
47+ featureName === "___GLOBAL_EXECUTION___" )
48+ ) [ 0 ] ;
3949 }
4050}
4151
@@ -45,15 +55,21 @@ class HookRegistry {
4555 this . runtime = { } ;
4656
4757 this . runtime = ( tags , implementation ) => {
48- this . definitions . push ( { tags, implementation } ) ;
58+ this . definitions . push ( {
59+ tags,
60+ implementation,
61+ featureName : window . currentFeatureName || "___GLOBAL_EXECUTION___"
62+ } ) ;
4963 } ;
5064
51- this . resolve = scenarioTags =>
65+ this . resolve = ( scenarioTags , runningFeatureName ) =>
5266 this . definitions . filter (
53- ( { tags } ) =>
54- ! tags ||
55- tags . length === 0 ||
56- shouldProceedCurrentStep ( scenarioTags , tags )
67+ ( { tags, featureName } ) =>
68+ ( ! tags ||
69+ tags . length === 0 ||
70+ shouldProceedCurrentStep ( scenarioTags , tags ) ) &&
71+ ( runningFeatureName === featureName ||
72+ featureName === "___GLOBAL_EXECUTION___" )
5773 ) ;
5874 }
5975}
@@ -62,10 +78,11 @@ const stepDefinitionRegistry = new StepDefinitionRegistry();
6278const beforeHookRegistry = new HookRegistry ( ) ;
6379const afterHookRegistry = new HookRegistry ( ) ;
6480
65- function resolveStepDefinition ( step ) {
81+ function resolveStepDefinition ( step , featureName ) {
6682 const stepDefinition = stepDefinitionRegistry . resolve (
6783 step . keyword . toLowerCase ( ) . trim ( ) ,
68- step . text
84+ step . text ,
85+ featureName
6986 ) ;
7087 return stepDefinition || { } ;
7188}
@@ -126,9 +143,9 @@ function resolveStepArgument(argument, exampleRowData, replaceParameterTags) {
126143 return argument ;
127144}
128145
129- function resolveAndRunHooks ( hookRegistry , scenarioTags ) {
146+ function resolveAndRunHooks ( hookRegistry , scenarioTags , featureName ) {
130147 return window . Cypress . Promise . each (
131- hookRegistry . resolve ( scenarioTags ) ,
148+ hookRegistry . resolve ( scenarioTags , featureName ) ,
132149 ( { implementation } ) => implementation . call ( this )
133150 ) ;
134151}
@@ -161,15 +178,23 @@ function parseHookArgs(args) {
161178}
162179
163180module . exports = {
164- resolveAndRunBeforeHooks ( scenarioTags ) {
165- return resolveAndRunHooks ( beforeHookRegistry , scenarioTags ) ;
181+ resolveAndRunBeforeHooks ( scenarioTags , featureName ) {
182+ return resolveAndRunHooks ( beforeHookRegistry , scenarioTags , featureName ) ;
166183 } ,
167- resolveAndRunAfterHooks ( scenarioTags ) {
168- return resolveAndRunHooks ( afterHookRegistry , scenarioTags ) ;
184+ resolveAndRunAfterHooks ( scenarioTags , featureName ) {
185+ return resolveAndRunHooks ( afterHookRegistry , scenarioTags , featureName ) ;
169186 } ,
170187 // eslint-disable-next-line func-names
171- resolveAndRunStepDefinition ( step , replaceParameterTags , exampleRowData ) {
172- const { expression, implementation } = resolveStepDefinition ( step ) ;
188+ resolveAndRunStepDefinition (
189+ step ,
190+ replaceParameterTags ,
191+ exampleRowData ,
192+ featureName
193+ ) {
194+ const { expression, implementation } = resolveStepDefinition (
195+ step ,
196+ featureName
197+ ) ;
173198 const stepText = step . text ;
174199 if ( expression && implementation ) {
175200 const argument = resolveStepArgument (
0 commit comments