Skip to content

Commit

Permalink
fix: respect retries from retryfailedstep plugin in helpers (#4028)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored Nov 29, 2023
1 parent 159350b commit c286f42
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ class Playwright extends Helper {
async _before(test) {
this.currentRunningTest = test;
recorder.retry({
retries: 5,
retries: process.env.FAILED_STEP_RETIRES || 3,
when: err => {
if (!err || typeof (err.message) !== 'string') {
return false;
Expand Down
2 changes: 1 addition & 1 deletion lib/helper/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class Puppeteer extends Helper {
this.sessionPages = {};
this.currentRunningTest = test;
recorder.retry({
retries: 3,
retries: process.env.FAILED_STEP_RETIRES || 3,
when: err => {
if (!err || typeof (err.message) !== 'string') {
return false;
Expand Down
2 changes: 2 additions & 0 deletions lib/plugin/retryFailedStep.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ module.exports = (config) => {

event.dispatcher.on(event.test.before, (test) => {
if (test && test.disableRetryFailedStep) return; // disable retry when a test is not active
// this env var is used to set the retries inside _before() block of helpers
process.env.FAILED_STEP_RETIRES = config.retries;
recorder.retry(config);
});
};
2 changes: 2 additions & 0 deletions test/unit/plugin/retryFailedStep_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('retryFailedStep', () => {
}, undefined, undefined, true);
return recorder.promise();
});

it('should not retry within', async () => {
retryFailedStep({ retries: 1, minTimeout: 1 });
event.dispatcher.emit(event.test.before, {});
Expand All @@ -54,6 +55,7 @@ describe('retryFailedStep', () => {
await recorder.catchWithoutStop((err) => err);
}

expect(process.env.FAILED_STEP_RETIRES).to.equal('1');
// expects to retry only once
counter.should.equal(2);
});
Expand Down

0 comments on commit c286f42

Please sign in to comment.