@@ -18,12 +18,14 @@ const defaultRetryOptions = {
1818 maxTimeout : 10000 ,
1919} ;
2020
21-
2221/**
2322 * Singleton object to record all test steps as promises and run them in chain.
2423 */
2524module . exports = {
2625
26+ /**
27+ * @var retries Array[object]
28+ */
2729 retries : [ ] ,
2830
2931 /**
@@ -123,6 +125,7 @@ module.exports = {
123125 tasks . push ( taskName ) ;
124126 // log(`${currentQueue()}Queued | ${taskName}`);
125127
128+
126129 return promise = Promise . resolve ( promise ) . then ( ( res ) => {
127130 const retryOpts = this . retries . slice ( - 1 ) . pop ( ) ;
128131 // no retries or unnamed tasks
@@ -132,9 +135,11 @@ module.exports = {
132135
133136 return promiseRetry ( Object . assign ( defaultRetryOptions , retryOpts ) , ( retry , number ) => {
134137 if ( number > 1 ) log ( `${ currentQueue ( ) } Retrying... Attempt #${ number } ` ) ;
138+
139+ const retryRules = this . retries . reverse ( ) ;
140+
135141 return Promise . resolve ( res ) . then ( fn ) . catch ( ( err ) => {
136- // does retry handled or should be thrown
137- for ( const retryObj in this . retries . reverse ( ) ) {
142+ for ( const retryObj of retryRules ) {
138143 if ( ! retryObj . when ) return retry ( err ) ;
139144 if ( retryObj . when && retryObj . when ( err ) ) return retry ( err ) ;
140145 }
@@ -153,7 +158,7 @@ module.exports = {
153158 if ( Number . isInteger ( opts ) ) {
154159 opts = { retries : opts } ;
155160 }
156- return promise . then ( ( ) => this . retries . push ( opts ) ) ;
161+ return this . add ( ( ) => this . retries . push ( opts ) ) ;
157162 } ,
158163
159164 catch ( customErrFn ) {
0 commit comments