Skip to content

Commit a581d6d

Browse files
author
DavertMik
committed
fixed tryTo/retryTo regressions
1 parent 8f57281 commit a581d6d

File tree

11 files changed

+100
-37
lines changed

11 files changed

+100
-37
lines changed

bin/codecept.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ program
6262
.command('check')
6363
.option(commandFlags.config.flag, commandFlags.config.description)
6464
.description('Checks configuration and environment before running tests')
65-
.option('-t, --timeout [ms]', 'timeout for checks in ms, 20000 by default')
65+
.option('-t, --timeout [ms]', 'timeout for checks in ms, 50000 by default')
6666
.action(errorHandler(require('../lib/command/check')))
6767

6868
program

lib/command/check.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ module.exports = async function (options) {
8787

8888
if (config?.ai?.request) {
8989
checks.ai = true
90-
printCheck('ai', checks['ai'], 'AI configuration is enabled, request function is set')
90+
printCheck('ai', checks['ai'], 'Configuration is enabled, request function is set')
9191
} else {
92-
printCheck('ai', checks['ai'], 'AI is disabled')
92+
printCheck('ai', checks['ai'], 'Disabled')
9393
}
9494

9595
printCheck('tests', checks['tests'], `Total: ${numTests} tests`)

lib/effects.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const recorder = require('./recorder')
22
const { debug } = require('./output')
33
const store = require('./store')
44
const event = require('./event')
5+
const within = require('./within')
56

67
/**
78
* A utility function for CodeceptJS tests that acts as a soft assertion.
@@ -178,11 +179,14 @@ async function tryTo(callback) {
178179
const sessionName = 'tryTo'
179180

180181
let result = false
182+
let hasAutoRetriesEnabled = store.autoRetries
181183
return recorder.add(
182184
sessionName,
183185
() => {
184186
recorder.session.start(sessionName)
185-
store.tryTo = true
187+
hasAutoRetriesEnabled = store.autoRetries
188+
if (hasAutoRetriesEnabled) debug('Auto retries disabled inside tryTo effect')
189+
store.autoRetries = false
186190
callback()
187191
recorder.add(() => {
188192
result = true
@@ -199,7 +203,7 @@ async function tryTo(callback) {
199203
return recorder.add(
200204
'result',
201205
() => {
202-
store.tryTo = undefined
206+
store.autoRetries = hasAutoRetriesEnabled
203207
return result
204208
},
205209
true,
@@ -215,4 +219,5 @@ module.exports = {
215219
hopeThat,
216220
retryTo,
217221
tryTo,
222+
within,
218223
}

lib/helper/Playwright.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ class Playwright extends Helper {
484484
this.currentRunningTest = test
485485

486486
recorder.retry({
487-
retries: process.env.FAILED_STEP_RETRIES || 3,
487+
retries: test.opts?.conditionalRetries || 3,
488488
when: err => {
489489
if (!err || typeof err.message !== 'string') {
490490
return false

lib/helper/Puppeteer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ class Puppeteer extends Helper {
312312
this.sessionPages = {}
313313
this.currentRunningTest = test
314314
recorder.retry({
315-
retries: process.env.FAILED_STEP_RETRIES || 3,
315+
retries: test.opts?.conditionalRetries || 3,
316316
when: err => {
317317
if (!err || typeof err.message !== 'string') {
318318
return false

lib/plugin/retryFailedStep.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const event = require('../event')
22
const recorder = require('../recorder')
3-
const container = require('../container')
4-
const { log } = require('../output')
5-
3+
const store = require('../store')
64
const defaultConfig = {
75
retries: 3,
86
defaultIgnoredSteps: ['amOnPage', 'wait*', 'send*', 'execute*', 'run*', 'have*'],
@@ -70,9 +68,9 @@ const defaultConfig = {
7068
* Use scenario configuration to disable plugin for a test
7169
*
7270
* ```js
73-
* Scenario('scenario tite', () => {
71+
* Scenario('scenario tite', { disableRetryFailedStep: true }, () => {
7472
* // test goes here
75-
* }).config(test => test.disableRetryFailedStep = true)
73+
* })
7674
* ```
7775
*
7876
*/
@@ -85,19 +83,14 @@ module.exports = config => {
8583

8684
const when = err => {
8785
if (!enableRetry) return
88-
const store = require('../store')
8986
if (store.debugMode) return false
87+
if (!store.autoRetries) return false
9088
if (customWhen) return customWhen(err)
9189
return true
9290
}
9391
config.when = when
9492

9593
event.dispatcher.on(event.step.started, step => {
96-
if (process.env.TRY_TO === 'true') {
97-
log('Info: RetryFailedStep plugin is disabled inside tryTo block')
98-
return
99-
}
100-
10194
// if a step is ignored - return
10295
for (const ignored of config.ignoredSteps) {
10396
if (step.name === ignored) return
@@ -113,9 +106,13 @@ module.exports = config => {
113106
})
114107

115108
event.dispatcher.on(event.test.before, test => {
116-
if (test && test.disableRetryFailedStep) return // disable retry when a test is not active
117-
// this env var is used to set the retries inside _before() block of helpers
118-
process.env.FAILED_STEP_RETRIES = config.retries
109+
if (test.opts.disableRetryFailedStep) {
110+
store.autoRetries = false
111+
return // disable retry when a test is not active
112+
}
113+
// this option is used to set the retries inside _before() block of helpers
114+
store.autoRetries = true
115+
test.opts.conditionalRetries = config.retries
119116
recorder.retry(config)
120117
})
121118
}

lib/recorder.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ module.exports = {
192192
.pop()
193193
// no retries or unnamed tasks
194194
debug(`${currentQueue()} Running | ${taskName} | Timeout: ${timeout || 'None'}`)
195+
if (retryOpts) debug(`${currentQueue()} Retry opts`, JSON.stringify(retryOpts))
195196

196197
if (!retryOpts || !taskName || !retry) {
197198
const [promise, timer] = getTimeoutPromise(timeout, taskName)

lib/store.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,41 @@
33
* @namespace
44
*/
55
const store = {
6-
/** @type {boolean} */
6+
/**
7+
* If we are in --debug mode
8+
* @type {boolean}
9+
*/
710
debugMode: false,
8-
/** @type {boolean} */
11+
12+
/**
13+
* Is timeouts enabled
14+
* @type {boolean}
15+
*/
916
timeouts: true,
10-
/** @type {boolean} */
17+
18+
/**
19+
* If auto-retries are enabled by retryFailedStep plugin
20+
* tryTo effect disables them
21+
* @type {boolean}
22+
*/
23+
autoRetries: false,
24+
25+
/**
26+
* Tests are executed via dry-run
27+
* @type {boolean}
28+
*/
1129
dryRun: false,
12-
/** @type {boolean} */
30+
/**
31+
* If we are in pause mode
32+
* @type {boolean}
33+
*/
1334
onPause: false,
35+
36+
// current object states
37+
1438
/** @type {CodeceptJS.Test | null} */
1539
currentTest: null,
16-
/** @type {any} */
40+
/** @type {CodeceptJS.Step | null} */
1741
currentStep: null,
1842
/** @type {CodeceptJS.Suite | null} */
1943
currentSuite: null,

lib/within.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const MetaStep = require('./step/meta')
77
const { isAsyncFunction } = require('./utils')
88

99
/**
10+
* TODO: move to effects
11+
*
1012
* @param {CodeceptJS.LocatorOrString} context
1113
* @param {Function} fn
1214
* @return {Promise<*> | undefined}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codeceptjs",
3-
"version": "3.7.0-beta.14",
3+
"version": "3.7.0-beta.15",
44
"description": "Supercharged End 2 End Testing Framework for NodeJS",
55
"keywords": [
66
"acceptance",

0 commit comments

Comments
 (0)