@@ -3,6 +3,7 @@ import { expect } from 'chai';
3
3
import path , { dirname } from 'path' ;
4
4
import { exec } from 'child_process' ;
5
5
import { fileURLToPath } from 'url' ;
6
+ import { stripAnsi } from '../../lib/utils.js' ;
6
7
7
8
const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
8
9
const runner = path . join ( __dirname , '../../bin/codecept.js' ) ;
@@ -19,7 +20,6 @@ describe('CodeceptJS Multiple Runner', function () {
19
20
20
21
it ( 'should execute one suite with browser' , ( done ) => {
21
22
exec ( `${ codecept_run } default:firefox` , ( err , stdout ) => {
22
- console . log ( stdout )
23
23
expect ( stdout ) . to . include ( 'CodeceptJS' ) ; // feature
24
24
expect ( stdout ) . to . include ( '.default:firefox]' ) ;
25
25
expect ( stdout ) . to . not . include ( '.default:chrome]' ) ;
@@ -30,25 +30,28 @@ describe('CodeceptJS Multiple Runner', function () {
30
30
31
31
it ( 'should execute all suites' , ( done ) => {
32
32
exec ( `${ codecept_run } --all` , ( err , stdout ) => {
33
+ stdout = stripAnsi ( stdout ) ;
33
34
expect ( stdout ) . to . include ( 'CodeceptJS' ) ; // feature
34
- expect ( stdout ) . to . include ( '[1.default:chrome]' ) ;
35
- expect ( stdout ) . to . include ( '[2.default:firefox]' ) ;
36
- expect ( stdout ) . to . include ( '[3.mobile:android]' ) ;
37
- expect ( stdout ) . to . include ( '[4.mobile:safari]' ) ;
38
- expect ( stdout ) . to . include ( '[5.mobile:chrome]' ) ;
39
- expect ( stdout ) . to . include ( '[6.mobile:safari]' ) ;
40
- expect ( stdout ) . to . include ( '[7.grep:chrome]' ) ;
41
- expect ( stdout ) . to . include ( '[8.grep:firefox]' ) ;
42
- expect ( stdout ) . to . include ( '[7.grep:chrome]' ) ;
43
- expect ( stdout ) . to . include ( '[1.default:chrome]' ) ;
44
- expect ( stdout ) . to . include ( '[3.mobile:android]' ) ;
35
+ expect ( stdout ) . to . include ( '[1.default:chrome] print browser ' ) ;
36
+ expect ( stdout ) . to . include ( '[2.default:firefox] print browser ' ) ;
37
+ expect ( stdout ) . to . include ( '[3.mobile:android] print browser ' ) ;
38
+ expect ( stdout ) . to . include ( '[4.mobile:safari] print browser ' ) ;
39
+ expect ( stdout ) . to . include ( '[5.mobile:chrome] print browser ' ) ;
40
+ expect ( stdout ) . to . include ( '[6.mobile:safari] print browser ' ) ;
41
+ expect ( stdout ) . to . include ( '[7.grep:chrome] @grep print browser size ' ) ;
42
+ expect ( stdout ) . to . include ( '[8.grep:firefox] @grep print browser size ' ) ;
43
+ expect ( stdout ) . to . not . include ( '[7.grep:chrome] print browser ' ) ;
44
+ expect ( stdout ) . to . include ( '[1.default:chrome] @grep print browser size ' ) ;
45
+ expect ( stdout ) . to . include ( '[3.mobile:android] @grep print browser size ' ) ;
45
46
assert ( ! err ) ;
46
47
done ( ) ;
47
48
} ) ;
48
49
} ) ;
49
50
50
51
it ( 'should replace parameters' , ( done ) => {
51
52
exec ( `${ codecept_run } grep --debug` , ( err , stdout ) => {
53
+ stdout = stripAnsi ( stdout ) ;
54
+ console . log ( `${ codecept_run } grep --debug` ) ;
52
55
expect ( stdout ) . to . include ( 'CodeceptJS' ) ; // feature
53
56
expect ( stdout ) . to . include ( '[1.grep:chrome]' ) ;
54
57
expect ( stdout ) . to . include ( '[2.grep:firefox]' ) ;
@@ -59,31 +62,34 @@ describe('CodeceptJS Multiple Runner', function () {
59
62
60
63
it ( 'should execute multiple suites' , ( done ) => {
61
64
exec ( `${ codecept_run } mobile default ` , ( err , stdout ) => {
65
+ stdout = stripAnsi ( stdout ) ;
62
66
expect ( stdout ) . to . include ( 'CodeceptJS' ) ; // feature
63
- expect ( stdout ) . to . include ( '[1.mobile:android]' ) ;
64
- expect ( stdout ) . to . include ( '[2.mobile:safari]' ) ;
65
- expect ( stdout ) . to . include ( '[3.mobile:chrome]' ) ;
66
- expect ( stdout ) . to . include ( '[4.mobile:safari]' ) ;
67
- expect ( stdout ) . to . include ( '[5.default:chrome]' ) ;
68
- expect ( stdout ) . to . include ( '[6.default:firefox]' ) ;
67
+ expect ( stdout ) . to . include ( '[1.mobile:android] print browser ' ) ;
68
+ expect ( stdout ) . to . include ( '[2.mobile:safari] print browser ' ) ;
69
+ expect ( stdout ) . to . include ( '[3.mobile:chrome] print browser ' ) ;
70
+ expect ( stdout ) . to . include ( '[4.mobile:safari] print browser ' ) ;
71
+ expect ( stdout ) . to . include ( '[5.default:chrome] print browser ' ) ;
72
+ expect ( stdout ) . to . include ( '[6.default:firefox] print browser ' ) ;
69
73
assert ( ! err ) ;
70
74
done ( ) ;
71
75
} ) ;
72
76
} ) ;
73
77
74
78
it ( 'should execute multiple suites with selected browsers' , ( done ) => {
75
79
exec ( `${ codecept_run } mobile:safari default:chrome ` , ( err , stdout ) => {
80
+ stdout = stripAnsi ( stdout ) ;
76
81
expect ( stdout ) . to . include ( 'CodeceptJS' ) ; // feature
77
- expect ( stdout ) . to . include ( '[1.mobile:safari]' ) ;
78
- expect ( stdout ) . to . include ( '[2.mobile:safari]' ) ;
79
- expect ( stdout ) . to . include ( '[3.default:chrome]' ) ;
82
+ expect ( stdout ) . to . include ( '[1.mobile:safari] print browser ' ) ;
83
+ expect ( stdout ) . to . include ( '[2.mobile:safari] print browser ' ) ;
84
+ expect ( stdout ) . to . include ( '[3.default:chrome] print browser ' ) ;
80
85
assert ( ! err ) ;
81
86
done ( ) ;
82
87
} ) ;
83
88
} ) ;
84
89
85
90
it ( 'should print steps' , ( done ) => {
86
91
exec ( `${ codecept_run } default --steps` , ( err , stdout ) => {
92
+ stdout = stripAnsi ( stdout ) ;
87
93
expect ( stdout ) . to . include ( 'CodeceptJS' ) ; // feature
88
94
expect ( stdout ) . to . include ( '[2.default:firefox] ' ) ;
89
95
expect ( stdout ) . to . include ( '[2.default:firefox] I' ) ;
@@ -96,42 +102,46 @@ describe('CodeceptJS Multiple Runner', function () {
96
102
97
103
it ( 'should pass grep to configuration' , ( done ) => {
98
104
exec ( `${ codecept_run } default --grep @grep` , ( err , stdout ) => {
105
+ stdout = stripAnsi ( stdout ) ;
99
106
expect ( stdout ) . to . include ( 'CodeceptJS' ) ; // feature
100
- expect ( stdout ) . to . include ( '[1.default:chrome]' ) ;
101
- expect ( stdout ) . to . include ( '[2.default:firefox]' ) ;
102
- expect ( stdout ) . to . not . include ( '[1.default:chrome]' ) ;
103
- expect ( stdout ) . to . not . include ( '[2.default:firefox]' ) ;
107
+ expect ( stdout ) . to . include ( '[1.default:chrome] ✔ print browser size info ' ) ;
108
+ expect ( stdout ) . to . include ( '[2.default:firefox] ✔ print browser size info ' ) ;
109
+ expect ( stdout ) . to . not . include ( '[1.default:chrome] print browser ' ) ;
110
+ expect ( stdout ) . to . not . include ( '[2.default:firefox] print browser ' ) ;
104
111
assert ( ! err ) ;
105
112
done ( ) ;
106
113
} ) ;
107
114
} ) ;
108
115
109
116
it ( 'should pass grep invert to configuration' , ( done ) => {
110
117
exec ( `${ codecept_run } default --grep @grep --invert` , ( err , stdout ) => {
118
+ stdout = stripAnsi ( stdout ) ;
111
119
expect ( stdout ) . to . include ( 'CodeceptJS' ) ; // feature
112
- expect ( stdout ) . to . not . include ( '[1.default:chrome]' ) ;
113
- expect ( stdout ) . to . not . include ( '[2.default:firefox]' ) ;
114
- expect ( stdout ) . to . include ( '[1.default:chrome]' ) ;
115
- expect ( stdout ) . to . include ( '[2.default:firefox]' ) ;
120
+ expect ( stdout ) . to . not . include ( '[1.default:chrome] @grep print browser size ' ) ;
121
+ expect ( stdout ) . to . not . include ( '[2.default:firefox] @grep print browser size ' ) ;
122
+ expect ( stdout ) . to . include ( '[1.default:chrome] print browser ' ) ;
123
+ expect ( stdout ) . to . include ( '[2.default:firefox] print browser ' ) ;
116
124
assert ( ! err ) ;
117
125
done ( ) ;
118
126
} ) ;
119
127
} ) ;
120
128
121
129
it ( 'should pass tests to configuration' , ( done ) => {
122
130
exec ( `${ codecept_run } test` , ( err , stdout ) => {
131
+ stdout = stripAnsi ( stdout ) ;
123
132
expect ( stdout ) . to . include ( 'CodeceptJS' ) ; // feature
124
- expect ( stdout ) . to . include ( '[1.test:chrome]size' ) ;
125
- expect ( stdout ) . to . include ( '[2.test:firefox]size' ) ;
126
- expect ( stdout ) . to . include ( '[1.test:chrome]' ) ;
127
- expect ( stdout ) . to . include ( '[2.test:firefox]' ) ;
133
+ expect ( stdout ) . to . include ( '[1.test:chrome] print browser size' ) ;
134
+ expect ( stdout ) . to . include ( '[2.test:firefox] print browser size' ) ;
135
+ expect ( stdout ) . to . include ( '[1.test:chrome] print browser ' ) ;
136
+ expect ( stdout ) . to . include ( '[2.test:firefox] print browser ' ) ;
128
137
assert ( ! err ) ;
129
138
done ( ) ;
130
139
} ) ;
131
140
} ) ;
132
141
133
142
it ( 'should run chunks' , ( done ) => {
134
143
exec ( `${ codecept_run } chunks` , ( err , stdout ) => {
144
+ stdout = stripAnsi ( stdout ) ;
135
145
expect ( stdout ) . to . include ( 'CodeceptJS' ) ; // feature
136
146
expect ( stdout ) . to . include ( '[1.chunks:chunk1:dummy] print browser' ) ;
137
147
expect ( stdout ) . to . include ( '[2.chunks:chunk2:dummy]' ) ;
@@ -141,34 +151,33 @@ describe('CodeceptJS Multiple Runner', function () {
141
151
} ) ;
142
152
143
153
it ( 'should run features in parallel' , ( done ) => {
144
- process . chdir ( codecept_dir ) ;
145
154
exec ( `${ runner } run-multiple --config codecept.multiple.features.js chunks --features --grep '(?=.*)^(?!.*@fail)'` , ( err , stdout ) => {
155
+ stdout = stripAnsi ( stdout ) ;
146
156
expect ( stdout ) . to . include ( '[1.chunks:chunk1:default] Checkout examples process' ) ;
147
157
expect ( stdout ) . to . not . include ( '[2.chunks:chunk2:default] Checkout examples process' ) ;
148
158
expect ( stdout ) . to . include ( '[2.chunks:chunk2:default] Checkout string' ) ;
149
159
expect ( stdout ) . to . not . include ( '[1.chunks:chunk1:default] Checkout string' ) ;
150
- expect ( stdout ) . to . include ( '[1.chunks:chunk1:default] OK | ' ) ;
151
- expect ( stdout ) . to . include ( '[2.chunks:chunk2:default] OK | ' ) ;
160
+ expect ( stdout ) . to . include ( '[1.chunks:chunk1:default] ✔ checkout ' ) ;
161
+ expect ( stdout ) . to . include ( '[2.chunks:chunk2:default] ✔ order a product with discount ' ) ;
152
162
expect ( stdout ) . to . not . include ( '@feature_grep' ) ;
153
- assert ( ! err ) ;
154
163
done ( ) ;
155
164
} ) ;
156
165
} ) ;
157
166
158
167
it ( 'should run features & tests in parallel' , ( done ) => {
159
- process . chdir ( codecept_dir ) ;
160
168
exec ( `${ runner } run-multiple --config codecept.multiple.features.js chunks --grep '(?=.*)^(?!.*@fail)'` , ( err , stdout ) => {
169
+ stdout = stripAnsi ( stdout ) ;
161
170
expect ( stdout ) . to . include ( '@feature_grep' ) ;
162
171
expect ( stdout ) . to . include ( 'Checkout examples process' ) ;
163
172
expect ( stdout ) . to . include ( 'Checkout string' ) ;
164
- assert ( ! err ) ;
165
173
done ( ) ;
166
174
} ) ;
167
175
} ) ;
168
176
169
177
it ( 'should run only tests in parallel' , ( done ) => {
170
178
process . chdir ( codecept_dir ) ;
171
179
exec ( `${ runner } run-multiple --config codecept.multiple.features.js chunks --tests` , ( err , stdout ) => {
180
+ stdout = stripAnsi ( stdout ) ;
172
181
expect ( stdout ) . to . include ( '@feature_grep' ) ;
173
182
expect ( stdout ) . to . not . include ( 'Checkout examples process' ) ;
174
183
expect ( stdout ) . to . not . include ( 'Checkout string' ) ;
@@ -180,8 +189,9 @@ describe('CodeceptJS Multiple Runner', function () {
180
189
it ( 'should exit with non-zero code for failures during init process' , ( done ) => {
181
190
process . chdir ( codecept_dir ) ;
182
191
exec ( `${ runner } run-multiple --config codecept.multiple.initFailure.js default --all` , ( err , stdout ) => {
192
+ stdout = stripAnsi ( stdout ) ;
183
193
expect ( err ) . not . to . false ;
184
- expect ( err . code ) . toBe ( 1 ) ;
194
+ expect ( err . code ) . to . eql ( 1 ) ;
185
195
expect ( stdout ) . contain ( 'Failed on FailureHelper' ) ;
186
196
done ( ) ;
187
197
} ) ;
@@ -190,6 +200,7 @@ describe('CodeceptJS Multiple Runner', function () {
190
200
it ( 'should exit code 1 when error in config' , ( done ) => {
191
201
process . chdir ( codecept_dir ) ;
192
202
exec ( `${ runner } run-multiple --config configs/codecept-invalid.config.js default --all` , ( err , stdout , stderr ) => {
203
+ stdout = stripAnsi ( stdout ) ;
193
204
expect ( stdout ) . not . contain ( 'UnhandledPromiseRejectionWarning' ) ;
194
205
expect ( stderr ) . not . contain ( 'UnhandledPromiseRejectionWarning' ) ;
195
206
expect ( stdout ) . contain ( 'badFn is not defined' ) ;
@@ -202,8 +213,9 @@ describe('CodeceptJS Multiple Runner', function () {
202
213
const _codecept_run = `run-multiple --config ${ codecept_dir } ` ;
203
214
it ( 'should be executed from async function in config' , ( done ) => {
204
215
exec ( `${ runner } ${ _codecept_run } /codecept.async.bootstrapall.multiple.code.js default` , ( err , stdout ) => {
216
+ stdout = stripAnsi ( stdout ) ;
205
217
expect ( stdout ) . to . include ( 'CodeceptJS' ) ; // feature
206
- expect ( stdout ) . to . include ( 'Results: inside Promise\n"event.multiple.before" is called ' ) ;
218
+ expect ( stdout ) . to . include ( 'Results: inside Promise' ) ;
207
219
expect ( stdout ) . to . include ( '"teardownAll" is called.' ) ;
208
220
assert ( ! err ) ;
209
221
done ( ) ;
@@ -212,6 +224,7 @@ describe('CodeceptJS Multiple Runner', function () {
212
224
213
225
it ( 'should be executed from function in config' , ( done ) => {
214
226
exec ( `${ runner } ${ _codecept_run } /codecept.bootstrapall.multiple.code.js default` , ( err , stdout ) => {
227
+ stdout = stripAnsi ( stdout ) ;
215
228
expect ( stdout ) . to . include ( 'CodeceptJS' ) ; // feature
216
229
expect ( stdout ) . to . include ( '"bootstrapAll" is called.' ) ;
217
230
expect ( stdout ) . to . include ( '"teardownAll" is called.' ) ;
@@ -227,8 +240,8 @@ describe('CodeceptJS Multiple Runner', function () {
227
240
const moduleOutput2 = 'Module was required 2' ;
228
241
229
242
it ( 'should be executed with module when described' , ( done ) => {
230
- process . chdir ( codecept_dir ) ;
231
243
exec ( `${ runner } ${ _codecept_run } /codecept.require.multiple.single.json default` , ( err , stdout ) => {
244
+ stdout = stripAnsi ( stdout ) ;
232
245
expect ( stdout ) . to . include ( moduleOutput ) ;
233
246
expect ( stdout ) . to . not . include ( moduleOutput2 ) ;
234
247
expect ( stdout . match ( new RegExp ( moduleOutput , 'g' ) ) || [ ] ) . to . have . lengthOf ( 2 ) ;
@@ -238,8 +251,8 @@ describe('CodeceptJS Multiple Runner', function () {
238
251
} ) ;
239
252
240
253
it ( 'should be executed with several module when described' , ( done ) => {
241
- process . chdir ( codecept_dir ) ;
242
254
exec ( `${ runner } ${ _codecept_run } /codecept.require.multiple.several.js default` , ( err , stdout ) => {
255
+ stdout = stripAnsi ( stdout ) ;
243
256
expect ( stdout ) . to . include ( moduleOutput ) ;
244
257
expect ( stdout ) . to . include ( moduleOutput2 ) ;
245
258
expect ( stdout . match ( new RegExp ( moduleOutput , 'g' ) ) || [ ] ) . to . have . lengthOf ( 2 ) ;
@@ -250,8 +263,8 @@ describe('CodeceptJS Multiple Runner', function () {
250
263
} ) ;
251
264
252
265
it ( 'should not be executed without module when not described' , ( done ) => {
253
- process . chdir ( codecept_dir ) ;
254
266
exec ( `${ runner } ${ _codecept_run } /codecept.require.multiple.without.json default` , ( err , stdout ) => {
267
+ stdout = stripAnsi ( stdout ) ;
255
268
expect ( stdout ) . to . not . include ( moduleOutput ) ;
256
269
expect ( stdout ) . to . not . include ( moduleOutput2 ) ;
257
270
assert ( ! err ) ;
0 commit comments