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

Commit d868ab9

Browse files
authored
chore(frameworks): allow frameworks to call afterEach. (#3906)
Follow up to #3893. Part of #3893
1 parent 9a73d41 commit d868ab9

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

Diff for: lib/runner.ts

+27-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export class Runner extends EventEmitter {
3333
driverprovider_: DriverProvider;
3434
o: any;
3535
plugins_: Plugins;
36+
restartPromise: q.Promise<any>;
37+
frameworkUsesAfterEach: boolean;
3638

3739
constructor(config: Config) {
3840
super();
@@ -86,6 +88,26 @@ export class Runner extends EventEmitter {
8688
});
8789
}
8890

91+
/**
92+
* Called after each test finishes.
93+
*
94+
* Responsible for `restartBrowserBetweenTests`
95+
*
96+
* @public
97+
* @return {q.Promise} A promise that will resolve when the work here is done
98+
*/
99+
afterEach(): q.Promise<void> {
100+
let ret: q.Promise<void>;
101+
this.frameworkUsesAfterEach = true;
102+
if (this.config_.restartBrowserBetweenTests) {
103+
// TODO(sjelin): remove the `|| q()` once `restart()` returns a promise
104+
this.restartPromise = this.restartPromise || protractor.browser.restart() || q();
105+
ret = this.restartPromise;
106+
this.restartPromise = undefined;
107+
}
108+
return ret || q();
109+
}
110+
89111
/**
90112
* Grab driver provider based on type
91113
* @private
@@ -322,8 +344,12 @@ export class Runner extends EventEmitter {
322344
}
323345

324346
if (this.config_.restartBrowserBetweenTests) {
347+
// TODO(sjelin): replace with warnings once `afterEach` support is required
325348
let restartDriver = () => {
326-
browser_.restart();
349+
if (!this.frameworkUsesAfterEach) {
350+
// TODO(sjelin): remove the `|| q()` once `restart()` returns a promise
351+
this.restartPromise = browser_.restart() || q();
352+
}
327353
};
328354
this.on('testPass', restartDriver);
329355
this.on('testFail', restartDriver);

0 commit comments

Comments
 (0)