4
4
* Module dependencies.
5
5
* @private
6
6
*/
7
- var util = require ( 'util' ) ;
8
7
var EventEmitter = require ( 'events' ) . EventEmitter ;
9
8
var Pending = require ( './pending' ) ;
10
9
var utils = require ( './utils' ) ;
@@ -19,8 +18,6 @@ var EVENT_ROOT_SUITE_RUN = Suite.constants.EVENT_ROOT_SUITE_RUN;
19
18
var STATE_FAILED = Runnable . constants . STATE_FAILED ;
20
19
var STATE_PASSED = Runnable . constants . STATE_PASSED ;
21
20
var STATE_PENDING = Runnable . constants . STATE_PENDING ;
22
- var dQuote = utils . dQuote ;
23
- var sQuote = utils . sQuote ;
24
21
var stackFilter = utils . stackTraceFilter ( ) ;
25
22
var stringify = utils . stringify ;
26
23
@@ -140,6 +137,7 @@ class Runner extends EventEmitter {
140
137
* @param {Suite } suite - Root suite
141
138
* @param {Object|boolean } [opts] - Options. If `boolean` (deprecated), whether or not to delay execution of root suite until ready.
142
139
* @param {boolean } [opts.delay] - Whether to delay execution of root suite until ready.
140
+ * @param {boolean } [opts.dryRun] - Whether to report tests without running them.
143
141
* @param {boolean } [opts.cleanReferencesAfterRun] - Whether to clean references to test fns and hooks when a suite is done.
144
142
*/
145
143
constructor ( suite , opts ) {
@@ -410,9 +408,8 @@ Runner.prototype.checkGlobals = function(test) {
410
408
this . _globals = this . _globals . concat ( leaks ) ;
411
409
412
410
if ( leaks . length ) {
413
- var msg = 'global leak(s) detected: %s' ;
414
- var error = new Error ( util . format ( msg , leaks . map ( sQuote ) . join ( ', ' ) ) ) ;
415
- this . fail ( test , error ) ;
411
+ var msg = `global leak(s) detected: ${ leaks . map ( e => `'${ e } '` ) . join ( ', ' ) } ` ;
412
+ this . fail ( test , new Error ( msg ) ) ;
416
413
}
417
414
} ;
418
415
@@ -479,6 +476,8 @@ Runner.prototype.fail = function(test, err, force) {
479
476
*/
480
477
481
478
Runner . prototype . hook = function ( name , fn ) {
479
+ if ( this . _opts . dryRun ) return fn ( ) ;
480
+
482
481
var suite = this . suite ;
483
482
var hooks = suite . getHooks ( name ) ;
484
483
var self = this ;
@@ -557,16 +556,15 @@ Runner.prototype.hook = function(name, fn) {
557
556
function setHookTitle ( hook ) {
558
557
hook . originalTitle = hook . originalTitle || hook . title ;
559
558
if ( hook . ctx && hook . ctx . currentTest ) {
560
- hook . title =
561
- hook . originalTitle + ' for ' + dQuote ( hook . ctx . currentTest . title ) ;
559
+ hook . title = `${ hook . originalTitle } for "${ hook . ctx . currentTest . title } "` ;
562
560
} else {
563
561
var parentTitle ;
564
562
if ( hook . parent . title ) {
565
563
parentTitle = hook . parent . title ;
566
564
} else {
567
565
parentTitle = hook . parent . root ? '{root}' : '' ;
568
566
}
569
- hook . title = hook . originalTitle + ' in ' + dQuote ( parentTitle ) ;
567
+ hook . title = ` ${ hook . originalTitle } in " ${ parentTitle } "` ;
570
568
}
571
569
}
572
570
}
@@ -612,7 +610,7 @@ Runner.prototype.hooks = function(name, suites, fn) {
612
610
} ;
613
611
614
612
/**
615
- * Run hooks from the top level down .
613
+ * Run 'afterEach' hooks from bottom up .
616
614
*
617
615
* @param {String } name
618
616
* @param {Function } fn
@@ -624,7 +622,7 @@ Runner.prototype.hookUp = function(name, fn) {
624
622
} ;
625
623
626
624
/**
627
- * Run hooks from the bottom up .
625
+ * Run 'beforeEach' hooks from top level down .
628
626
*
629
627
* @param {String } name
630
628
* @param {Function } fn
@@ -659,6 +657,8 @@ Runner.prototype.parents = function() {
659
657
* @private
660
658
*/
661
659
Runner . prototype . runTest = function ( fn ) {
660
+ if ( this . _opts . dryRun ) return fn ( ) ;
661
+
662
662
var self = this ;
663
663
var test = this . test ;
664
664
@@ -704,7 +704,6 @@ Runner.prototype.runTests = function(suite, fn) {
704
704
self . suite = after ? errSuite . parent : errSuite ;
705
705
706
706
if ( self . suite ) {
707
- // call hookUp afterEach
708
707
self . hookUp ( HOOK_TYPE_AFTER_EACH , function ( err2 , errSuite2 ) {
709
708
self . suite = orig ;
710
709
// some hooks may fail even now
0 commit comments