@@ -4,7 +4,7 @@ const mkdirp = require('mkdirp');
44const  output  =  require ( '../../output' ) ; 
55const  {  fileExists }  =  require ( '../../utils' ) ; 
66const  { 
7-   getConfig,  getTestRoot,  updateConfig,  safeFileWrite, 
7+   getConfig,  getTestRoot,  updateConfig,  safeFileWrite,  findConfigFile , 
88}  =  require ( '../utils' ) ; 
99
1010const  featureFile  =  `Feature: Business rules 
@@ -26,7 +26,17 @@ Given('I have a defined step', () => {
2626
2727module . exports  =  function  ( genPath )  { 
2828  const  testsPath  =  getTestRoot ( genPath ) ; 
29+   const  configFile  =  findConfigFile ( testsPath ) ; 
30+ 
31+   if  ( ! configFile )  { 
32+     output . error ( 
33+       "Can't initialize Gherkin. This command must be run in an already initialized project." 
34+     ) ; 
35+     process . exit ( 1 ) ; 
36+   } 
37+ 
2938  const  config  =  getConfig ( testsPath ) ; 
39+   const  extension  =  path . extname ( configFile ) . substring ( 1 ) ; 
3040
3141  output . print ( 'Initializing Gherkin (Cucumber BDD) for CodeceptJS' ) ; 
3242  output . print ( '--------------------------' ) ; 
@@ -53,18 +63,18 @@ module.exports = function (genPath) {
5363    output . success ( `Created ${ dir }  ) ; 
5464  } 
5565
56-   if  ( safeFileWrite ( path . join ( dir ,  'steps.js' ) ,  stepsFile ) )  { 
57-     output . success ( 'Created sample steps file: step_definitions/steps.js' ) ; 
66+   if  ( safeFileWrite ( path . join ( dir ,  `steps.${ extension }  ) ,  stepsFile ) )  { 
67+     output . success ( 
68+       `Created sample steps file: step_definitions/steps.${ extension }  
69+     ) ; 
5870  } 
5971
6072  config . gherkin  =  { 
61-     features : './features/*.feature' , 
62-     steps : [ 
63-       './step_definitions/steps.js' , 
64-     ] , 
73+     features : "./features/*.feature" , 
74+     steps : [ `./step_definitions/steps.${ extension }  ] , 
6575  } ; 
6676
67-   updateConfig ( testsPath ,  config ) ; 
77+   updateConfig ( testsPath ,  config ,   extension ) ; 
6878
6979  output . success ( 'Gherkin setup is done.' ) ; 
7080  output . success ( 'Start writing feature files and implement corresponding steps.' ) ; 
0 commit comments