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

Commit

Permalink
feat(config): allow onComplete to return a promise
Browse files Browse the repository at this point in the history
Closes #1944
  • Loading branch information
sjelin committed Feb 1, 2016
1 parent 4b79228 commit fa0c692
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/referenceConf.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ exports.config = {
},

// A callback function called once tests are finished.
// onComplete can optionally return a promise, which Protractor will wait for
// before shutting down webdriver.
onComplete: function() {
// At this point, tests will be done but global objects will still be
// available.
Expand Down
2 changes: 2 additions & 0 deletions lib/frameworks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Requirements
- `runner.runTestPreparer` must be called before any tests are run.

- `runner.getConfig().onComplete` must be called when tests are finished.
It might return a promise, in which case `exports.run`'s promise should not
resolve until after `onComplete`'s promise resolves.

- The returned promise must be resolved when tests are finished and it should return a results object. This object must have a `failedCount` property and optionally a `specResults`
object of the following structure:
Expand Down
11 changes: 7 additions & 4 deletions lib/frameworks/jasmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ exports.run = function(runner, specs) {

jrunner.onComplete(function(passed) {
try {
var completed = q();
if (originalOnComplete) {
originalOnComplete(passed);
completed = q(originalOnComplete(passed));
}
resolve({
failedCount: reporter.failedCount,
specResults: reporter.testResult
completed.then(function() {
resolve({
failedCount: reporter.failedCount,
specResults: reporter.testResult
});
});
} catch (err) {
reject(err);
Expand Down
11 changes: 7 additions & 4 deletions lib/frameworks/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ exports.run = function(runner, specs) {

var mochaRunner = mocha.run(function(failures) {
try {
var completed = q();
if (runner.getConfig().onComplete) {
runner.getConfig().onComplete();
completed = q(runner.getConfig().onComplete());
}
deferred.resolve({
failedCount: failures,
specResults: testResult
completed.then(function() {
deferred.resolve({
failedCount: failures,
specResults: testResult
});
});
} catch (err) {
deferred.reject(err);
Expand Down

0 comments on commit fa0c692

Please sign in to comment.