@@ -192,7 +192,7 @@ class NodeTestHelper extends EventEmitter {
192
192
return this . _settings ;
193
193
}
194
194
195
- load ( testNode , testFlow , testCredentials , cb ) {
195
+ async load ( testNode , testFlow , testCredentials , cb ) {
196
196
const log = this . _log ;
197
197
const logSpy = this . _logSpy = this . _sandbox . spy ( log , 'log' ) ;
198
198
logSpy . FATAL = log . FATAL ;
@@ -314,13 +314,16 @@ class NodeTestHelper extends EventEmitter {
314
314
}
315
315
}
316
316
} ) ;
317
- return Promise . all ( initPromises )
318
- . then ( ( ) => redNodes . loadFlows ( ) )
319
- . then ( ( ) => redNodes . startFlows ( ) )
320
- . then ( ( ) => {
321
- should . deepEqual ( testFlow , redNodes . getFlows ( ) . flows ) ;
322
- if ( cb ) cb ( ) ;
323
- } ) ;
317
+ try {
318
+ await Promise . all ( initPromises ) ;
319
+ await redNodes . loadFlows ( ) ;
320
+ await redNodes . startFlows ( ) ;
321
+ should . deepEqual ( testFlow , redNodes . getFlows ( ) . flows ) ;
322
+ if ( cb ) cb ( ) ;
323
+ } catch ( error ) {
324
+ if ( cb ) cb ( error ) ;
325
+ else throw error ;
326
+ }
324
327
}
325
328
326
329
unload ( ) {
@@ -355,7 +358,7 @@ class NodeTestHelper extends EventEmitter {
355
358
* @param {function } [cb] Optional callback (not required when called with await)
356
359
* @returns {Promise }
357
360
*/
358
- setFlows ( testFlow , type , testCredentials , cb ) {
361
+ async setFlows ( testFlow , type , testCredentials , cb ) {
359
362
const helper = this ;
360
363
if ( typeof testCredentials === 'string' ) {
361
364
cb = testCredentials ;
@@ -383,18 +386,22 @@ class NodeTestHelper extends EventEmitter {
383
386
helper . _events . on ( 'flows:started' , hander ) ; // call resolve when its done
384
387
} ) ;
385
388
}
386
- return this . _redNodes . setFlows ( testFlow , testCredentials || { } , type )
387
- . then ( waitStarted )
388
- . then ( ( ) => {
389
- if ( cb ) cb ( ) ;
390
- } ) ;
389
+ try {
390
+ await this . _redNodes . setFlows ( testFlow , testCredentials || { } , type ) ;
391
+ await waitStarted ( ) ;
392
+
393
+ if ( cb ) cb ( ) ;
394
+ } catch ( error ) {
395
+ if ( cb ) cb ( error ) ;
396
+ else throw error ;
397
+ }
391
398
}
392
399
393
400
request ( ) {
394
401
return request ( this . _httpAdmin ) ;
395
402
}
396
403
397
- async startServer ( done ) {
404
+ async startServer ( cb ) {
398
405
try {
399
406
await new Promise ( ( resolve , reject ) => {
400
407
this . _app = express ( ) ;
@@ -419,30 +426,30 @@ class NodeTestHelper extends EventEmitter {
419
426
server . on ( 'error' , reject ) ;
420
427
} ) ;
421
428
422
- if ( done ) done ( ) ;
423
- } catch ( err ) {
424
- if ( done ) done ( err ) ;
425
- else throw err ;
429
+ if ( cb ) cb ( ) ;
430
+ } catch ( error ) {
431
+ if ( cb ) cb ( error ) ;
432
+ else throw error ;
426
433
}
427
434
}
428
435
429
- async stopServer ( done ) {
436
+ async stopServer ( cb ) {
430
437
try {
431
438
if ( this . _server ) {
432
439
await new Promise ( ( resolve , reject ) => {
433
440
this . _comms . stop ( ) ;
434
441
435
- this . _server . stop ( ( err ) => {
436
- if ( err ) reject ( err ) ;
442
+ this . _server . stop ( ( error ) => {
443
+ if ( error ) reject ( error ) ;
437
444
else resolve ( ) ;
438
445
} ) ;
439
446
} ) ;
440
447
}
441
448
442
- if ( done ) done ( ) ;
443
- } catch ( err ) {
444
- if ( done ) done ( err ) ;
445
- else throw err ;
449
+ if ( cb ) cb ( ) ;
450
+ } catch ( error ) {
451
+ if ( cb ) cb ( error ) ;
452
+ else throw error ;
446
453
}
447
454
}
448
455
0 commit comments