Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chrome: co-locate transport types (#236)
Pavel Feldmanbae8cd3fae60
diff --git a/DeviceDescriptors.js b/DeviceDescriptors.jsindex b5f92b43ea..2ac295c3ba 100644--- a/DeviceDescriptors.js+++ b/DeviceDescriptors.js@@ -15,7 +15,7 @@* limitations under the License.*/-const {DeviceDescriptors} = require('./lib/DeviceDescriptors');+const {DeviceDescriptors} = require('./lib/deviceDescriptors');const descriptors = DeviceDescriptors.slice();module.exports = descriptors;diff --git a/Errors.js b/Errors.jsindex 4779e1d850..5475d2223d 100644--- a/Errors.js+++ b/Errors.js@@ -14,4 +14,4 @@* limitations under the License.*/-module.exports = require('./lib/Errors');+module.exports = require('./lib/errors');diff --git a/src/chromium/Connection.ts b/src/chromium/Connection.tsindex 77821ef175..59a2780236 100644--- a/src/chromium/Connection.ts+++ b/src/chromium/Connection.ts@@ -17,7 +17,7 @@import * as debug from 'debug';import { EventEmitter } from 'events';-import { ConnectionTransport } from '../types';+import { ConnectionTransport } from '../transport';import { assert } from '../helper';import { Protocol } from './protocol';diff --git a/src/chromium/Launcher.ts b/src/chromium/Launcher.tsindex b2b4ad4e42..84418af2eb 100644--- a/src/chromium/Launcher.ts+++ b/src/chromium/Launcher.ts@@ -27,9 +27,7 @@ import { Connection } from './Connection';import { TimeoutError } from '../errors';import { assert, debugError, helper } from '../helper';import * as types from '../types';-import { PipeTransport } from './PipeTransport';-import { WebSocketTransport } from '../webSocketTransport';-import { ConnectionTransport } from '../types';+import { ConnectionTransport, WebSocketTransport, PipeTransport } from '../transport';import * as util from 'util';import { launchProcess, waitForLine } from '../processLauncher';diff --git a/src/chromium/Playwright.ts b/src/chromium/Playwright.tsindex ce98c34c0e..86e856734c 100644--- a/src/chromium/Playwright.ts+++ b/src/chromium/Playwright.ts@@ -17,7 +17,7 @@import { Browser } from './Browser';import { BrowserFetcher, BrowserFetcherOptions, BrowserFetcherRevisionInfo, OnProgressCallback } from '../browserFetcher';-import { ConnectionTransport } from '../types';+import { ConnectionTransport } from '../transport';import { DeviceDescriptors, DeviceDescriptor } from '../deviceDescriptors';import * as Errors from '../errors';import { Launcher, LauncherBrowserOptions, LauncherChromeArgOptions, LauncherLaunchOptions, createBrowserFetcher } from './Launcher';diff --git a/src/firefox/Connection.ts b/src/firefox/Connection.tsindex 5a69a08a5e..447c6a5243 100644--- a/src/firefox/Connection.ts+++ b/src/firefox/Connection.ts@@ -18,7 +18,7 @@import {assert} from '../helper';import {EventEmitter} from 'events';import * as debug from 'debug';-import { ConnectionTransport } from '../types';+import { ConnectionTransport } from '../transport';import { Protocol } from './protocol';const debugProtocol = debug('playwright:protocol');diff --git a/src/firefox/Playwright.ts b/src/firefox/Playwright.tsindex 8c64c387f0..2fa46e8e5e 100644--- a/src/firefox/Playwright.ts+++ b/src/firefox/Playwright.ts@@ -16,7 +16,7 @@*/import { Browser } from './Browser';import { BrowserFetcher, BrowserFetcherOptions, OnProgressCallback, BrowserFetcherRevisionInfo } from '../browserFetcher';-import { ConnectionTransport } from '../types';+import { ConnectionTransport } from '../transport';import { DeviceDescriptors, DeviceDescriptor } from '../deviceDescriptors';import * as Errors from '../errors';import { Launcher, createBrowserFetcher } from './Launcher';diff --git a/src/firefox/WebSocketTransport.ts b/src/firefox/WebSocketTransport.tsindex 93dcf6b631..8846b7bf81 100644--- a/src/firefox/WebSocketTransport.ts+++ b/src/firefox/WebSocketTransport.ts@@ -14,7 +14,7 @@* See the License for the specific language governing permissions and* limitations under the License.*/-import { ConnectionTransport } from '../types';+import { ConnectionTransport } from '../transport';import * as WebSocket from 'ws';export class WebSocketTransport implements ConnectionTransport {diff --git a/src/chromium/PipeTransport.ts b/src/transport.tssimilarity index 63%rename from src/chromium/PipeTransport.tsrename to src/transport.tsindex 74db2f8188..a3374bf310 100644--- a/src/chromium/PipeTransport.ts+++ b/src/transport.ts@@ -15,8 +15,54 @@* limitations under the License.*/-import { ConnectionTransport } from '../types';-import { debugError, helper, RegisteredListener } from '../helper';+import * as WebSocket from 'ws';+import { debugError, helper, RegisteredListener } from './helper';++export interface ConnectionTransport {+ send(s: string): void;+ close(): void;+ onmessage?: (message: string) => void,+ onclose?: () => void,+}++export class WebSocketTransport implements ConnectionTransport {+ private _ws: WebSocket;+ onmessage?: (message: string) => void;+ onclose?: () => void;++ static create(url: string): Promise<WebSocketTransport> {+ return new Promise((resolve, reject) => {+ const ws = new WebSocket(url, [], {+ perMessageDeflate: false,+ maxPayload: 256 * 1024 * 1024, // 256Mb+ });+ ws.addEventListener('open', () => resolve(new WebSocketTransport(ws)));+ ws.addEventListener('error', reject);+ });+ }++ constructor(ws: WebSocket) {+ this._ws = ws;+ this._ws.addEventListener('message', event => {+ if (this.onmessage)+ this.onmessage.call(null, event.data);+ });+ this._ws.addEventListener('close', event => {+ if (this.onclose)+ this.onclose.call(null);+ });+ // Silently ignore all errors - we don't know what to do with them.+ this._ws.addEventListener('error', () => {});+ }++ send(message: string) {+ this._ws.send(message);+ }++ close() {+ this._ws.close();+ }+}export class PipeTransport implements ConnectionTransport {private _pipeWrite: NodeJS.WritableStream;diff --git a/src/types.ts b/src/types.tsindex 0122dca471..fd7839c39a 100644--- a/src/types.ts+++ b/src/types.ts@@ -64,10 +64,3 @@ export type Viewport = {isLandscape?: boolean;hasTouch?: boolean;};--export interface ConnectionTransport {- send(s: string): void;- close(): void;- onmessage?: (message: string) => void,- onclose?: () => void,-}diff --git a/src/webSocketTransport.ts b/src/webSocketTransport.tsdeleted file mode 100644index 478b08eae6..0000000000--- a/src/webSocketTransport.ts+++ /dev/null@@ -1,58 +0,0 @@-/**- * Copyright 2018 Google Inc. All rights reserved.- * Modifications copyright (c) Microsoft Corporation.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import * as WebSocket from 'ws';-import { ConnectionTransport } from './types';--export class WebSocketTransport implements ConnectionTransport {- private _ws: WebSocket;- onmessage?: (message: string) => void;- onclose?: () => void;-- static create(url: string): Promise<WebSocketTransport> {- return new Promise((resolve, reject) => {- const ws = new WebSocket(url, [], {- perMessageDeflate: false,- maxPayload: 256 * 1024 * 1024, // 256Mb- });- ws.addEventListener('open', () => resolve(new WebSocketTransport(ws)));- ws.addEventListener('error', reject);- });- }-- constructor(ws: WebSocket) {- this._ws = ws;- this._ws.addEventListener('message', event => {- if (this.onmessage)- this.onmessage.call(null, event.data);- });- this._ws.addEventListener('close', event => {- if (this.onclose)- this.onclose.call(null);- });- // Silently ignore all errors - we don't know what to do with them.- this._ws.addEventListener('error', () => {});- }-- send(message: string) {- this._ws.send(message);- }-- close() {- this._ws.close();- }-}diff --git a/src/webkit/Connection.ts b/src/webkit/Connection.tsindex 2ac3cdb1f2..e946aa5400 100644--- a/src/webkit/Connection.ts+++ b/src/webkit/Connection.ts@@ -17,8 +17,8 @@import {assert, debugError} from '../helper';import * as debug from 'debug';-import {EventEmitter} from 'events';-import { ConnectionTransport } from '../types';+import { EventEmitter } from 'events';+import { ConnectionTransport } from '../transport';import { Protocol } from './protocol';const debugProtocol = debug('playwright:protocol');diff --git a/src/webkit/Launcher.ts b/src/webkit/Launcher.tsindex 4cfc997865..226cb89adc 100644--- a/src/webkit/Launcher.ts+++ b/src/webkit/Launcher.ts@@ -20,7 +20,7 @@ import { Browser } from './Browser';import { BrowserFetcher, BrowserFetcherOptions } from '../browserFetcher';import { Connection } from './Connection';import * as types from '../types';-import { PipeTransport } from './PipeTransport';+import { PipeTransport } from '../transport';import { execSync } from 'child_process';import * as path from 'path';import * as util from 'util';diff --git a/src/webkit/PipeTransport.ts b/src/webkit/PipeTransport.tsdeleted file mode 100644index 74db2f8188..0000000000--- a/src/webkit/PipeTransport.ts+++ /dev/null@@ -1,73 +0,0 @@-/**- * Copyright 2018 Google Inc. All rights reserved.- * Modifications copyright (c) Microsoft Corporation.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--import { ConnectionTransport } from '../types';-import { debugError, helper, RegisteredListener } from '../helper';--export class PipeTransport implements ConnectionTransport {- private _pipeWrite: NodeJS.WritableStream;- private _pendingMessage = '';- private _eventListeners: RegisteredListener[];- onmessage?: (message: string) => void;- onclose?: () => void;-- constructor(pipeWrite: NodeJS.WritableStream, pipeRead: NodeJS.ReadableStream) {- this._pipeWrite = pipeWrite;- this._eventListeners = [- helper.addEventListener(pipeRead, 'data', buffer => this._dispatch(buffer)),- helper.addEventListener(pipeRead, 'close', () => {- if (this.onclose)- this.onclose.call(null);- }),- helper.addEventListener(pipeRead, 'error', debugError),- helper.addEventListener(pipeWrite, 'error', debugError),- ];- this.onmessage = null;- this.onclose = null;- }-- send(message: string) {- this._pipeWrite.write(message);- this._pipeWrite.write('\0');- }-- _dispatch(buffer: Buffer) {- let end = buffer.indexOf('\0');- if (end === -1) {- this._pendingMessage += buffer.toString();- return;- }- const message = this._pendingMessage + buffer.toString(undefined, 0, end);- if (this.onmessage)- this.onmessage.call(null, message);-- let start = end + 1;- end = buffer.indexOf('\0', start);- while (end !== -1) {- if (this.onmessage)- this.onmessage.call(null, buffer.toString(undefined, start, end));- start = end + 1;- end = buffer.indexOf('\0', start);- }- this._pendingMessage = buffer.toString(undefined, start);- }-- close() {- this._pipeWrite = null;- helper.removeEventListeners(this._eventListeners);- }-}diff --git a/test/launcher.spec.js b/test/launcher.spec.jsindex 7ef8c05820..346dcb08b4 100644--- a/test/launcher.spec.js+++ b/test/launcher.spec.js@@ -116,11 +116,11 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, pdescribe('Top-level requires', function() {it('should require top-level Errors', async() => {- const Errors = require(path.join(utils.projectRoot(), '/errors'));+ const Errors = require(path.join(utils.projectRoot(), '/Errors'));expect(Errors.TimeoutError).toBe(playwright.errors.TimeoutError);});it('should require top-level DeviceDescriptors', async() => {- const Devices = require(path.join(utils.projectRoot(), '/deviceDescriptors'));+ const Devices = require(path.join(utils.projectRoot(), '/DeviceDescriptors'));expect(Devices['iPhone 6']).toBe(playwright.devices['iPhone 6']);});});