forked from codeceptjs/CodeceptJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgherkin_test.js
93 lines (85 loc) · 2.92 KB
/
gherkin_test.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
82
83
84
85
86
87
88
89
90
91
92
93
const assert = require("assert");
const path = require("path");
const fs = require("fs");
const exec = require("child_process").exec;
const runner = path.join(__dirname, "/../../bin/codecept.js");
const codecept_dir = path.join(__dirname, "/../data/sandbox/configs/gherkin/");
describe("gherkin bdd commands", () => {
describe("bdd:init", () => {
let codecept_dir_js = path.join(codecept_dir, "config_js");
let codecept_dir_ts = path.join(codecept_dir, "config_ts");
beforeEach(() => {
fs.copyFileSync(
path.join(codecept_dir_js, "codecept.conf.init.js"),
path.join(codecept_dir_js, "codecept.conf.js")
);
fs.copyFileSync(
path.join(codecept_dir_ts, "codecept.conf.init.ts"),
path.join(codecept_dir_ts, "codecept.conf.ts")
);
});
afterEach(() => {
try {
fs.rmSync(path.join(codecept_dir_js, "codecept.conf.js"));
fs.rmSync(path.join(codecept_dir_js, "features"), {
recursive: true,
});
fs.rmSync(path.join(codecept_dir_js, "step_definitions"), {
recursive: true,
});
} catch (e) {}
try {
fs.rmSync(path.join(codecept_dir_ts, "codecept.conf.ts"));
fs.rmSync(path.join(codecept_dir_ts, "features"), {
recursive: true,
});
fs.rmSync(path.join(codecept_dir_ts, "step_definitions"), {
recursive: true,
});
} catch (e) {}
});
[
{
codecept_dir_test: codecept_dir_js,
extension: "js",
},
{
codecept_dir_test: codecept_dir_ts,
extension: "ts",
},
].forEach(({ codecept_dir_test, extension }) => {
it(`prepare CodeceptJS to run feature files (codecept.conf.${extension})`, (done) => {
exec(`${runner} gherkin:init ${codecept_dir_test}`, (err, stdout) => {
let dir = path.join(codecept_dir_test, "features");
stdout.should.include(
"Initializing Gherkin (Cucumber BDD) for CodeceptJS"
);
stdout.should.include(
`Created ${dir}, place your *.feature files in it`
);
stdout.should.include(
"Created sample feature file: features/basic.feature"
);
dir = path.join(codecept_dir_test, "step_definitions");
stdout.should.include(
`Created ${dir}, place step definitions into it`
);
stdout.should.include(
`Created sample steps file: step_definitions/steps.${extension}`
);
assert(!err);
const configResult = fs
.readFileSync(
path.join(codecept_dir_test, `codecept.conf.${extension}`)
)
.toString();
configResult.should.contain(`features: './features/*.feature'`);
configResult.should.contain(
`steps: ['./step_definitions/steps.${extension}']`
);
done();
});
});
});
});
});