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

Commit fa0c692

Browse files
committed
feat(config): allow onComplete to return a promise
Closes #1944
1 parent 4b79228 commit fa0c692

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

docs/referenceConf.js

+2
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ exports.config = {
248248
},
249249

250250
// A callback function called once tests are finished.
251+
// onComplete can optionally return a promise, which Protractor will wait for
252+
// before shutting down webdriver.
251253
onComplete: function() {
252254
// At this point, tests will be done but global objects will still be
253255
// available.

lib/frameworks/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Requirements
2828
- `runner.runTestPreparer` must be called before any tests are run.
2929

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

3234
- 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`
3335
object of the following structure:

lib/frameworks/jasmine.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,15 @@ exports.run = function(runner, specs) {
9696

9797
jrunner.onComplete(function(passed) {
9898
try {
99+
var completed = q();
99100
if (originalOnComplete) {
100-
originalOnComplete(passed);
101+
completed = q(originalOnComplete(passed));
101102
}
102-
resolve({
103-
failedCount: reporter.failedCount,
104-
specResults: reporter.testResult
103+
completed.then(function() {
104+
resolve({
105+
failedCount: reporter.failedCount,
106+
specResults: reporter.testResult
107+
});
105108
});
106109
} catch (err) {
107110
reject(err);

lib/frameworks/mocha.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,15 @@ exports.run = function(runner, specs) {
5252

5353
var mochaRunner = mocha.run(function(failures) {
5454
try {
55+
var completed = q();
5556
if (runner.getConfig().onComplete) {
56-
runner.getConfig().onComplete();
57+
completed = q(runner.getConfig().onComplete());
5758
}
58-
deferred.resolve({
59-
failedCount: failures,
60-
specResults: testResult
59+
completed.then(function() {
60+
deferred.resolve({
61+
failedCount: failures,
62+
specResults: testResult
63+
});
6164
});
6265
} catch (err) {
6366
deferred.reject(err);

0 commit comments

Comments
 (0)