Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
feat(runner): Add support for async onCleanUp functions
Browse files Browse the repository at this point in the history
If the onCleanUp function returns a promise, the process will allow it to resolve before exiting. This is useful for performing async operations like writing to a file or calling an API at the end of a test run.
  • Loading branch information
bclinkinbeard authored and juliemr committed Aug 4, 2014
1 parent cd575ee commit 6de2e32
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,12 @@ Runner.prototype.loadDriverProvider_ = function() {
*/
Runner.prototype.exit_ = function(exitCode) {
if (typeof this.config_.onCleanUp === 'function') {
this.config_.onCleanUp(exitCode);
var val = this.config_.onCleanUp(exitCode);
if (typeof val === 'number' || q.isPromiseAlike(val)) {
return val;
}
}
return exitCode;
};


Expand Down Expand Up @@ -277,8 +281,7 @@ Runner.prototype.run = function() {
}).then(function() {
var passed = testResult.failedCount === 0;
var exitCode = passed ? 0 : 1;
self.exit_(exitCode);
return exitCode;
return q.when(self.exit_(exitCode));
});
};

Expand Down
3 changes: 3 additions & 0 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ var scripts = [
'node lib/cli.js spec/basicConf.js',
'node lib/cli.js spec/multiConf.js',
'node lib/cli.js spec/altRootConf.js',
'node lib/cli.js spec/onCleanUpAsyncReturnValueConf.js',
'node lib/cli.js spec/onCleanUpNoReturnValueConf.js',
'node lib/cli.js spec/onCleanUpSyncReturnValueConf.js',
'node lib/cli.js spec/onPrepareConf.js',
'node lib/cli.js spec/onPrepareFileConf.js',
'node lib/cli.js spec/onPreparePromiseConf.js',
Expand Down
5 changes: 5 additions & 0 deletions spec/onCleanUp/onCleanUp_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('onCleanUp function in the config', function() {
it('should not be affected by tests', function() {
expect(true).toBe(true);
});
});
23 changes: 23 additions & 0 deletions spec/onCleanUpAsyncReturnValueConf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var env = require('./environment.js');
var q = require('q');

// The main suite of Protractor tests.
exports.config = {
seleniumAddress: env.seleniumAddress,

specs: [
'onCleanUp/*_spec.js'
],

capabilities: env.capabilities,

baseUrl: env.baseUrl,

onCleanUp: function(exitCode) {
var deferred = q.defer();
setTimeout(function () {
deferred.resolve(exitCode);
}, 500);
return deferred.promise;
}
};
18 changes: 18 additions & 0 deletions spec/onCleanUpNoReturnValueConf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var env = require('./environment.js');

// The main suite of Protractor tests.
exports.config = {
seleniumAddress: env.seleniumAddress,

specs: [
'onCleanUp/*_spec.js'
],

capabilities: env.capabilities,

baseUrl: env.baseUrl,

onCleanUp: function(exitCode) {
// no return
}
};
18 changes: 18 additions & 0 deletions spec/onCleanUpSyncReturnValueConf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var env = require('./environment.js');

// The main suite of Protractor tests.
exports.config = {
seleniumAddress: env.seleniumAddress,

specs: [
'onCleanUp/*_spec.js'
],

capabilities: env.capabilities,

baseUrl: env.baseUrl,

onCleanUp: function(exitCode) {
return exitCode;
}
};

0 comments on commit 6de2e32

Please sign in to comment.