@@ -4,7 +4,7 @@ const mkdirp = require('mkdirp');
4
4
const output = require ( '../../output' ) ;
5
5
const { fileExists } = require ( '../../utils' ) ;
6
6
const {
7
- getConfig, getTestRoot, updateConfig, safeFileWrite,
7
+ getConfig, getTestRoot, updateConfig, safeFileWrite, findConfigFile ,
8
8
} = require ( '../utils' ) ;
9
9
10
10
const featureFile = `Feature: Business rules
@@ -26,7 +26,17 @@ Given('I have a defined step', () => {
26
26
27
27
module . exports = function ( genPath ) {
28
28
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
+
29
38
const config = getConfig ( testsPath ) ;
39
+ const extension = path . extname ( configFile ) . substring ( 1 ) ;
30
40
31
41
output . print ( 'Initializing Gherkin (Cucumber BDD) for CodeceptJS' ) ;
32
42
output . print ( '--------------------------' ) ;
@@ -53,18 +63,18 @@ module.exports = function (genPath) {
53
63
output . success ( `Created ${ dir } , place step definitions into it` ) ;
54
64
}
55
65
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
+ ) ;
58
70
}
59
71
60
72
config . gherkin = {
61
- features : './features/*.feature' ,
62
- steps : [
63
- './step_definitions/steps.js' ,
64
- ] ,
73
+ features : "./features/*.feature" ,
74
+ steps : [ `./step_definitions/steps.${ extension } ` ] ,
65
75
} ;
66
76
67
- updateConfig ( testsPath , config ) ;
77
+ updateConfig ( testsPath , config , extension ) ;
68
78
69
79
output . success ( 'Gherkin setup is done.' ) ;
70
80
output . success ( 'Start writing feature files and implement corresponding steps.' ) ;
0 commit comments