@@ -6,58 +6,37 @@ const createTestsFromFeature = (filePath, spec) => {
66 const testState = new CucumberDataCollector ( filePath , spec ) ;
77 const featureTags = testState . feature . tags ;
88 const hasEnvTags = ! ! getEnvTags ( ) ;
9- const sectionsWithTags = testState . feature . children . filter (
10- section => section . tags && section . tags . length
9+ const anyFocused =
10+ testState . feature . children . filter (
11+ section => section . tags && section . tags . find ( t => t . name === "@focus" )
12+ ) . length > 0 ;
13+ const backgroundSection = testState . feature . children . find (
14+ section => section . type === "Background"
15+ ) ;
16+ const allScenarios = testState . feature . children . filter (
17+ section => section . type !== "Background"
1118 ) ;
1219
13- const sectionsWithTagsExist = sectionsWithTags . length > 0 ;
14-
15- let everythingShouldRun = false ;
16- let featureShouldRun = false ;
17- let taggedScenarioShouldRun = false ;
18- let anyFocused = false ;
19- if ( hasEnvTags ) {
20- featureShouldRun = shouldProceedCurrentStep ( featureTags ) ;
21- taggedScenarioShouldRun = testState . feature . children . some (
22- section =>
23- section . tags &&
24- section . tags . length &&
25- shouldProceedCurrentStep ( section . tags . concat ( featureTags ) )
26- ) ;
27- } else if ( ! sectionsWithTagsExist ) {
28- everythingShouldRun = true ;
29- } else {
30- anyFocused = sectionsWithTags . some ( section =>
31- section . tags . find ( t => t . name === "@focus" )
32- ) ;
33- if ( anyFocused ) {
34- taggedScenarioShouldRun = true ;
20+ const scenariosToRun = allScenarios . filter ( section => {
21+ let shouldRun ;
22+ // only just run focused if no env tags set
23+ // https://github.com/TheBrainFamily/cypress-cucumber-example#smart-tagging
24+ if ( ! hasEnvTags && anyFocused ) {
25+ shouldRun = section . tags . find ( t => t . name === "@focus" ) ;
3526 } else {
36- everythingShouldRun = true ;
27+ shouldRun =
28+ ! hasEnvTags ||
29+ shouldProceedCurrentStep ( section . tags . concat ( featureTags ) ) ; // Concat handles inheritance of tags from feature
3730 }
38- }
39-
40- // eslint-disable-next-line prefer-arrow-callback
41- if ( everythingShouldRun || featureShouldRun || taggedScenarioShouldRun ) {
42- const backgroundSection = testState . feature . children . find (
43- section => section . type === "Background"
44- ) ;
45- const otherSections = testState . feature . children . filter (
46- section => section . type !== "Background"
47- ) ;
48- const scenariosToRun = otherSections . filter ( section => {
49- let shouldRun ;
50- if ( anyFocused ) {
51- shouldRun = section . tags . find ( t => t . name === "@focus" ) ;
52- } else {
53- shouldRun =
54- everythingShouldRun ||
55- shouldProceedCurrentStep ( section . tags . concat ( featureTags ) ) ; // Concat handles inheritance of tags from feature
56- }
57- return shouldRun ;
58- } ) ;
59- createTestFromScenarios ( scenariosToRun , backgroundSection , testState ) ;
60- }
31+ return shouldRun ;
32+ } ) ;
33+ // create tests for all the scenarios
34+ // but flag only the ones that should be run
35+ scenariosToRun . forEach ( section => {
36+ // eslint-disable-next-line no-param-reassign
37+ section . shouldRun = true ;
38+ } ) ;
39+ createTestFromScenarios ( allScenarios , backgroundSection , testState ) ;
6140} ;
6241
6342module . exports = {
0 commit comments