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

Commit

Permalink
chore(frameworks): allow frameworks to call afterEach. (#3906)
Browse files Browse the repository at this point in the history
Follow up to #3893.

Part of #3893
  • Loading branch information
sjelin authored Jan 18, 2017
1 parent 9a73d41 commit d868ab9
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion lib/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export class Runner extends EventEmitter {
driverprovider_: DriverProvider;
o: any;
plugins_: Plugins;
restartPromise: q.Promise<any>;
frameworkUsesAfterEach: boolean;

constructor(config: Config) {
super();
Expand Down Expand Up @@ -86,6 +88,26 @@ export class Runner extends EventEmitter {
});
}

/**
* Called after each test finishes.
*
* Responsible for `restartBrowserBetweenTests`
*
* @public
* @return {q.Promise} A promise that will resolve when the work here is done
*/
afterEach(): q.Promise<void> {
let ret: q.Promise<void>;
this.frameworkUsesAfterEach = true;
if (this.config_.restartBrowserBetweenTests) {
// TODO(sjelin): remove the `|| q()` once `restart()` returns a promise
this.restartPromise = this.restartPromise || protractor.browser.restart() || q();
ret = this.restartPromise;
this.restartPromise = undefined;
}
return ret || q();
}

/**
* Grab driver provider based on type
* @private
Expand Down Expand Up @@ -322,8 +344,12 @@ export class Runner extends EventEmitter {
}

if (this.config_.restartBrowserBetweenTests) {
// TODO(sjelin): replace with warnings once `afterEach` support is required
let restartDriver = () => {
browser_.restart();
if (!this.frameworkUsesAfterEach) {
// TODO(sjelin): remove the `|| q()` once `restart()` returns a promise
this.restartPromise = browser_.restart() || q();
}
};
this.on('testPass', restartDriver);
this.on('testFail', restartDriver);
Expand Down

0 comments on commit d868ab9

Please sign in to comment.