Skip to content

Commit 7912198

Browse files
authored
fix: retryFailedStep is disabled for non tryTo steps (#4069)
1 parent af49335 commit 7912198

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

docs/plugins.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ Run tests with plugin enabled:
721721
- `factor` - The exponential factor to use. Default is 1.5.
722722
- `minTimeout` - The number of milliseconds before starting the first retry. Default is 1000.
723723
- `maxTimeout` - The maximum number of milliseconds between two retries. Default is Infinity.
724-
- `randomize` - Randomizes the timeouts by multiplying with a factor between 1 to 2. Default is false.
724+
- `randomize` - Randomizes the timeouts by multiplying with a factor from 1 to 2. Default is false.
725725
- `defaultIgnoredSteps` - an array of steps to be ignored for retry. Includes:
726726
- `amOnPage`
727727
- `wait*`
@@ -1085,7 +1085,7 @@ plugins: {
10851085
10861086
## tryTo
10871087
1088-
Adds global `tryTo` function inside of which all failed steps won't fail a test but will return true/false.
1088+
Adds global `tryTo` function in which all failed steps won't fail a test but will return true/false.
10891089
10901090
Enable this plugin in `codecept.conf.js` (enabled by default for new setups):
10911091
@@ -1124,7 +1124,7 @@ Add assert requires first:
11241124
const assert = require('assert');
11251125
````
11261126

1127-
Then use the assert:
1127+
Then use the assertion:
11281128
const result1 = await tryTo(() => I.see('Hello, user'));
11291129
const result2 = await tryTo(() => I.seeElement('.welcome'));
11301130
assert.ok(result1 && result2, 'Assertions were not succesful');

lib/plugin/retryFailedStep.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const defaultConfig = {
4343
* * `factor` - The exponential factor to use. Default is 1.5.
4444
* * `minTimeout` - The number of milliseconds before starting the first retry. Default is 1000.
4545
* * `maxTimeout` - The maximum number of milliseconds between two retries. Default is Infinity.
46-
* * `randomize` - Randomizes the timeouts by multiplying with a factor between 1 to 2. Default is false.
46+
* * `randomize` - Randomizes the timeouts by multiplying with a factor from 1 to 2. Default is false.
4747
* * `defaultIgnoredSteps` - an array of steps to be ignored for retry. Includes:
4848
* * `amOnPage`
4949
* * `wait*`
@@ -99,7 +99,7 @@ module.exports = (config) => {
9999
config.when = when;
100100

101101
event.dispatcher.on(event.step.started, (step) => {
102-
if (container.plugins('tryTo')) return;
102+
if (process.env.TRY_TO) return;
103103

104104
// if a step is ignored - return
105105
for (const ignored of config.ignoredSteps) {

lib/plugin/tryTo.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const recorder = require('../recorder');
2-
const store = require('../store');
32
const { debug } = require('../output');
43

54
const defaultConfig = {
@@ -9,7 +8,7 @@ const defaultConfig = {
98
/**
109
*
1110
*
12-
* Adds global `tryTo` function inside of which all failed steps won't fail a test but will return true/false.
11+
* Adds global `tryTo` function in which all failed steps won't fail a test but will return true/false.
1312
*
1413
* Enable this plugin in `codecept.conf.js` (enabled by default for new setups):
1514
*
@@ -47,7 +46,7 @@ const defaultConfig = {
4746
* ```js
4847
* const assert = require('assert');
4948
* ```
50-
* Then use the assert:
49+
* Then use the assertion:
5150
* const result1 = await tryTo(() => I.see('Hello, user'));
5251
* const result2 = await tryTo(() => I.seeElement('.welcome'));
5352
* assert.ok(result1 && result2, 'Assertions were not succesful');
@@ -70,7 +69,7 @@ const defaultConfig = {
7069
* const tryTo = codeceptjs.container.plugins('tryTo');
7170
* ```
7271
*
73-
*/
72+
*/
7473
module.exports = function (config) {
7574
config = Object.assign(defaultConfig, config);
7675

@@ -84,6 +83,7 @@ function tryTo(callback) {
8483
let result = false;
8584
return recorder.add('tryTo', () => {
8685
recorder.session.start('tryTo');
86+
process.env.TRY_TO = 'true';
8787
callback();
8888
recorder.add(() => {
8989
result = true;
@@ -98,6 +98,7 @@ function tryTo(callback) {
9898
return result;
9999
});
100100
return recorder.add('result', () => {
101+
process.env.TRY_TO = undefined;
101102
return result;
102103
}, true, false);
103104
}, false, false);

0 commit comments

Comments
 (0)