@@ -7,22 +7,32 @@ const log = require("debug")("cypress:cucumber");
77const { getStepDefinitionsPaths } = require ( "./getStepDefinitionsPaths" ) ;
88const { cucumberTemplate } = require ( "./cucumberTemplate" ) ;
99const { getCucumberJsonConfig } = require ( "./getCucumberJsonConfig" ) ;
10+ const {
11+ isNonGlobalStepDefinitionsMode
12+ } = require ( "./isNonGlobalStepDefinitionsMode" ) ;
1013
11- // This is the template for the file that we will send back to cypress instead of the text of a
12- // feature file
13- const createCucumber = ( specs , toRequire , cucumberJson ) =>
14+ const createCucumber = (
15+ specs ,
16+ globalToRequire ,
17+ nonGlobalToRequire ,
18+ cucumberJson
19+ ) =>
1420 `
1521 ${ cucumberTemplate }
1622
1723 window.cucumberJson = ${ JSON . stringify ( cucumberJson ) } ;
1824
19- ${ toRequire . join ( "\n" ) }
25+ ${ globalToRequire . join ( "\n" ) }
2026
2127 ${ specs
2228 . map (
23- ( { spec, filePath, name } ) =>
24- `
29+ ( { spec, filePath, name } ) => `
2530 describe(\`${ name } \`, function() {
31+ ${ nonGlobalToRequire &&
32+ nonGlobalToRequire
33+ . find ( fileSteps => fileSteps [ filePath ] )
34+ [ filePath ] . join ( "\n" ) }
35+
2636 createTestsFromFeature('${ filePath } ', \`${ spec } \`);
2737 })
2838 `
@@ -35,24 +45,35 @@ module.exports = function(_, filePath) {
3545
3646 const features = glob . sync ( `${ path . dirname ( filePath ) } /**/*.feature` ) ;
3747
38- const stepDefinitionsToRequire = [
39- ...new Set (
40- features . reduce (
41- requires =>
42- requires . concat (
43- getStepDefinitionsPaths ( filePath ) . map (
44- sdPath => `require('${ sdPath } ')`
45- )
46- ) ,
47- [ ]
48+ let globalStepDefinitionsToRequire = [ ] ;
49+ let nonGlobalStepDefinitionsToRequire ;
50+
51+ if ( isNonGlobalStepDefinitionsMode ( ) ) {
52+ nonGlobalStepDefinitionsToRequire = features . map ( featurePath => ( {
53+ [ featurePath ] : getStepDefinitionsPaths ( featurePath ) . map (
54+ sdPath => `require('${ sdPath } ')`
4855 )
49- )
50- ] ;
56+ } ) ) ;
57+ } else {
58+ globalStepDefinitionsToRequire = [
59+ ...new Set (
60+ features . reduce (
61+ requires =>
62+ requires . concat (
63+ getStepDefinitionsPaths ( filePath ) . map (
64+ sdPath => `require('${ sdPath } ')`
65+ )
66+ ) ,
67+ [ ]
68+ )
69+ )
70+ ] ;
71+ }
5172
5273 const specs = features
5374 . map ( featurePath => ( {
5475 spec : fs . readFileSync ( featurePath ) . toString ( ) ,
55- filePath : path . basename ( featurePath )
76+ filePath : featurePath
5677 } ) )
5778 . map ( feature =>
5879 Object . assign ( { } , feature , {
@@ -62,7 +83,8 @@ module.exports = function(_, filePath) {
6283
6384 return createCucumber (
6485 specs ,
65- stepDefinitionsToRequire ,
86+ globalStepDefinitionsToRequire ,
87+ nonGlobalStepDefinitionsToRequire ,
6688 getCucumberJsonConfig ( )
6789 ) ;
6890} ;
0 commit comments