@@ -52,35 +52,23 @@ util.inherits(Runner, EventEmitter);
52
52
/**
53
53
* Internal helper for abstraction of polymorphic filenameOrFn properties.
54
54
* @private
55
- * @param {Array } source The Array that we'll be iterating through
56
- * as we evaluate whether to require or execute each item.
57
- * @return {q.Promise } A promise that will resolve when the test preparers
58
- * are finished.
55
+ * @param {object } filenameOrFn The filename or function that we will execute.
56
+ * @return {object } A number or a promise that will resolve when the test
57
+ * preparers are finished.
59
58
*/
60
- Runner . prototype . runFilenamesOrFns_ = function ( source ) {
61
- var filenameOrFn ;
62
- var promises = [ ] ;
63
- var returned ;
64
- for ( var i = 0 ; i < source . length ; i ++ ) {
65
- filenameOrFn = source [ i ] ;
66
- if ( filenameOrFn ) {
67
- if ( typeof filenameOrFn === 'function' ) {
68
- returned = filenameOrFn ( ) ;
69
- } else if ( typeof filenameOrFn === 'string' ) {
70
- returned = require ( path . resolve ( this . config_ . configDir , filenameOrFn ) ) ;
71
- } else {
72
- // TODO - this is not generic.
73
- throw 'config.onPrepare must be a string or function' ;
74
- }
75
- if ( q . isPromiseAlike ( returned ) ) {
76
- promises . push ( returned ) ;
77
- }
59
+ Runner . prototype . runFilenameOrFn_ = function ( filenameOrFn , args ) {
60
+ if ( filenameOrFn ) {
61
+ if ( typeof filenameOrFn === 'function' ) {
62
+ return filenameOrFn . apply ( null , args ) ;
63
+ } else if ( typeof filenameOrFn === 'string' ) {
64
+ return require ( path . resolve ( this . config_ . configDir , filenameOrFn ) ) ;
65
+ } else {
66
+ // TODO - this is not generic.
67
+ throw 'config.onPrepare and config.onCleanUp must be a string or function' ;
78
68
}
79
69
}
80
- return q . all ( promises ) ;
81
70
} ;
82
71
83
-
84
72
/**
85
73
* Registrar for testPreparers - executed right before tests run.
86
74
* @public
@@ -98,7 +86,17 @@ Runner.prototype.registerTestPreparer = function(filenameOrFn) {
98
86
* are finished.
99
87
*/
100
88
Runner . prototype . runTestPreparers = function ( ) {
101
- return this . runFilenamesOrFns_ ( this . preparers_ ) ;
89
+ var filenameOrFn ;
90
+ var promises = [ ] ;
91
+ var returned ;
92
+ for ( var i = 0 ; i < this . preparers_ . length ; i ++ ) {
93
+ filenameOrFn = this . preparers_ [ i ] ;
94
+ returned = this . runFilenameOrFn_ ( filenameOrFn ) ;
95
+ if ( q . isPromiseAlike ( returned ) ) {
96
+ promises . push ( returned ) ;
97
+ }
98
+ }
99
+ return q . all ( promises ) ;
102
100
} ;
103
101
104
102
@@ -139,13 +137,12 @@ Runner.prototype.loadDriverProvider_ = function() {
139
137
* @param {int } Standard unix exit code
140
138
*/
141
139
Runner . prototype . exit_ = function ( exitCode ) {
142
- if ( typeof this . config_ . onCleanUp === 'function' ) {
143
- var val = this . config_ . onCleanUp ( exitCode ) ;
144
- if ( typeof val === 'number' || q . isPromiseAlike ( val ) ) {
145
- return val ;
146
- }
140
+ var returned = this . runFilenameOrFn_ ( this . config_ . onCleanUp , [ exitCode ] ) ;
141
+ if ( typeof returned === 'number' || q . isPromiseAlike ( returned ) ) {
142
+ return returned ;
143
+ } else {
144
+ return exitCode ;
147
145
}
148
- return exitCode ;
149
146
} ;
150
147
151
148
0 commit comments