From b97bbe05727e3591d044a018c76ea6f7b3908f4c Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 2 May 2014 19:38:10 -0700 Subject: [PATCH] Add `Jobs#reset`. --- test/saucelabs.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/test/saucelabs.js b/test/saucelabs.js index 5bd041191..a9f20e82a 100644 --- a/test/saucelabs.js +++ b/test/saucelabs.js @@ -433,6 +433,25 @@ function Job(properties) { Job.prototype = _.create(EventEmitter.prototype); +/** + * Resets the job. + * + * @memberOf Job + * @param {Function} callback The function called once the job is reset. + * @param {Object} Returns the job instance. + */ +Job.prototype.reset = function(callback) { + if (this.running) { + return this.stop(_.bind(this.reset, this)); + } + this.attempts = 0; + this.failed = false; + this.id = this.result = this.url = null; + + _.defer(callback); + return this; +}; + /** * Restarts the job. * @@ -580,11 +599,7 @@ function Tunnel(properties) { this.on('stop', function() { completed = 0; success = true; - _.each(all, function(job) { - job.attempts = 0; - job.failed = false; - job.id = job.result = job.url = null; - }); + _.invoke(all, 'reset'); }); this.jobs = {'active': active, 'all': all, 'queue': queue };