Skip to content

Commit 350c43f

Browse files
committed
fix: CodeceptJS Multiple Runner tests - 20 tests
1 parent 1c790ee commit 350c43f

File tree

9 files changed

+84
-63
lines changed

9 files changed

+84
-63
lines changed

lib/cli.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ class Cli extends Base {
1717
super(runner);
1818
let level = 0;
1919
this.loadedTests = [];
20+
this.stats = {};
21+
this.failures = [];
2022
opts = opts.reporterOptions || opts;
2123
if (opts.steps) level = 1;
2224
if (opts.debug) level = 2;
2325
if (opts.verbose) level = 3;
2426
output.output.level(level);
2527
const version = Codecept.version();
2628
output.output.print(`CodeceptJS v${version} ${output.output.standWithUkraine()}`);
29+
// @ts-ignore
2730
output.output.print(`Using test root "${global.codecept_dir}"`);
2831

2932
const showSteps = level >= 1;

lib/command/interactive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default async function (path, options) {
2121
try {
2222
await codecept.bootstrap();
2323

24-
if (options.verbose) output.level(3);
24+
if (options.verbose) output.output.level(3);
2525

2626
output.print('Starting interactive shell for current suite...');
2727
recorder.start();

lib/command/run-multiple.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default async function (selectedRuns, options) {
3434
const configFile = options.config;
3535

3636
const testRoot = getTestRoot(configFile);
37+
// @ts-ignore
3738
global.codecept_dir = testRoot;
3839

3940
// copy opts to run

lib/pause.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,16 @@ async function parseInput(cmd) {
106106
let $res;
107107
try {
108108
// eslint-disable-next-line
109+
// @ts-ignore
109110
const locate = global.locate; // enable locate in this context
110111
// eslint-disable-next-line
111112
const I = container.support('I');
112113
if (cmd.trim().startsWith('=>')) {
113114
isCustomCommand = true;
114115
cmd = cmd.trim().substring(2, cmd.length);
115116
} else if (aiAssistant.isEnabled && !cmd.match(/^\w+\(/) && cmd.includes(' ')) {
116-
const currentOutputLevel = output.level();
117-
output.level(0);
117+
const currentOutputLevel = output.output.level();
118+
output.output.level(0);
118119
const res = I.grabSource();
119120
isAiCommand = true;
120121
executeCommand = executeCommand.then(async () => {
@@ -125,7 +126,7 @@ async function parseInput(cmd) {
125126
output.print(output.output.styles.error(' ERROR '), 'Can\'t get HTML context', err.stack);
126127
return;
127128
} finally {
128-
output.level(currentOutputLevel);
129+
output.output.level(currentOutputLevel);
129130
}
130131
// aiAssistant.mockResponse("```js\nI.click('Sign in');\n```");
131132
const spinner = ora("Processing OpenAI request...").start();

lib/plugin/debugErrors.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ export default function (config = {}) {
4646
event.dispatcher.on(event.test.failed, (test) => {
4747
recorder.add('HTML snapshot failed test', async () => {
4848
try {
49-
const currentOutputLevel = output.level();
50-
output.level(0);
49+
const currentOutputLevel = output.output.level();
50+
output.output.level(0);
5151
const html = await helper.grabHTMLFrom('body');
52-
output.level(currentOutputLevel);
52+
output.output.level(currentOutputLevel);
5353

5454
if (!html) return;
5555

5656
const errors = scanForErrorMessages(html, config.errorClasses);
5757
if (errors.length) {
58-
output.debug('Detected errors in HTML code');
59-
errors.forEach((error) => output.debug(error));
58+
output.output.debug('Detected errors in HTML code');
59+
errors.forEach((error) => output.output.debug(error));
6060
test.artifacts.errors = errors;
6161
}
6262
} catch (err) {

lib/plugin/heal.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ export default function (config = {}) {
125125
const step = test.steps[test.steps.length - 1];
126126
debug('Self-healing started', step.toCode());
127127

128-
const currentOutputLevel = output.level();
129-
output.level(0);
128+
const currentOutputLevel = output.output.level();
129+
output.output.level(0);
130130
const html = await helper.grabHTMLFrom('body');
131-
output.level(currentOutputLevel);
131+
output.output.level(currentOutputLevel);
132132

133133
if (!html) throw err;
134134

lib/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,3 +478,7 @@ export const printObjectProperties = (obj) => {
478478
export const normalizeSpacesInString = (string) => {
479479
return string.replace(/\s+/g, ' ');
480480
};
481+
482+
export function stripAnsi(string) {
483+
return string.replace(/\u001b\[.*?m/g, '');
484+
};

test/data/fake_driver.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import Helper from '../../lib/helper.js';
2-
import { output } from '../../lib/output.js';
1+
import Helper from '@codeceptjs/helper';
2+
import * as output from '../../lib/output.js';
3+
4+
export default class FakeDriver extends Helper {
35

4-
class FakeDriver extends Helper {
56
printBrowser() {
6-
output.debug(this.config.browser);
7+
output.output.debug(this.config.browser);
78
}
89

910
printWindowSize() {
10-
output.debug(this.config.windowSize);
11+
output.output.debug(this.config.windowSize);
1112
}
1213
}
13-
14-
export default FakeDriver;

test/runner/run_multiple_test.js

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { expect } from 'chai';
33
import path, { dirname } from 'path';
44
import { exec } from 'child_process';
55
import { fileURLToPath } from 'url';
6+
import { stripAnsi } from '../../lib/utils.js';
67

78
const __dirname = dirname(fileURLToPath(import.meta.url));
89
const runner = path.join(__dirname, '../../bin/codecept.js');
@@ -19,7 +20,6 @@ describe('CodeceptJS Multiple Runner', function () {
1920

2021
it('should execute one suite with browser', (done) => {
2122
exec(`${codecept_run}default:firefox`, (err, stdout) => {
22-
console.log(stdout)
2323
expect(stdout).to.include('CodeceptJS'); // feature
2424
expect(stdout).to.include('.default:firefox]');
2525
expect(stdout).to.not.include('.default:chrome]');
@@ -30,25 +30,28 @@ describe('CodeceptJS Multiple Runner', function () {
3030

3131
it('should execute all suites', (done) => {
3232
exec(`${codecept_run}--all`, (err, stdout) => {
33+
stdout = stripAnsi(stdout);
3334
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 ');
4546
assert(!err);
4647
done();
4748
});
4849
});
4950

5051
it('should replace parameters', (done) => {
5152
exec(`${codecept_run}grep --debug`, (err, stdout) => {
53+
stdout = stripAnsi(stdout);
54+
console.log(`${codecept_run}grep --debug`);
5255
expect(stdout).to.include('CodeceptJS'); // feature
5356
expect(stdout).to.include('[1.grep:chrome]');
5457
expect(stdout).to.include('[2.grep:firefox]');
@@ -59,31 +62,34 @@ describe('CodeceptJS Multiple Runner', function () {
5962

6063
it('should execute multiple suites', (done) => {
6164
exec(`${codecept_run}mobile default `, (err, stdout) => {
65+
stdout = stripAnsi(stdout);
6266
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 ');
6973
assert(!err);
7074
done();
7175
});
7276
});
7377

7478
it('should execute multiple suites with selected browsers', (done) => {
7579
exec(`${codecept_run}mobile:safari default:chrome `, (err, stdout) => {
80+
stdout = stripAnsi(stdout);
7681
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 ');
8085
assert(!err);
8186
done();
8287
});
8388
});
8489

8590
it('should print steps', (done) => {
8691
exec(`${codecept_run}default --steps`, (err, stdout) => {
92+
stdout = stripAnsi(stdout);
8793
expect(stdout).to.include('CodeceptJS'); // feature
8894
expect(stdout).to.include('[2.default:firefox] ');
8995
expect(stdout).to.include('[2.default:firefox] I');
@@ -96,42 +102,46 @@ describe('CodeceptJS Multiple Runner', function () {
96102

97103
it('should pass grep to configuration', (done) => {
98104
exec(`${codecept_run}default --grep @grep`, (err, stdout) => {
105+
stdout = stripAnsi(stdout);
99106
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');
104111
assert(!err);
105112
done();
106113
});
107114
});
108115

109116
it('should pass grep invert to configuration', (done) => {
110117
exec(`${codecept_run}default --grep @grep --invert`, (err, stdout) => {
118+
stdout = stripAnsi(stdout);
111119
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 ');
116124
assert(!err);
117125
done();
118126
});
119127
});
120128

121129
it('should pass tests to configuration', (done) => {
122130
exec(`${codecept_run}test`, (err, stdout) => {
131+
stdout = stripAnsi(stdout);
123132
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 ');
128137
assert(!err);
129138
done();
130139
});
131140
});
132141

133142
it('should run chunks', (done) => {
134143
exec(`${codecept_run}chunks`, (err, stdout) => {
144+
stdout = stripAnsi(stdout);
135145
expect(stdout).to.include('CodeceptJS'); // feature
136146
expect(stdout).to.include('[1.chunks:chunk1:dummy] print browser');
137147
expect(stdout).to.include('[2.chunks:chunk2:dummy]');
@@ -141,34 +151,33 @@ describe('CodeceptJS Multiple Runner', function () {
141151
});
142152

143153
it('should run features in parallel', (done) => {
144-
process.chdir(codecept_dir);
145154
exec(`${runner} run-multiple --config codecept.multiple.features.js chunks --features --grep '(?=.*)^(?!.*@fail)'`, (err, stdout) => {
155+
stdout = stripAnsi(stdout);
146156
expect(stdout).to.include('[1.chunks:chunk1:default] Checkout examples process');
147157
expect(stdout).to.not.include('[2.chunks:chunk2:default] Checkout examples process');
148158
expect(stdout).to.include('[2.chunks:chunk2:default] Checkout string');
149159
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');
152162
expect(stdout).to.not.include('@feature_grep');
153-
assert(!err);
154163
done();
155164
});
156165
});
157166

158167
it('should run features & tests in parallel', (done) => {
159-
process.chdir(codecept_dir);
160168
exec(`${runner} run-multiple --config codecept.multiple.features.js chunks --grep '(?=.*)^(?!.*@fail)'`, (err, stdout) => {
169+
stdout = stripAnsi(stdout);
161170
expect(stdout).to.include('@feature_grep');
162171
expect(stdout).to.include('Checkout examples process');
163172
expect(stdout).to.include('Checkout string');
164-
assert(!err);
165173
done();
166174
});
167175
});
168176

169177
it('should run only tests in parallel', (done) => {
170178
process.chdir(codecept_dir);
171179
exec(`${runner} run-multiple --config codecept.multiple.features.js chunks --tests`, (err, stdout) => {
180+
stdout = stripAnsi(stdout);
172181
expect(stdout).to.include('@feature_grep');
173182
expect(stdout).to.not.include('Checkout examples process');
174183
expect(stdout).to.not.include('Checkout string');
@@ -180,8 +189,9 @@ describe('CodeceptJS Multiple Runner', function () {
180189
it('should exit with non-zero code for failures during init process', (done) => {
181190
process.chdir(codecept_dir);
182191
exec(`${runner} run-multiple --config codecept.multiple.initFailure.js default --all`, (err, stdout) => {
192+
stdout = stripAnsi(stdout);
183193
expect(err).not.to.false;
184-
expect(err.code).toBe(1);
194+
expect(err.code).to.eql(1);
185195
expect(stdout).contain('Failed on FailureHelper');
186196
done();
187197
});
@@ -190,6 +200,7 @@ describe('CodeceptJS Multiple Runner', function () {
190200
it('should exit code 1 when error in config', (done) => {
191201
process.chdir(codecept_dir);
192202
exec(`${runner} run-multiple --config configs/codecept-invalid.config.js default --all`, (err, stdout, stderr) => {
203+
stdout = stripAnsi(stdout);
193204
expect(stdout).not.contain('UnhandledPromiseRejectionWarning');
194205
expect(stderr).not.contain('UnhandledPromiseRejectionWarning');
195206
expect(stdout).contain('badFn is not defined');
@@ -202,8 +213,9 @@ describe('CodeceptJS Multiple Runner', function () {
202213
const _codecept_run = `run-multiple --config ${codecept_dir}`;
203214
it('should be executed from async function in config', (done) => {
204215
exec(`${runner} ${_codecept_run}/codecept.async.bootstrapall.multiple.code.js default`, (err, stdout) => {
216+
stdout = stripAnsi(stdout);
205217
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');
207219
expect(stdout).to.include('"teardownAll" is called.');
208220
assert(!err);
209221
done();
@@ -212,6 +224,7 @@ describe('CodeceptJS Multiple Runner', function () {
212224

213225
it('should be executed from function in config', (done) => {
214226
exec(`${runner} ${_codecept_run}/codecept.bootstrapall.multiple.code.js default`, (err, stdout) => {
227+
stdout = stripAnsi(stdout);
215228
expect(stdout).to.include('CodeceptJS'); // feature
216229
expect(stdout).to.include('"bootstrapAll" is called.');
217230
expect(stdout).to.include('"teardownAll" is called.');
@@ -227,8 +240,8 @@ describe('CodeceptJS Multiple Runner', function () {
227240
const moduleOutput2 = 'Module was required 2';
228241

229242
it('should be executed with module when described', (done) => {
230-
process.chdir(codecept_dir);
231243
exec(`${runner} ${_codecept_run}/codecept.require.multiple.single.json default`, (err, stdout) => {
244+
stdout = stripAnsi(stdout);
232245
expect(stdout).to.include(moduleOutput);
233246
expect(stdout).to.not.include(moduleOutput2);
234247
expect(stdout.match(new RegExp(moduleOutput, 'g')) || []).to.have.lengthOf(2);
@@ -238,8 +251,8 @@ describe('CodeceptJS Multiple Runner', function () {
238251
});
239252

240253
it('should be executed with several module when described', (done) => {
241-
process.chdir(codecept_dir);
242254
exec(`${runner} ${_codecept_run}/codecept.require.multiple.several.js default`, (err, stdout) => {
255+
stdout = stripAnsi(stdout);
243256
expect(stdout).to.include(moduleOutput);
244257
expect(stdout).to.include(moduleOutput2);
245258
expect(stdout.match(new RegExp(moduleOutput, 'g')) || []).to.have.lengthOf(2);
@@ -250,8 +263,8 @@ describe('CodeceptJS Multiple Runner', function () {
250263
});
251264

252265
it('should not be executed without module when not described', (done) => {
253-
process.chdir(codecept_dir);
254266
exec(`${runner} ${_codecept_run}/codecept.require.multiple.without.json default`, (err, stdout) => {
267+
stdout = stripAnsi(stdout);
255268
expect(stdout).to.not.include(moduleOutput);
256269
expect(stdout).to.not.include(moduleOutput2);
257270
assert(!err);

0 commit comments

Comments
 (0)