Skip to content

Commit

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

// A callback function called once tests are finished.
// onComplete can optionally return a promise, which Protractor will wait for.
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 the returned 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 {
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 0fb4508

Please sign in to comment.