Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(yarn): download browsers to package directories #1133

Merged
merged 2 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const {Playwright} = require('./lib/server/playwright.js');

const { helper } = require('./lib/helper');
const api = require('./lib/api');
const packageJson = require('./package.json');
const { DeviceDescriptors } = require('./lib/deviceDescriptors');
const { TimeoutError } = require('./lib/errors');
const { Chromium } = require('./lib/server/chromium');
const { Firefox } = require('./lib/server/firefox');
const { WebKit } = require('./lib/server/webkit');
module.exports = new Playwright({
downloadPath: __dirname,
browsers: ['webkit', 'chromium', 'firefox'],
});

for (const className in api) {
if (typeof api[className] === 'function')
helper.installApiHooks(className[0].toLowerCase() + className.substring(1), api[className]);
}

module.exports = {
devices: DeviceDescriptors,
errors: { TimeoutError },
selectors: api.Selectors._instance(),
chromium: new Chromium(__dirname, packageJson.playwright.chromium_revision),
firefox: new Firefox(__dirname, packageJson.playwright.firefox_revision),
webkit: new WebKit(__dirname, packageJson.playwright.webkit_revision),
}
13 changes: 7 additions & 6 deletions packages/playwright-chromium/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
* limitations under the License.
*/

module.exports = {
...require('playwright-core'),
// Keep exporting Chromium and nullify other browsers.
webkit: undefined,
firefox: undefined,
}
const {Playwright} = require('playwright-core/lib/server/playwright.js');

module.exports = new Playwright({
downloadPath: __dirname,
browsers: ['chromium'],
});

13 changes: 7 additions & 6 deletions packages/playwright-firefox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
* limitations under the License.
*/

module.exports = {
...require('playwright-core'),
// Keep exporting firefox and nullify other browsers.
chromium: undefined,
webkit: undefined,
}
const {Playwright} = require('playwright-core/lib/server/playwright.js');

module.exports = new Playwright({
downloadPath: __dirname,
browsers: ['firefox'],
});

13 changes: 7 additions & 6 deletions packages/playwright-webkit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
* limitations under the License.
*/

module.exports = {
...require('playwright-core'),
// Keep exporting webkit and nullify other browsers.
chromium: undefined,
firefox: undefined,
}
const {Playwright} = require('playwright-core/lib/server/playwright.js');

module.exports = new Playwright({
downloadPath: __dirname,
browsers: ['webkit'],
});

8 changes: 7 additions & 1 deletion packages/playwright/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
module.exports = require('playwright-core');
const {Playwright} = require('playwright-core/lib/server/playwright.js');

module.exports = new Playwright({
downloadPath: __dirname,
browsers: ['webkit', 'chromium', 'firefox'],
});

8 changes: 4 additions & 4 deletions src/server/chromium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ import { ConnectionTransport } from '../transport';
import { BrowserContext } from '../browserContext';

export class Chromium implements BrowserType {
private _projectRoot: string;
private _downloadPath: string;
readonly _revision: string;

constructor(projectRoot: string, preferredRevision: string) {
this._projectRoot = projectRoot;
constructor(downloadPath: string, preferredRevision: string) {
this._downloadPath = downloadPath;
this._revision = preferredRevision;
}

Expand Down Expand Up @@ -218,7 +218,7 @@ export class Chromium implements BrowserType {
};

const defaultOptions = {
path: path.join(this._projectRoot, '.local-chromium'),
path: path.join(this._downloadPath, '.local-chromium'),
host: 'https://storage.googleapis.com',
platform: (() => {
const platform = os.platform();
Expand Down
8 changes: 4 additions & 4 deletions src/server/firefox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ import { BrowserContext } from '../browserContext';
const mkdtempAsync = platform.promisify(fs.mkdtemp);

export class Firefox implements BrowserType {
private _projectRoot: string;
private _downloadPath: string;
readonly _revision: string;

constructor(projectRoot: string, preferredRevision: string) {
this._projectRoot = projectRoot;
constructor(downloadPath: string, preferredRevision: string) {
this._downloadPath = downloadPath;
this._revision = preferredRevision;
}

Expand Down Expand Up @@ -216,7 +216,7 @@ export class Firefox implements BrowserType {
};

const defaultOptions = {
path: path.join(this._projectRoot, '.local-firefox'),
path: path.join(this._downloadPath, '.local-firefox'),
host: 'https://playwright.azureedge.net',
platform: (() => {
const platform = os.platform();
Expand Down
31 changes: 24 additions & 7 deletions src/server/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,41 @@
*/

import * as types from '../types';
import * as api from '../api';
import { helper } from '../helper';
import { TimeoutError } from '../errors';
import { DeviceDescriptors } from '../deviceDescriptors';
import { Chromium } from './chromium';
import { WebKit } from './webkit';
import { Firefox } from './firefox';

const packageJSON = require('../../package.json');

for (const className in api) {
if (typeof (api as any)[className] === 'function')
helper.installApiHooks(className[0].toLowerCase() + className.substring(1), (api as any)[className]);
}

export class Playwright {
readonly selectors = api.Selectors;
readonly devices: types.Devices;
readonly errors: { TimeoutError: typeof TimeoutError };
readonly chromium: Chromium;
readonly firefox: Firefox;
readonly webkit: WebKit;
readonly chromium: (Chromium|undefined);
readonly firefox: (Firefox|undefined);
readonly webkit: (WebKit|undefined);

constructor(projectRoot: string, revisions: { chromium_revision: string, firefox_revision: string, webkit_revision: string }) {
constructor(options: {downloadPath: string, browsers: Array<('firefox'|'webkit'|'chromium')>}) {
const {
downloadPath,
browsers,
} = options;
this.devices = DeviceDescriptors;
this.errors = { TimeoutError };
this.chromium = new Chromium(projectRoot, revisions.chromium_revision);
this.firefox = new Firefox(projectRoot, revisions.firefox_revision);
this.webkit = new WebKit(projectRoot, revisions.webkit_revision);
if (browsers.includes('chromium'))
this.chromium = new Chromium(downloadPath, packageJSON.playwright.chromium_revision);
if (browsers.includes('webkit'))
this.webkit = new WebKit(downloadPath, packageJSON.playwright.webkit_revision);
if (browsers.includes('firefox'))
this.firefox = new Firefox(downloadPath, packageJSON.playwright.firefox_revision);
}
}
8 changes: 4 additions & 4 deletions src/server/webkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ import { Events } from '../events';
import { BrowserContext } from '../browserContext';

export class WebKit implements BrowserType {
private _projectRoot: string;
private _downloadPath: string;
readonly _revision: string;

constructor(projectRoot: string, preferredRevision: string) {
this._projectRoot = projectRoot;
constructor(downloadPath: string, preferredRevision: string) {
this._downloadPath = downloadPath;
this._revision = preferredRevision;
}

Expand Down Expand Up @@ -200,7 +200,7 @@ export class WebKit implements BrowserType {
};

const defaultOptions = {
path: path.join(this._projectRoot, '.local-webkit'),
path: path.join(this._downloadPath, '.local-webkit'),
host: 'https://playwright.azureedge.net',
platform: (() => {
const platform = os.platform();
Expand Down