Skip to content

Commit cbe818a

Browse files
Horsty80a-stankevichandonaryactions-userkobenguyent
authoredJun 7, 2024
fix: handle throw error inside retryTo promise (#4377)
* fix(webApi): error message of dontSeeCookie (#4357) * Fixed error message for dontSeeCookie() * fix(cli): gherkin command init with TypeScript (#4366) * DOC: Update contributor faces * fix(doc): Expect helper is not described correctly (#4370) * fix: Puppeteer helper doc typo (#4369) * chore(deps): bump devtools from 8.36.1 to 8.38.0 (#4374) * chore(deps-dev): bump playwright from 1.44.0 to 1.44.1 (#4376) Bumps [playwright](https://github.com/microsoft/playwright) from 1.44.0 to 1.44.1. - [Release notes](https://github.com/microsoft/playwright/releases) - [Commits](microsoft/playwright@v1.44.0...v1.44.1) --- updated-dependencies: - dependency-name: playwright dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump axios from 1.6.7 to 1.7.2 (#4372) * chore(deps-dev): bump typedoc-plugin-markdown from 3.17.1 to 4.0.3 (#4373) * fix: handle throw error inside retryTo promise * fix: test due to update on retryTo plugin * fix: add a test case succeed after 2 retry --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Arthur Stankevich <[email protected]> Co-authored-by: Ando NARY <[email protected]> Co-authored-by: GitHub Action <[email protected]> Co-authored-by: KobeN <[email protected]> Co-authored-by: Yoann Fleury <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
1 parent 80c73a9 commit cbe818a

25 files changed

+240
-65
lines changed
 

Diff for: ‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ Thanks all to those who are and will have contributing to this awesome project!
315315
<a href="https://github.com/VikalpP"><img src="https://avatars.githubusercontent.com/u/11846339?v=4" title="VikalpP" width="80" height="80"></a>
316316
<a href="https://github.com/elaichenkov"><img src="https://avatars.githubusercontent.com/u/29764053?v=4" title="elaichenkov" width="80" height="80"></a>
317317
<a href="https://github.com/BorisOsipov"><img src="https://avatars.githubusercontent.com/u/6514276?v=4" title="BorisOsipov" width="80" height="80"></a>
318-
<a href="https://github.com/hubidu"><img src="https://avatars.githubusercontent.com/u/13134082?v=4" title="hubidu" width="80" height="80"></a>
319318
<a href="https://github.com/nitschSB"><img src="https://avatars.githubusercontent.com/u/39341455?v=4" title="nitschSB" width="80" height="80"></a>
319+
<a href="https://github.com/hubidu"><img src="https://avatars.githubusercontent.com/u/13134082?v=4" title="hubidu" width="80" height="80"></a>
320320
<a href="https://github.com/jploskonka"><img src="https://avatars.githubusercontent.com/u/669483?v=4" title="jploskonka" width="80" height="80"></a>
321321
<a href="https://github.com/ngraf"><img src="https://avatars.githubusercontent.com/u/7094389?v=4" title="ngraf" width="80" height="80"></a>
322322
<a href="https://github.com/maojunxyz"><img src="https://avatars.githubusercontent.com/u/28778042?v=4" title="maojunxyz" width="80" height="80"></a>

Diff for: ‎docs/helpers/Expect.md renamed to ‎docs/helpers/ExpectHelper.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
permalink: /helpers/Expect
2+
permalink: /helpers/ExpectHelper
33
editLink: false
44
sidebar: auto
5-
title: Expect
5+
title: ExpectHelper
66
---
77

88
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
@@ -20,7 +20,7 @@ Zero-configuration when paired with other helpers like REST, Playwright:
2020
{
2121
helpers: {
2222
Playwright: {...},
23-
Expect: {},
23+
ExpectHelper: {},
2424
}
2525
}
2626
```

Diff for: ‎docs/helpers/Puppeteer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2476,7 +2476,7 @@ Returns **void** automatically synchronized promise through #recorder
24762476
24772477
[18]: https://codecept.io/helpers/FileSystem
24782478
2479-
[19]: https://pptr.dev/next/guides/request-interception
2479+
[19]: https://pptr.dev/guides/network-interception
24802480
24812481
[20]: https://github.com/GoogleChrome/puppeteer/issues/1313
24822482

Diff for: ‎lib/command/gherkin/init.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const mkdirp = require('mkdirp');
44
const output = require('../../output');
55
const { fileExists } = require('../../utils');
66
const {
7-
getConfig, getTestRoot, updateConfig, safeFileWrite,
7+
getConfig, getTestRoot, updateConfig, safeFileWrite, findConfigFile,
88
} = require('../utils');
99

1010
const featureFile = `Feature: Business rules
@@ -26,7 +26,17 @@ Given('I have a defined step', () => {
2626

2727
module.exports = function (genPath) {
2828
const testsPath = getTestRoot(genPath);
29+
const configFile = findConfigFile(testsPath);
30+
31+
if (!configFile) {
32+
output.error(
33+
"Can't initialize Gherkin. This command must be run in an already initialized project."
34+
);
35+
process.exit(1);
36+
}
37+
2938
const config = getConfig(testsPath);
39+
const extension = path.extname(configFile).substring(1);
3040

3141
output.print('Initializing Gherkin (Cucumber BDD) for CodeceptJS');
3242
output.print('--------------------------');
@@ -53,18 +63,18 @@ module.exports = function (genPath) {
5363
output.success(`Created ${dir}, place step definitions into it`);
5464
}
5565

56-
if (safeFileWrite(path.join(dir, 'steps.js'), stepsFile)) {
57-
output.success('Created sample steps file: step_definitions/steps.js');
66+
if (safeFileWrite(path.join(dir, `steps.${extension}`), stepsFile)) {
67+
output.success(
68+
`Created sample steps file: step_definitions/steps.${extension}`
69+
);
5870
}
5971

6072
config.gherkin = {
61-
features: './features/*.feature',
62-
steps: [
63-
'./step_definitions/steps.js',
64-
],
73+
features: "./features/*.feature",
74+
steps: [`./step_definitions/steps.${extension}`],
6575
};
6676

67-
updateConfig(testsPath, config);
77+
updateConfig(testsPath, config, extension);
6878

6979
output.success('Gherkin setup is done.');
7080
output.success('Start writing feature files and implement corresponding steps.');

Diff for: ‎lib/command/utils.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ function fail(msg) {
4141

4242
module.exports.fail = fail;
4343

44-
function updateConfig(testsPath, config, key, extension = 'js') {
44+
function updateConfig(testsPath, config, extension) {
4545
const configFile = path.join(testsPath, `codecept.conf.${extension}`);
4646
if (!fileExists(configFile)) {
47-
console.log();
4847
const msg = `codecept.conf.${extension} config can\'t be updated automatically`;
48+
console.log();
4949
console.log(`${output.colors.bold.red(msg)}`);
50-
console.log('Please update it manually:');
50+
console.log(`${output.colors.bold.red("Please update it manually:")}`);
5151
console.log();
52-
console.log(`${key}: ${config[key]}`);
52+
console.log(config);
5353
console.log();
5454
return;
5555
}
@@ -104,3 +104,14 @@ module.exports.createOutputDir = (config, testRoot) => {
104104
mkdirp.sync(outputDir);
105105
}
106106
};
107+
108+
module.exports.findConfigFile = (testsPath) => {
109+
const extensions = ['js', 'ts'];
110+
for (const ext of extensions) {
111+
const configFile = path.join(testsPath, `codecept.conf.${ext}`);
112+
if (fileExists(configFile)) {
113+
return configFile;
114+
}
115+
}
116+
return null;
117+
}

Diff for: ‎lib/helper/Expect.js renamed to ‎lib/helper/ExpectHelper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import('chai').then(chai => {
2323
*{
2424
* helpers: {
2525
* Playwright: {...},
26-
* Expect: {},
26+
* ExpectHelper: {},
2727
* }
2828
*}
2929
* ```

Diff for: ‎lib/helper/Playwright.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1981,7 +1981,7 @@ class Playwright extends Helper {
19811981
*/
19821982
async dontSeeCookie(name) {
19831983
const cookies = await this.browserContext.cookies();
1984-
empty(`cookie ${name} to be set`).assert(cookies.filter(c => c.name === name));
1984+
empty(`cookie ${name} not to be set`).assert(cookies.filter(c => c.name === name));
19851985
}
19861986

19871987
/**

Diff for: ‎lib/helper/Puppeteer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,7 @@ class Puppeteer extends Helper {
16271627
*/
16281628
async dontSeeCookie(name) {
16291629
const cookies = await this.page.cookies();
1630-
empty(`cookie ${name} to be set`).assert(cookies.filter(c => c.name === name));
1630+
empty(`cookie ${name} not to be set`).assert(cookies.filter(c => c.name === name));
16311631
}
16321632

16331633
/**
@@ -2472,12 +2472,12 @@ class Puppeteer extends Helper {
24722472
}
24732473

24742474
/**
2475-
* Mocks network request using [`Request Interception`](https://pptr.dev/next/guides/request-interception)
2475+
* Mocks network request using [`Request Interception`](https://pptr.dev/guides/network-interception)
24762476
*
24772477
* ```js
24782478
* I.mockRoute(/(\.png$)|(\.jpg$)/, route => route.abort());
24792479
* ```
2480-
* This method allows intercepting and mocking requests & responses. [Learn more about it](https://pptr.dev/next/guides/request-interception)
2480+
* This method allows intercepting and mocking requests & responses. [Learn more about it](https://pptr.dev/guides/network-interception)
24812481
*
24822482
* @param {string|RegExp} [url] URL, regex or pattern for to match URL
24832483
* @param {function} [handler] a function to process request

Diff for: ‎lib/plugin/retryTo.js

+31-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const recorder = require('../recorder');
2-
const store = require('../store');
32
const { debug } = require('../output');
43

54
const defaultConfig = {
@@ -73,49 +72,55 @@ const defaultConfig = {
7372
* const retryTo = codeceptjs.container.plugins('retryTo');
7473
* ```
7574
*
76-
*/
75+
*/
7776
module.exports = function (config) {
7877
config = Object.assign(defaultConfig, config);
78+
function retryTo(callback, maxTries, pollInterval = config.pollInterval) {
79+
return new Promise((done, reject) => {
80+
let tries = 1;
7981

80-
if (config.registerGlobal) {
81-
global.retryTo = retryTo;
82-
}
83-
return retryTo;
82+
function handleRetryException(err) {
83+
recorder.throw(err);
84+
reject(err);
85+
}
8486

85-
function retryTo(callback, maxTries, pollInterval = undefined) {
86-
let tries = 1;
87-
if (!pollInterval) pollInterval = config.pollInterval;
88-
89-
let err = null;
90-
91-
return new Promise((done) => {
9287
const tryBlock = async () => {
88+
tries++;
9389
recorder.session.start(`retryTo ${tries}`);
94-
await callback(tries);
90+
try {
91+
await callback(tries);
92+
} catch (err) {
93+
handleRetryException(err);
94+
}
95+
96+
// Call done if no errors
9597
recorder.add(() => {
9698
recorder.session.restore(`retryTo ${tries}`);
9799
done(null);
98100
});
99-
recorder.session.catch((e) => {
100-
err = e;
101+
102+
// Catch errors and retry
103+
recorder.session.catch((err) => {
101104
recorder.session.restore(`retryTo ${tries}`);
102-
tries++;
103105
if (tries <= maxTries) {
104106
debug(`Error ${err}... Retrying`);
105-
err = null;
106-
107-
recorder.add(`retryTo ${tries}`, () => setTimeout(tryBlock, pollInterval));
107+
recorder.add(`retryTo ${tries}`, () =>
108+
setTimeout(tryBlock, pollInterval)
109+
);
108110
} else {
109-
done(null);
111+
// if maxTries reached
112+
handleRetryException(err);
110113
}
111114
});
112115
};
113116

114-
recorder.add('retryTo', async () => {
115-
tryBlock();
116-
});
117-
}).then(() => {
118-
if (err) recorder.throw(err);
117+
recorder.add('retryTo', tryBlock);
119118
});
120119
}
120+
121+
if (config.registerGlobal) {
122+
global.retryTo = retryTo;
123+
}
124+
125+
return retryTo;
121126
};

Diff for: ‎package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"@xmldom/xmldom": "0.8.10",
7777
"acorn": "8.11.3",
7878
"arrify": "2.0.1",
79-
"axios": "1.6.7",
79+
"axios": "1.7.2",
8080
"chai": "5.1.1",
8181
"chai-deep-match": "1.2.1",
8282
"chai-exclude": "2.1.0",
@@ -89,7 +89,7 @@
8989
"cross-spawn": "7.0.3",
9090
"css-to-xpath": "0.1.0",
9191
"csstoxpath": "1.6.0",
92-
"devtools": "8.36.1",
92+
"devtools": "8.38.0",
9393
"envinfo": "7.11.1",
9494
"escape-string-regexp": "4.0.0",
9595
"figures": "3.2.0",
@@ -148,7 +148,7 @@
148148
"jsdoc": "4.0.3",
149149
"jsdoc-typeof-plugin": "1.0.0",
150150
"json-server": "0.10.1",
151-
"playwright": "1.44.0",
151+
"playwright": "1.44.1",
152152
"puppeteer": "22.10.0",
153153
"qrcode-terminal": "0.12.0",
154154
"rosie": "2.1.1",
@@ -161,7 +161,7 @@
161161
"tsd": "^0.31.0",
162162
"tsd-jsdoc": "2.5.0",
163163
"typedoc": "0.25.13",
164-
"typedoc-plugin-markdown": "3.17.1",
164+
"typedoc-plugin-markdown": "4.0.3",
165165
"typescript": "5.3.3",
166166
"wdio-docker-service": "1.5.0",
167167
"webdriverio": "8.36.1",

Diff for: ‎test/acceptance/codecept.Playwright.coverage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports.config = {
2323
require: '../support/ScreenshotSessionHelper.js',
2424
outputPath: 'test/acceptance/output',
2525
},
26-
Expect: {},
26+
ExpectHelper: {},
2727
},
2828
include: {},
2929
bootstrap: false,

Diff for: ‎test/acceptance/codecept.Playwright.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports.config = {
2323
require: '../support/ScreenshotSessionHelper.js',
2424
outputPath: 'test/acceptance/output',
2525
},
26-
Expect: {},
26+
ExpectHelper: {},
2727
},
2828
include: {},
2929
bootstrap: false,

Diff for: ‎test/acceptance/codecept.Playwright.retryTo.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports.config = {
2323
require: '../support/ScreenshotSessionHelper.js',
2424
outputPath: 'test/acceptance/output',
2525
},
26-
Expect: {},
26+
ExpectHelper: {},
2727
},
2828
include: {},
2929
bootstrap: false,

Diff for: ‎test/acceptance/codecept.Puppeteer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports.config = {
1919
require: '../support/ScreenshotSessionHelper.js',
2020
outputPath: './output',
2121
},
22-
Expect: {},
22+
ExpectHelper: {},
2323
},
2424
include: {},
2525
bootstrap: false,

Diff for: ‎test/acceptance/codecept.Testcafe.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports.config = {
99
url: TestHelper.siteUrl(),
1010
show: true,
1111
},
12-
Expect: {},
12+
ExpectHelper: {},
1313
},
1414
include: {},
1515
bootstrap: false,

Diff for: ‎test/acceptance/codecept.WebDriver.devtools.coverage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports.config = {
2121
require: '../support/ScreenshotSessionHelper.js',
2222
outputPath: './output',
2323
},
24-
Expect: {},
24+
ExpectHelper: {},
2525
},
2626
include: {},
2727
mocha: {},

Diff for: ‎test/acceptance/codecept.WebDriver.devtools.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports.config = {
2121
require: '../support/ScreenshotSessionHelper.js',
2222
outputPath: './output',
2323
},
24-
Expect: {},
24+
ExpectHelper: {},
2525
},
2626
include: {},
2727
bootstrap: async () => new Promise(done => {

Diff for: ‎test/acceptance/codecept.WebDriver.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports.config = {
2121
require: '../support/ScreenshotSessionHelper.js',
2222
outputPath: './output',
2323
},
24-
Expect: {},
24+
ExpectHelper: {},
2525
},
2626
include: {},
2727
bootstrap: async () => new Promise(done => {

Diff for: ‎test/acceptance/retryTo_test.js

+12
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,15 @@ Scenario('retryTo works with non await steps @plugin', async () => {
1414
if (tryNum < 3) I.waitForVisible('.nothing', 1);
1515
}, 4);
1616
});
17+
18+
Scenario('Should fail after reached max retries', async () => {
19+
await retryTo(() => {
20+
throw new Error('Custom pluginRetryTo Error');
21+
}, 3);
22+
});
23+
24+
Scenario('Should succeed at the third attempt @plugin', async () => {
25+
await retryTo(async (tryNum) => {
26+
if (tryNum < 2) throw new Error('Custom pluginRetryTo Error');
27+
}, 3);
28+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/** @type {CodeceptJS.MainConfig} */
2+
exports.config = {
3+
tests: "./*_test.js",
4+
output: "./output",
5+
helpers: {
6+
Playwright: {
7+
browser: "chromium",
8+
url: "http://localhost",
9+
show: true,
10+
},
11+
},
12+
include: {
13+
I: "./steps_file.js",
14+
},
15+
name: "CodeceptJS",
16+
};

0 commit comments

Comments
 (0)