-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,35 +52,23 @@ util.inherits(Runner, EventEmitter); | |
/** | ||
* Internal helper for abstraction of polymorphic filenameOrFn properties. | ||
* @private | ||
* @param {Array} source The Array that we'll be iterating through | ||
* as we evaluate whether to require or execute each item. | ||
* @return {q.Promise} A promise that will resolve when the test preparers | ||
* are finished. | ||
* @param {object} filenameOrFn The filename or function that we will execute. | ||
* @return {object} A number or a promise that will resolve when the test | ||
* preparers are finished. | ||
*/ | ||
Runner.prototype.runFilenamesOrFns_ = function(source) { | ||
var filenameOrFn; | ||
var promises = []; | ||
var returned; | ||
for (var i = 0; i < source.length; i++) { | ||
filenameOrFn = source[i]; | ||
if (filenameOrFn) { | ||
if (typeof filenameOrFn === 'function') { | ||
returned = filenameOrFn(); | ||
} else if (typeof filenameOrFn === 'string') { | ||
returned = require(path.resolve(this.config_.configDir, filenameOrFn)); | ||
} else { | ||
// TODO - this is not generic. | ||
throw 'config.onPrepare must be a string or function'; | ||
} | ||
if (q.isPromiseAlike(returned)) { | ||
promises.push(returned); | ||
} | ||
Runner.prototype.runFilenameOrFn_ = function(filenameOrFn, args) { | ||
if (filenameOrFn) { | ||
if (typeof filenameOrFn === 'function') { | ||
return filenameOrFn.apply(null, args); | ||
} else if (typeof filenameOrFn === 'string') { | ||
return require(path.resolve(this.config_.configDir, filenameOrFn)); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
hankduan
Author
Contributor
|
||
} else { | ||
// TODO - this is not generic. | ||
throw 'config.onPrepare and config.onCleanUp must be a string or function'; | ||
} | ||
} | ||
return q.all(promises); | ||
}; | ||
|
||
|
||
/** | ||
* Registrar for testPreparers - executed right before tests run. | ||
* @public | ||
|
@@ -98,7 +86,17 @@ Runner.prototype.registerTestPreparer = function(filenameOrFn) { | |
* are finished. | ||
*/ | ||
Runner.prototype.runTestPreparers = function() { | ||
return this.runFilenamesOrFns_(this.preparers_); | ||
var filenameOrFn; | ||
var promises = []; | ||
var returned; | ||
for (var i = 0; i < this.preparers_.length; i++) { | ||
filenameOrFn = this.preparers_[i]; | ||
returned = this.runFilenameOrFn_(filenameOrFn); | ||
if (q.isPromiseAlike(returned)) { | ||
promises.push(returned); | ||
} | ||
} | ||
return q.all(promises); | ||
}; | ||
|
||
|
||
|
@@ -139,13 +137,12 @@ Runner.prototype.loadDriverProvider_ = function() { | |
* @param {int} Standard unix exit code | ||
*/ | ||
Runner.prototype.exit_ = function(exitCode) { | ||
if (typeof this.config_.onCleanUp === 'function') { | ||
var val = this.config_.onCleanUp(exitCode); | ||
if (typeof val === 'number' || q.isPromiseAlike(val)) { | ||
return val; | ||
} | ||
var returned = this.runFilenameOrFn_(this.config_.onCleanUp, [exitCode]); | ||
if (typeof returned === 'number' || q.isPromiseAlike(returned)) { | ||
return returned; | ||
} else { | ||
return exitCode; | ||
} | ||
return exitCode; | ||
}; | ||
|
||
|
||
|
Looks like you're not applying args here.
This feature is not working for me, I've merged from master.
Could you add a test case so I figure what should I be exporting from the custom
onCleanUp.js
external file?