-
-
Notifications
You must be signed in to change notification settings - Fork 736
/
Copy pathinit.js
81 lines (64 loc) · 2.23 KB
/
init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const path = require('path');
const mkdirp = require('mkdirp');
const output = require('../../output');
const { fileExists } = require('../../utils');
const {
getConfig, getTestRoot, updateConfig, safeFileWrite, findConfigFile,
} = require('../utils');
const featureFile = `Feature: Business rules
In order to achieve my goals
As a persona
I want to be able to interact with a system
Scenario: do something
Given I have a defined step
`;
const stepsFile = `const { I } = inject();
// Add in your custom step files
Given('I have a defined step', () => {
// TODO: replace with your own step
});
`;
module.exports = function (genPath) {
const testsPath = getTestRoot(genPath);
const configFile = findConfigFile(testsPath);
if (!configFile) {
output.error(
"Can't initialize Gherkin. This command must be run in an already initialized project.",
);
process.exit(1);
}
const config = getConfig(testsPath);
const extension = path.extname(configFile).substring(1);
output.print('Initializing Gherkin (Cucumber BDD) for CodeceptJS');
output.print('--------------------------');
if (config.gherkin && config.gherkin.steps) {
output.error('Gherkin is already initialized in this project. See `gherkin` section in the config');
process.exit(1);
}
let dir;
dir = path.join(testsPath, 'features');
if (!fileExists(dir)) {
mkdirp.sync(dir);
output.success(`Created ${dir}, place your *.feature files in it`);
}
if (safeFileWrite(path.join(dir, 'basic.feature'), featureFile)) {
output.success('Created sample feature file: features/basic.feature');
}
dir = path.join(testsPath, 'step_definitions');
if (!fileExists(dir)) {
mkdirp.sync(dir);
output.success(`Created ${dir}, place step definitions into it`);
}
if (safeFileWrite(path.join(dir, `steps.${extension}`), stepsFile)) {
output.success(
`Created sample steps file: step_definitions/steps.${extension}`,
);
}
config.gherkin = {
features: './features/*.feature',
steps: [`./step_definitions/steps.${extension}`],
};
updateConfig(testsPath, config, extension);
output.success('Gherkin setup is done.');
output.success('Start writing feature files and implement corresponding steps.');
};