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

Commit

Permalink
Revert "feat(core): use native Promise in place of Q"
Browse files Browse the repository at this point in the history
This reverts commit 4e73d5e.
  • Loading branch information
vikerman committed Mar 17, 2017
1 parent 0eb5b76 commit c525ca6
Show file tree
Hide file tree
Showing 21 changed files with 203 additions and 241 deletions.
3 changes: 2 additions & 1 deletion lib/bpRunner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ChildProcess, fork} from 'child_process';
import * as q from 'q';

import {Config} from './config';
import {Logger} from './logger';
Expand All @@ -14,7 +15,7 @@ export class BlockingProxyRunner {
constructor(private config: Config) {}

start() {
return new Promise((resolve, reject) => {
return q.Promise((resolve, reject) => {
this.checkSupportedConfig();

let args = [
Expand Down
4 changes: 2 additions & 2 deletions lib/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1046,8 +1046,8 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver {
clientSideScripts.setLocation, 'Protractor.setLocation()', rootEl, url)
.then((browserErr: Error) => {
if (browserErr) {
const message = `Error while navigating to '${url}'`;
throw `${message} : ${JSON.stringify(browserErr)}`;
throw 'Error while navigating to \'' + url + '\' : ' +
JSON.stringify(browserErr);
}
}));
}
Expand Down
6 changes: 3 additions & 3 deletions lib/driverProviders/attachSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ export class AttachSession extends DriverProvider {

/**
* Configure and launch (if applicable) the object's environment.
* @return {Promise} A promise which will resolve when the environment is
* @return {q.promise} A promise which will resolve when the environment is
* ready to test.
*/
protected setupDriverEnv(): Promise<any> {
protected setupDriverEnv(): q.Promise<any> {
logger.info('Using the selenium server at ' + this.config_.seleniumAddress);
logger.info('Using session id - ' + this.config_.seleniumSessionId);
return Promise.resolve(undefined);
return q(undefined);
}

/**
Expand Down
26 changes: 12 additions & 14 deletions lib/driverProviders/browserStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* it down, and setting up the driver correctly.
*/
import * as https from 'https';
import * as q from 'q';
import {Session, WebDriver} from 'selenium-webdriver';
import * as util from 'util';

Expand All @@ -24,16 +25,11 @@ export class BrowserStack extends DriverProvider {
* Hook to update the BrowserStack job status.
* @public
* @param {Object} update
* @return {Promise} A promise that will resolve when the update is complete.
* @return {q.promise} A promise that will resolve when the update is complete.
*/
updateJob(update: any): Promise<any> {
updateJob(update: any): q.Promise<any> {
let deferredArray = this.drivers_.map((driver: WebDriver) => {
let deferredResolve: (x?: any) => void;
let deferredReject;
let deferred = new Promise((resolve, reject) => {
deferredResolve = resolve;
deferredReject = reject;
});
let deferred = q.defer();
driver.getSession().then((session: Session) => {
let headers: Object = {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -77,7 +73,7 @@ export class BrowserStack extends DriverProvider {
});
res.on('end', () => {
logger.info(responseStr);
deferredResolve();
deferred.resolve();
});
res.on('error', (e: Error) => {
throw new BrowserError(
Expand All @@ -87,17 +83,18 @@ export class BrowserStack extends DriverProvider {
update_req.write('{"status":"' + jobStatus + '"}');
update_req.end();
});
return deferred;
return deferred.promise;
});
return Promise.all(deferredArray);
return q.all(deferredArray);
}

/**
* Configure and launch (if applicable) the object's environment.
* @return {Promise} A promise which will resolve when the environment is
* @return {q.promise} A promise which will resolve when the environment is
* ready to test.
*/
protected setupDriverEnv(): Promise<any> {
protected setupDriverEnv(): q.Promise<any> {
let deferred = q.defer();
this.config_.capabilities['browserstack.user'] = this.config_.browserstackUser;
this.config_.capabilities['browserstack.key'] = this.config_.browserstackKey;
this.config_.seleniumAddress = 'http://hub.browserstack.com/wd/hub';
Expand All @@ -110,6 +107,7 @@ export class BrowserStack extends DriverProvider {
}

logger.info('Using BrowserStack selenium server at ' + this.config_.seleniumAddress);
return Promise.resolve();
deferred.resolve();
return deferred.promise;
}
}
7 changes: 4 additions & 3 deletions lib/driverProviders/direct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import * as fs from 'fs';
import * as path from 'path';
import * as q from 'q';
import {Capabilities, WebDriver} from 'selenium-webdriver';
import {Driver as ChromeDriver, ServiceBuilder as ChromeServiceBuilder} from 'selenium-webdriver/chrome';
import {Driver as FirefoxDriver} from 'selenium-webdriver/firefox';
Expand All @@ -25,10 +26,10 @@ export class Direct extends DriverProvider {

/**
* Configure and launch (if applicable) the object's environment.
* @return {Promise} A promise which will resolve when the environment is
* @return {q.promise} A promise which will resolve when the environment is
* ready to test.
*/
protected setupDriverEnv(): Promise<any> {
protected setupDriverEnv(): q.Promise<any> {
switch (this.config_.capabilities.browserName) {
case 'chrome':
logger.info('Using ChromeDriver directly...');
Expand All @@ -42,7 +43,7 @@ export class Direct extends DriverProvider {
'browserName ' + this.config_.capabilities.browserName +
' is not supported with directConnect.');
}
return Promise.resolve();
return q.fcall(function() {});
}

/**
Expand Down
41 changes: 23 additions & 18 deletions lib/driverProviders/driverProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* It is responsible for setting up the account object, tearing
* it down, and setting up the driver correctly.
*/
import * as q from 'q';
import {Builder, promise as wdpromise, Session, WebDriver} from 'selenium-webdriver';

import {BlockingProxyRunner} from '../bpRunner';
Expand Down Expand Up @@ -88,38 +89,42 @@ export abstract class DriverProvider {


/**
* Quits an array of drivers and returns a native promise instead of a webdriver one
* Quits an array of drivers and returns a q promise instead of a webdriver one
*
* @param drivers {webdriver.WebDriver[]} The webdriver instances
*/
static quitDrivers(provider: DriverProvider, drivers: WebDriver[]): Promise<void> {
let deferredResolve: (x?: any) => void;
let deferredReject: (x?: any) => void;
let deferred = new Promise<void>((resolve, reject) => {
deferredResolve = resolve;
deferredReject = reject;
});
wdpromise.all(drivers.map((driver: WebDriver) => provider.quitDriver(driver)))
.then(() => deferredResolve(), () => deferredReject());
return deferred;
static quitDrivers(provider: DriverProvider, drivers: WebDriver[]): q.Promise<void> {
let deferred = q.defer<void>();
wdpromise
.all(drivers.map((driver: WebDriver) => {
return provider.quitDriver(driver);
}))
.then(
() => {
deferred.resolve();
},
() => {
deferred.resolve();
});
return deferred.promise;
}

/**
* Default update job method.
* @return a promise
*/
updateJob(update: any): Promise<any> {
return Promise.resolve();
updateJob(update: any): q.Promise<any> {
return q.fcall(function() {});
};

/**
* Default setup environment method, common to all driver providers.
*/
setupEnv(): Promise<any> {
setupEnv(): q.Promise<any> {
let driverPromise = this.setupDriverEnv();
if (this.config_.useBlockingProxy && !this.config_.blockingProxyUrl) {
// TODO(heathkit): If set, pass the webDriverProxy to BP.
return Promise.all([driverPromise, this.bpRunner.start()]);
return q.all([driverPromise, this.bpRunner.start()]);
}
return driverPromise;
};
Expand All @@ -128,16 +133,16 @@ export abstract class DriverProvider {
* Set up environment specific to a particular driver provider. Overridden
* by each driver provider.
*/
protected abstract setupDriverEnv(): Promise<any>;
protected abstract setupDriverEnv(): q.Promise<any>;

/**
* Teardown and destroy the environment and do any associated cleanup.
* Shuts down the drivers.
*
* @public
* @return {Promise<any>} A promise which will resolve when the environment is down.
* @return {q.Promise<any>} A promise which will resolve when the environment is down.
*/
teardownEnv(): Promise<any> {
teardownEnv(): q.Promise<any> {
return DriverProvider.quitDrivers(this, this.drivers_);
}
}
8 changes: 5 additions & 3 deletions lib/driverProviders/hosted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* It is responsible for setting up the account object, tearing
* it down, and setting up the driver correctly.
*/
import * as q from 'q';

import {Config} from '../config';
import {Logger} from '../logger';

Expand All @@ -17,11 +19,11 @@ export class Hosted extends DriverProvider {
/**
* Configure and launch (if applicable) the object's environment.
* @public
* @return {Promise} A promise which will resolve when the environment is
* @return {q.promise} A promise which will resolve when the environment is
* ready to test.
*/
protected setupDriverEnv(): Promise<any> {
protected setupDriverEnv(): q.Promise<any> {
logger.info('Using the selenium server at ' + this.config_.seleniumAddress);
return Promise.resolve();
return q.fcall(function() {});
}
}
22 changes: 9 additions & 13 deletions lib/driverProviders/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
import * as fs from 'fs';
import * as path from 'path';
import * as q from 'q';

import {Config} from '../config';
import {BrowserError, ConfigError} from '../exitCodes';
Expand Down Expand Up @@ -90,10 +91,10 @@ export class Local extends DriverProvider {
/**
* Configure and launch (if applicable) the object's environment.
* @public
* @return {Promise} A promise which will resolve when the environment is
* @return {q.promise} A promise which will resolve when the environment is
* ready to test.
*/
setupDriverEnv(): Promise<any> {
setupDriverEnv(): q.Promise<any> {
this.addDefaultBinaryLocs_();
logger.info('Starting selenium standalone server...');

Expand Down Expand Up @@ -122,12 +123,7 @@ export class Local extends DriverProvider {

this.server_ = new remote.SeleniumServer(this.config_.seleniumServerJar, serverConf);

let deferredResolve: (x?: any) => void;
let deferredReject: (err?: any) => void;
let deferred = new Promise((resolve, reject) => {
deferredResolve = resolve;
deferredReject = reject;
});
let deferred = q.defer();
// start local server, grab hosted address, and resolve promise
this.server_.start(this.config_.seleniumServerStartTimeout)
.then((url: string) => {
Expand All @@ -136,13 +132,13 @@ export class Local extends DriverProvider {
})
.then((address: string) => {
this.config_.seleniumAddress = address;
deferredResolve();
deferred.resolve();
})
.catch((err: string) => {
deferredReject(err);
deferred.reject(err);
});

return deferred;
return deferred.promise;
}

/**
Expand All @@ -151,10 +147,10 @@ export class Local extends DriverProvider {
*
* @public
* @override
* @return {Promise} A promise which will resolve when the environment
* @return {q.promise} A promise which will resolve when the environment
* is down.
*/
teardownEnv(): Promise<any> {
teardownEnv(): q.Promise<any> {
return super.teardownEnv().then(() => {
logger.info('Shutting down selenium standalone server.');
return this.server_.stop();
Expand Down
13 changes: 8 additions & 5 deletions lib/driverProviders/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* It returns a fake webdriver and never actually contacts a selenium
* server.
*/
import * as q from 'q';
import {Session, WebDriver} from 'selenium-webdriver';
import * as executors from 'selenium-webdriver/executors';

Expand All @@ -21,17 +22,19 @@ export class Mock extends DriverProvider {
/**
* An execute function that returns a promise with a test value.
*/
execute(): Promise<any> {
return Promise.resolve({value: 'test_response'});
execute(): q.Promise<any> {
let deferred = q.defer();
deferred.resolve({value: 'test_response'});
return deferred.promise;
}

/**
* Configure and launch (if applicable) the object's environment.
* @public
* @return {Promise} A promise which will resolve immediately.
* @return {q.promise} A promise which will resolve immediately.
*/
protected setupDriverEnv(): Promise<any> {
return Promise.resolve();
protected setupDriverEnv(): q.Promise<any> {
return q.fcall(function() {});
}

/**
Expand Down
Loading

2 comments on commit c525ca6

@drypa
Copy link

@drypa drypa commented on c525ca6 Mar 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was some problems?
Why did You revert this?

@seanmay
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent wasn't to get rid of it, but to move it to a branch reserved for breaking changes, for the next major release.
This commit, and the commits that are intended to follow after, will end up making changes that affect the types that TypeScript users of Protractor may expect to see (thus breaking their code). This isn't going away, so to speak.

Please sign in to comment.