Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Plugins tests

on:
push:
branches:
- 3.x
pull_request:
branches:
- '**'

env:
CI: true
# Force terminal colors. @see https://www.npmjs.com/package/colors
FORCE_COLOR: 1

jobs:
build:

runs-on: ubuntu-22.04

strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
- name: npm install
run: |
npm install --legacy-peer-deps
env:
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD: true
- name: Install browsers and deps
run: npx playwright install chromium && npx playwright install-deps
- name: start a server
run: "php -S 127.0.0.1:8000 -t test/data/app &"
- name: run plugin tests
run: npm run test:plugin
4 changes: 2 additions & 2 deletions lib/plugin/retryTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ module.exports = function (config) {
let err = null;

return new Promise((done) => {
const tryBlock = () => {
const tryBlock = async () => {
recorder.session.start(`retryTo ${tries}`);
callback(tries);
await callback(tries);
recorder.add(() => {
recorder.session.restore(`retryTo ${tries}`);
done(null);
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"test:unit:webbapi:webDriver": "mocha test/helper/WebDriver_test.js",
"test:unit:webbapi:testCafe": "mocha test/helper/TestCafe_test.js",
"test:unit:expect": "mocha test/helper/Expect_test.js",
"test:plugin": "mocha test/plugin/plugin_test.js",
"def": "./runok.js def",
"dev:graphql": "node test/data/graphql/index.js",
"publish:site": "./runok.js publish:site",
Expand Down
3 changes: 3 additions & 0 deletions test/acceptance/codecept.Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ module.exports.config = {
screenshotOnFail: {
enabled: true,
},
retryTo: {
enabled: true,
},
},
name: 'acceptance',
gherkin: {
Expand Down
44 changes: 44 additions & 0 deletions test/acceptance/codecept.Playwright.retryTo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const TestHelper = require('../support/TestHelper');

module.exports.config = {
tests: './*_test.js',
timeout: 10000,
output: './output',
grep: '@Playwright',
helpers: {
Playwright: {
url: TestHelper.siteUrl(),
show: false,
restart: process.env.BROWSER_RESTART || false,
browser: process.env.BROWSER || 'chromium',
ignoreHTTPSErrors: true,
webkit: {
ignoreHTTPSErrors: true,
},
},
JSONResponse: {
requestHelper: 'Playwright',
},
ScreenshotSessionHelper: {
require: '../support/ScreenshotSessionHelper.js',
outputPath: 'test/acceptance/output',
},
Expect: {},
},
include: {},
bootstrap: false,
mocha: {},
plugins: {
screenshotOnFail: {
enabled: true,
},
retryTo: {
enabled: true,
},
},
name: 'acceptance',
gherkin: {
features: './gherkin/*.feature',
steps: ['./gherkin/steps.js'],
},
};
16 changes: 16 additions & 0 deletions test/acceptance/retryTo_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { I } = inject();

Feature('Plugins');

Scenario('retryTo works with await steps @plugin', async () => {
await retryTo(async (tryNum) => {
const foo = await I.grabCurrentUrl();
if (tryNum < 3) I.waitForVisible('.nothing', 1);
}, 4);
});

Scenario('retryTo works with non await steps @plugin', async () => {
await retryTo(async (tryNum) => {
if (tryNum < 3) I.waitForVisible('.nothing', 1);
}, 4);
});
34 changes: 34 additions & 0 deletions test/plugin/plugin_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const path = require('path');
const { exec } = require('child_process');
const { expect } = require('expect');

const runner = path.join(__dirname, '../../bin/codecept.js');
const codecept_dir = path.join(
__dirname,
'../acceptance',
);
const codecept_run = `${runner} run`;
const config_run_config = (config, grep) => `${codecept_run} --config ${codecept_dir}/${config} ${
grep ? `--grep "${grep}"` : ''
}`;

describe('CodeceptJS plugin', function () {
this.timeout(30000);

before(() => {
process.chdir(codecept_dir);
});

it('should retry the await/non await steps', (done) => {
exec(`${config_run_config('codecept.Playwright.retryTo.js', '@plugin')} --verbose`, (err, stdout) => {
const lines = stdout.split('\n');
expect(lines).toEqual(
expect.arrayContaining([
expect.stringContaining('... Retrying'),
]),
);
expect(err).toBeFalsy();
done();
});
});
});