Skip to content

Commit 7c3ee50

Browse files
authored
fix(plugin): retryTo issue (#4117)
1 parent 17e0919 commit 7c3ee50

File tree

7 files changed

+144
-2
lines changed

7 files changed

+144
-2
lines changed

.github/workflows/plugin.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Plugins tests
2+
3+
on:
4+
push:
5+
branches:
6+
- 3.x
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
env:
12+
CI: true
13+
# Force terminal colors. @see https://www.npmjs.com/package/colors
14+
FORCE_COLOR: 1
15+
16+
jobs:
17+
build:
18+
19+
runs-on: ubuntu-22.04
20+
21+
strategy:
22+
matrix:
23+
node-version: [20.x]
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Use Node.js ${{ matrix.node-version }}
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: ${{ matrix.node-version }}
31+
- uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: 7.4
34+
- name: npm install
35+
run: |
36+
npm install --legacy-peer-deps
37+
env:
38+
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
39+
- name: Install browsers and deps
40+
run: npx playwright install chromium && npx playwright install-deps
41+
- name: start a server
42+
run: "php -S 127.0.0.1:8000 -t test/data/app &"
43+
- name: run plugin tests
44+
run: npm run test:plugin

lib/plugin/retryTo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ module.exports = function (config) {
8989
let err = null;
9090

9191
return new Promise((done) => {
92-
const tryBlock = () => {
92+
const tryBlock = async () => {
9393
recorder.session.start(`retryTo ${tries}`);
94-
callback(tries);
94+
await callback(tries);
9595
recorder.add(() => {
9696
recorder.session.restore(`retryTo ${tries}`);
9797
done(null);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"test:unit:webbapi:webDriver": "mocha test/helper/WebDriver_test.js",
5555
"test:unit:webbapi:testCafe": "mocha test/helper/TestCafe_test.js",
5656
"test:unit:expect": "mocha test/helper/Expect_test.js",
57+
"test:plugin": "mocha test/plugin/plugin_test.js",
5758
"def": "./runok.js def",
5859
"dev:graphql": "node test/data/graphql/index.js",
5960
"publish:site": "./runok.js publish:site",

test/acceptance/codecept.Playwright.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ module.exports.config = {
3232
screenshotOnFail: {
3333
enabled: true,
3434
},
35+
retryTo: {
36+
enabled: true,
37+
},
3538
},
3639
name: 'acceptance',
3740
gherkin: {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const TestHelper = require('../support/TestHelper');
2+
3+
module.exports.config = {
4+
tests: './*_test.js',
5+
timeout: 10000,
6+
output: './output',
7+
grep: '@Playwright',
8+
helpers: {
9+
Playwright: {
10+
url: TestHelper.siteUrl(),
11+
show: false,
12+
restart: process.env.BROWSER_RESTART || false,
13+
browser: process.env.BROWSER || 'chromium',
14+
ignoreHTTPSErrors: true,
15+
webkit: {
16+
ignoreHTTPSErrors: true,
17+
},
18+
},
19+
JSONResponse: {
20+
requestHelper: 'Playwright',
21+
},
22+
ScreenshotSessionHelper: {
23+
require: '../support/ScreenshotSessionHelper.js',
24+
outputPath: 'test/acceptance/output',
25+
},
26+
Expect: {},
27+
},
28+
include: {},
29+
bootstrap: false,
30+
mocha: {},
31+
plugins: {
32+
screenshotOnFail: {
33+
enabled: true,
34+
},
35+
retryTo: {
36+
enabled: true,
37+
},
38+
},
39+
name: 'acceptance',
40+
gherkin: {
41+
features: './gherkin/*.feature',
42+
steps: ['./gherkin/steps.js'],
43+
},
44+
};

test/acceptance/retryTo_test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { I } = inject();
2+
3+
Feature('Plugins');
4+
5+
Scenario('retryTo works with await steps @plugin', async () => {
6+
await retryTo(async (tryNum) => {
7+
const foo = await I.grabCurrentUrl();
8+
if (tryNum < 3) I.waitForVisible('.nothing', 1);
9+
}, 4);
10+
});
11+
12+
Scenario('retryTo works with non await steps @plugin', async () => {
13+
await retryTo(async (tryNum) => {
14+
if (tryNum < 3) I.waitForVisible('.nothing', 1);
15+
}, 4);
16+
});

test/plugin/plugin_test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const path = require('path');
2+
const { exec } = require('child_process');
3+
const { expect } = require('expect');
4+
5+
const runner = path.join(__dirname, '../../bin/codecept.js');
6+
const codecept_dir = path.join(
7+
__dirname,
8+
'../acceptance',
9+
);
10+
const codecept_run = `${runner} run`;
11+
const config_run_config = (config, grep) => `${codecept_run} --config ${codecept_dir}/${config} ${
12+
grep ? `--grep "${grep}"` : ''
13+
}`;
14+
15+
describe('CodeceptJS plugin', function () {
16+
this.timeout(30000);
17+
18+
before(() => {
19+
process.chdir(codecept_dir);
20+
});
21+
22+
it('should retry the await/non await steps', (done) => {
23+
exec(`${config_run_config('codecept.Playwright.retryTo.js', '@plugin')} --verbose`, (err, stdout) => {
24+
const lines = stdout.split('\n');
25+
expect(lines).toEqual(
26+
expect.arrayContaining([
27+
expect.stringContaining('... Retrying'),
28+
]),
29+
);
30+
expect(err).toBeFalsy();
31+
done();
32+
});
33+
});
34+
});

0 commit comments

Comments
 (0)