Skip to content

Commit

Permalink
fix: disable retryFailedStep when using with tryTo (#4022)
Browse files Browse the repository at this point in the history
  • Loading branch information
kobenguyent authored Nov 29, 2023
1 parent d0901d8 commit 1936b0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
3 changes: 3 additions & 0 deletions lib/plugin/retryFailedStep.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const event = require('../event');
const recorder = require('../recorder');
const container = require('../container');

const defaultConfig = {
retries: 3,
Expand Down Expand Up @@ -98,6 +99,8 @@ module.exports = (config) => {
config.when = when;

event.dispatcher.on(event.step.started, (step) => {
if (container.plugins('tryTo')) return;

// if a step is ignored - return
for (const ignored of config.ignoredSteps) {
if (step.name === ignored) return;
Expand Down
22 changes: 11 additions & 11 deletions test/unit/plugin/retryFailedStep_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('retryFailedStep', () => {
event.dispatcher.emit(event.step.started, { name: 'click' });

let counter = 0;
recorder.add(() => {
await recorder.add(() => {
counter++;
if (counter < 3) {
throw new Error();
Expand All @@ -51,7 +51,7 @@ describe('retryFailedStep', () => {
});
await recorder.promise();
} catch (e) {
recorder.catchWithoutStop((err) => err);
await recorder.catchWithoutStop((err) => err);
}

// expects to retry only once
Expand All @@ -65,15 +65,15 @@ describe('retryFailedStep', () => {
let counter = 0;
event.dispatcher.emit(event.step.started, { name: 'waitForElement' });
try {
recorder.add(() => {
await recorder.add(() => {
counter++;
if (counter < 3) {
throw new Error();
}
}, undefined, undefined, true);
await recorder.promise();
} catch (e) {
recorder.catchWithoutStop((err) => err);
await recorder.catchWithoutStop((err) => err);
}

expect(counter).to.equal(1);
Expand All @@ -87,15 +87,15 @@ describe('retryFailedStep', () => {
let counter = 0;
event.dispatcher.emit(event.step.started, { name: 'amOnPage' });
try {
recorder.add(() => {
await recorder.add(() => {
counter++;
if (counter < 3) {
throw new Error();
}
}, undefined, undefined, true);
await recorder.promise();
} catch (e) {
recorder.catchWithoutStop((err) => err);
await recorder.catchWithoutStop((err) => err);
}

expect(counter).to.equal(1);
Expand All @@ -109,15 +109,15 @@ describe('retryFailedStep', () => {
let counter = 0;
event.dispatcher.emit(event.step.started, { name: 'somethingNew' });
try {
recorder.add(() => {
await recorder.add(() => {
counter++;
if (counter < 3) {
throw new Error();
}
}, undefined, undefined, true);
await recorder.promise();
} catch (e) {
recorder.catchWithoutStop((err) => err);
await recorder.catchWithoutStop((err) => err);
}

expect(counter).to.equal(1);
Expand All @@ -131,15 +131,15 @@ describe('retryFailedStep', () => {
let counter = 0;
event.dispatcher.emit(event.step.started, { name: 'somethingNew' });
try {
recorder.add(() => {
await recorder.add(() => {
counter++;
if (counter < 3) {
throw new Error();
}
}, undefined, undefined, true);
await recorder.promise();
} catch (e) {
recorder.catchWithoutStop((err) => err);
await recorder.catchWithoutStop((err) => err);
}

expect(counter).to.equal(1);
Expand All @@ -161,7 +161,7 @@ describe('retryFailedStep', () => {
});
await recorder.promise();
} catch (e) {
recorder.catchWithoutStop((err) => err);
await recorder.catchWithoutStop((err) => err);
}

// expects to retry only once
Expand Down

0 comments on commit 1936b0b

Please sign in to comment.