-
-
Notifications
You must be signed in to change notification settings - Fork 737
/
Copy pathinterface_test.js
199 lines (167 loc) · 7.18 KB
/
interface_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
const { expect } = require('expect');
const path = require('path');
const exec = require('child_process').exec;
const runner = path.join(__dirname, '/../../bin/codecept.js');
const codecept_dir = path.join(__dirname, '/../data/sandbox');
const codecept_run = `${runner} run`;
const config_run_config = config => `${codecept_run} --config ${codecept_dir}/${config}`;
describe('CodeceptJS Interface', () => {
before(() => {
process.chdir(codecept_dir);
});
it('should rerun flaky tests', (done) => {
exec(config_run_config('codecept.flaky.js'), (err, stdout) => {
expect(stdout).toContain('Flaky'); // feature
expect(stdout).toContain('Not so flaky test'); // test name
expect(stdout).toContain('Old style flaky'); // test name
expect(stdout).toContain('[T1] Retries: 2'); // test name
expect(stdout).toContain('[T2] Retries: 4'); // test name
expect(stdout).toContain('[T3] Retries: 1'); // test name
expect(err).toBeFalsy();
done();
});
});
it('should rerun retried steps', (done) => {
exec(`${config_run_config('codecept.retry.json')} --grep @test1`, (err, stdout) => {
expect(stdout).toContain('Retry'); // feature
expect(stdout).toContain('Retries: 4'); // test name
expect(err).toBeFalsy();
done();
});
});
it('should not propagate retries to non retried steps', (done) => {
exec(`${config_run_config('codecept.retry.json')} --grep @test2 --verbose`, (err, stdout) => {
expect(stdout).toContain('Retry'); // feature
expect(stdout).toContain('Retries: 1'); // test name
done();
});
});
it('should use retryFailedStep plugin for failed steps', (done) => {
exec(`${config_run_config('codecept.retryFailed.json')} --grep @test1`, (err, stdout) => {
expect(stdout).toContain('Retry'); // feature
expect(stdout).toContain('Retries: 5'); // test name
expect(err).toBeFalsy();
done();
});
});
it('should not retry wait* steps in retryFailedStep plugin', (done) => {
exec(`${config_run_config('codecept.retryFailed.json')} --grep @test2`, (err, stdout) => {
expect(stdout).toContain('Retry'); // feature
expect(stdout).not.toContain('Retries: 5');
expect(stdout).toContain('Retries: 1');
expect(err).toBeTruthy();
done();
});
});
it('should not retry steps if retryFailedStep plugin disabled', (done) => {
exec(`${config_run_config('codecept.retryFailed.json')} --grep @test3`, (err, stdout) => {
expect(stdout).toContain('Retry'); // feature
expect(stdout).not.toContain('Retries: 5');
expect(stdout).toContain('Retries: 1');
expect(err).toBeTruthy();
done();
});
});
it('should include grep option tests', (done) => {
exec(config_run_config('codecept.grep.js'), (err, stdout) => {
expect(stdout).toContain('Got login davert and password'); // feature
expect(stdout).not.toContain('Got changed login'); // test name
expect(err).toBeFalsy();
done();
});
});
it('should run tests with different data', (done) => {
exec(config_run_config('codecept.ddt.js'), (err, stdout) => {
const output = stdout.replace(/in [0-9]ms/g, '').replace(/\r/g, '');
expect(output).toContain(`Got login davert and password 123456
✔ Should log accounts1 | {"login":"davert","password":"123456"}`);
expect(output).toContain(`Got login admin and password 666666
✔ Should log accounts1 | {"login":"admin","password":"666666"}`);
expect(output).toContain(`Got changed login andrey and password 555555
✔ Should log accounts2 | {"login":"andrey","password":"555555"}`);
expect(output).toContain(`Got changed login collaborator and password 222222
✔ Should log accounts2 | {"login":"collaborator","password":"222222"}`);
expect(output).toContain(`Got changed login nick
✔ Should log accounts3 | ["nick","pick"]`);
expect(output).toContain(`Got changed login jack
✔ Should log accounts3 | ["jack","sacj"]`);
expect(output).toContain(`Got generator login nick
✔ Should log accounts4 | {"user":"nick"}`);
expect(output).toContain(`Got generator login pick
✔ Should log accounts4 | {"user":"pick"}`);
expect(output).toContain(`Got array item 1
✔ Should log array of strings | {"1"}`);
expect(output).toContain(`Got array item 2
✔ Should log array of strings | {"2"}`);
expect(output).toContain(`Got array item 3
✔ Should log array of strings | {"3"}`);
expect(err).toBeFalsy();
done();
});
});
it('should run all tests with data of array by only', (done) => {
exec(config_run_config('codecept.addt.js'), (err, stdout) => {
const output = stdout.replace(/in [0-9]ms/g, '').replace(/\r/g, '');
expect(output).toContain('Got array item 1');
expect(output).toContain('Should log array of strings | {"1"}');
expect(output).toContain('Got array item 2');
expect(output).toContain('Should log array of strings | {"2"}');
expect(output).toContain('Got array item 3');
expect(output).toContain('Should log array of strings | {"3"}');
expect(err).toBeFalsy();
done();
});
});
it('should run all tests with data of generator by only', (done) => {
exec(config_run_config('codecept.gddt.js'), (err, stdout) => {
const output = stdout.replace(/in [0-9]ms/g, '').replace(/\r/g, '');
expect(output).toContain(`Got generator login nick
✔ Should log generator of strings | {"user":"nick"}`);
expect(output).toContain(`Got generator login pick
✔ Should log generator of strings | {"user":"pick"}`);
expect(err).toBeFalsy();
done();
});
});
it('should provide skipped test for each entry of data', (done) => {
exec(config_run_config('codecept.skip_ddt.json'), (err, stdout) => {
const output = stdout.replace(/in [0-9]ms/g, '').replace(/\r/g, '');
expect(output).toContain('S Should add skip entry for each item | {"user":"bob"}');
expect(output).toContain('S Should add skip entry for each item | {"user":"anne"}');
expect(output).toContain('OK');
expect(output).toContain('0 passed');
expect(output).toContain('2 skipped');
expect(err).toBeFalsy();
done();
});
});
it('should execute expected promise chain', (done) => {
exec(`${codecept_run} --debug`, (err, stdout) => {
const lines = stdout.match(/\S.+/g);
// before hooks
const beforeStep = [
'I am in path "."',
];
lines.filter(l => beforeStep.indexOf(l) > -1)
.should.eql(beforeStep, 'check step hooks execution order');
// steps order
const step = [
'I am in path "."',
'hello world',
'I see file "codecept.js"',
];
lines.filter(l => step.indexOf(l) > -1)
.should.eql(step, 'check steps execution order');
expect(err).toBeFalsy();
done();
});
});
it('should display steps and artifacts & error log', (done) => {
exec(`${config_run_config('./configs/testArtifacts')} --debug`, (err, stdout) => {
stdout.should.include('Scenario Steps:');
stdout.should.include('Artifacts');
stdout.should.include('- screenshot: [ SCREEENSHOT FILE ]');
done();
});
});
});