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
chore: cleanup code around device descriptors (#404)
Dmitry Gozman92b14cf99677
diff --git a/DeviceDescriptors.js b/DeviceDescriptors.jsindex 2ac295c3ba..5b4ab87e1c 100644--- a/DeviceDescriptors.js+++ b/DeviceDescriptors.js@@ -17,7 +17,4 @@const {DeviceDescriptors} = require('./lib/deviceDescriptors');-const descriptors = DeviceDescriptors.slice();-module.exports = descriptors;-for (const device of descriptors)- module.exports[device.name] = device;+module.exports = DeviceDescriptors;diff --git a/src/chromium/crPlaywright.ts b/src/chromium/crPlaywright.tsindex d14f3bb256..880475ff5d 100644--- a/src/chromium/crPlaywright.ts+++ b/src/chromium/crPlaywright.ts@@ -20,15 +20,14 @@ import * as https from 'https';import * as URL from 'url';import * as browsers from '../browser';import { BrowserFetcher, BrowserFetcherOptions, BrowserFetcherRevisionInfo, OnProgressCallback } from '../browserFetcher';-import { DeviceDescriptor, DeviceDescriptors } from '../deviceDescriptors';+import { DeviceDescriptors } from '../deviceDescriptors';import * as Errors from '../errors';+import * as types from '../types';import { assert } from '../helper';import { ConnectionTransport, WebSocketTransport, SlowMoTransport } from '../transport';import { ConnectionOptions, createBrowserFetcher, CRLauncher, LauncherChromeArgOptions, LauncherLaunchOptions } from './crLauncher';import { CRBrowser } from './crBrowser';-type Devices = { [name: string]: DeviceDescriptor } & DeviceDescriptor[];-export class CRPlaywright {private _projectRoot: string;private _launcher: CRLauncher;@@ -80,11 +79,8 @@ export class CRPlaywright {return this._launcher.executablePath();}- get devices(): Devices {- const result = DeviceDescriptors.slice() as Devices;- for (const device of DeviceDescriptors)- result[device.name] = device;- return result;+ get devices(): types.Devices {+ return DeviceDescriptors;}get errors(): any {diff --git a/src/deviceDescriptors.ts b/src/deviceDescriptors.tsindex e387a309ab..0697a0cbc2 100644--- a/src/deviceDescriptors.ts+++ b/src/deviceDescriptors.ts@@ -17,13 +17,7 @@import * as types from './types';-export type DeviceDescriptor = {- name: string,- userAgent: string,- viewport: types.Viewport,-};--export const DeviceDescriptors: DeviceDescriptor[] = [+const descriptors: types.DeviceDescriptor[] = [{'name': 'Blackberry PlayBook','userAgent': 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML like Gecko) Version/7.2.1.0 Safari/536.2+',@@ -877,3 +871,7 @@ export const DeviceDescriptors: DeviceDescriptor[] = [}}];++export const DeviceDescriptors = descriptors as types.Devices;+for (const device of descriptors)+ DeviceDescriptors[device.name] = device;diff --git a/src/firefox/ffPlaywright.ts b/src/firefox/ffPlaywright.tsindex fdf716fe0a..c6a5aaf988 100644--- a/src/firefox/ffPlaywright.ts+++ b/src/firefox/ffPlaywright.ts@@ -19,12 +19,11 @@ import * as browsers from '../browser';import { FFBrowser } from './ffBrowser';import { BrowserFetcher, BrowserFetcherOptions, OnProgressCallback, BrowserFetcherRevisionInfo } from '../browserFetcher';import { WebSocketTransport, SlowMoTransport } from '../transport';-import { DeviceDescriptors, DeviceDescriptor } from '../deviceDescriptors';+import { DeviceDescriptors } from '../deviceDescriptors';import * as Errors from '../errors';+import * as types from '../types';import { FFLauncher, createBrowserFetcher } from './ffLauncher';-type Devices = { [name: string]: DeviceDescriptor } & DeviceDescriptor[];-export class FFPlaywright {private _projectRoot: string;private _launcher: FFLauncher;@@ -61,11 +60,8 @@ export class FFPlaywright {return this._launcher.executablePath();}- get devices(): Devices {- const result = DeviceDescriptors.slice() as Devices;- for (const device of DeviceDescriptors)- result[device.name] = device;- return result;+ get devices(): types.Devices {+ return DeviceDescriptors;}get errors(): any {diff --git a/src/types.ts b/src/types.tsindex 49fd3a4436..1ead5a50fc 100644--- a/src/types.ts+++ b/src/types.ts@@ -92,3 +92,10 @@ export const mediaTypes: Set<MediaType> = new Set(['screen', 'print']);export type ColorScheme = 'dark' | 'light' | 'no-preference';export const colorSchemes: Set<ColorScheme> = new Set(['dark', 'light', 'no-preference']);++export type DeviceDescriptor = {+ name: string,+ userAgent: string,+ viewport: Viewport,+};+export type Devices = { [name: string]: DeviceDescriptor } & DeviceDescriptor[];diff --git a/src/webkit/wkPlaywright.ts b/src/webkit/wkPlaywright.tsindex f71c3d30eb..d7422133ba 100644--- a/src/webkit/wkPlaywright.ts+++ b/src/webkit/wkPlaywright.ts@@ -18,6 +18,7 @@ import * as browsers from '../browser';import { BrowserFetcher, BrowserFetcherOptions, OnProgressCallback, BrowserFetcherRevisionInfo } from '../browserFetcher';import { DeviceDescriptors } from '../deviceDescriptors';import * as Errors from '../errors';+import * as types from '../types';import { WKLauncher, LauncherLaunchOptions, createBrowserFetcher } from './wkLauncher';import { WKBrowser } from './wkBrowser';@@ -52,11 +53,8 @@ export class WKPlaywright {return this._launcher.executablePath();}- get devices(): any {- const result = DeviceDescriptors.slice();- for (const device of DeviceDescriptors)- result[device.name] = device;- return result;+ get devices(): types.Devices {+ return DeviceDescriptors;}get errors(): any {