diff --git a/.github/workflows/plugin.yml b/.github/workflows/plugin.yml new file mode 100644 index 000000000..060b05858 --- /dev/null +++ b/.github/workflows/plugin.yml @@ -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 diff --git a/lib/plugin/retryTo.js b/lib/plugin/retryTo.js index 8d08dadfe..9929944f1 100644 --- a/lib/plugin/retryTo.js +++ b/lib/plugin/retryTo.js @@ -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); diff --git a/package.json b/package.json index 47da7b9a6..ca67e6af1 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/acceptance/codecept.Playwright.js b/test/acceptance/codecept.Playwright.js index fb5a92c63..d45a49f50 100644 --- a/test/acceptance/codecept.Playwright.js +++ b/test/acceptance/codecept.Playwright.js @@ -32,6 +32,9 @@ module.exports.config = { screenshotOnFail: { enabled: true, }, + retryTo: { + enabled: true, + }, }, name: 'acceptance', gherkin: { diff --git a/test/acceptance/codecept.Playwright.retryTo.js b/test/acceptance/codecept.Playwright.retryTo.js new file mode 100644 index 000000000..d45a49f50 --- /dev/null +++ b/test/acceptance/codecept.Playwright.retryTo.js @@ -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'], + }, +}; diff --git a/test/acceptance/retryTo_test.js b/test/acceptance/retryTo_test.js new file mode 100644 index 000000000..b568e8607 --- /dev/null +++ b/test/acceptance/retryTo_test.js @@ -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); +}); diff --git a/test/plugin/plugin_test.js b/test/plugin/plugin_test.js new file mode 100644 index 000000000..848935d7a --- /dev/null +++ b/test/plugin/plugin_test.js @@ -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(); + }); + }); +});