mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 13:45:36 +03:00
chore: cleanup code around device descriptors (#404)
This commit is contained in:
parent
a494efed0f
commit
92b14cf996
@ -17,7 +17,4 @@
|
|||||||
|
|
||||||
const {DeviceDescriptors} = require('./lib/deviceDescriptors');
|
const {DeviceDescriptors} = require('./lib/deviceDescriptors');
|
||||||
|
|
||||||
const descriptors = DeviceDescriptors.slice();
|
module.exports = DeviceDescriptors;
|
||||||
module.exports = descriptors;
|
|
||||||
for (const device of descriptors)
|
|
||||||
module.exports[device.name] = device;
|
|
||||||
|
@ -20,15 +20,14 @@ import * as https from 'https';
|
|||||||
import * as URL from 'url';
|
import * as URL from 'url';
|
||||||
import * as browsers from '../browser';
|
import * as browsers from '../browser';
|
||||||
import { BrowserFetcher, BrowserFetcherOptions, BrowserFetcherRevisionInfo, OnProgressCallback } from '../browserFetcher';
|
import { BrowserFetcher, BrowserFetcherOptions, BrowserFetcherRevisionInfo, OnProgressCallback } from '../browserFetcher';
|
||||||
import { DeviceDescriptor, DeviceDescriptors } from '../deviceDescriptors';
|
import { DeviceDescriptors } from '../deviceDescriptors';
|
||||||
import * as Errors from '../errors';
|
import * as Errors from '../errors';
|
||||||
|
import * as types from '../types';
|
||||||
import { assert } from '../helper';
|
import { assert } from '../helper';
|
||||||
import { ConnectionTransport, WebSocketTransport, SlowMoTransport } from '../transport';
|
import { ConnectionTransport, WebSocketTransport, SlowMoTransport } from '../transport';
|
||||||
import { ConnectionOptions, createBrowserFetcher, CRLauncher, LauncherChromeArgOptions, LauncherLaunchOptions } from './crLauncher';
|
import { ConnectionOptions, createBrowserFetcher, CRLauncher, LauncherChromeArgOptions, LauncherLaunchOptions } from './crLauncher';
|
||||||
import { CRBrowser } from './crBrowser';
|
import { CRBrowser } from './crBrowser';
|
||||||
|
|
||||||
type Devices = { [name: string]: DeviceDescriptor } & DeviceDescriptor[];
|
|
||||||
|
|
||||||
export class CRPlaywright {
|
export class CRPlaywright {
|
||||||
private _projectRoot: string;
|
private _projectRoot: string;
|
||||||
private _launcher: CRLauncher;
|
private _launcher: CRLauncher;
|
||||||
@ -80,11 +79,8 @@ export class CRPlaywright {
|
|||||||
return this._launcher.executablePath();
|
return this._launcher.executablePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
get devices(): Devices {
|
get devices(): types.Devices {
|
||||||
const result = DeviceDescriptors.slice() as Devices;
|
return DeviceDescriptors;
|
||||||
for (const device of DeviceDescriptors)
|
|
||||||
result[device.name] = device;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get errors(): any {
|
get errors(): any {
|
||||||
|
@ -17,13 +17,7 @@
|
|||||||
|
|
||||||
import * as types from './types';
|
import * as types from './types';
|
||||||
|
|
||||||
export type DeviceDescriptor = {
|
const descriptors: types.DeviceDescriptor[] = [
|
||||||
name: string,
|
|
||||||
userAgent: string,
|
|
||||||
viewport: types.Viewport,
|
|
||||||
};
|
|
||||||
|
|
||||||
export const DeviceDescriptors: DeviceDescriptor[] = [
|
|
||||||
{
|
{
|
||||||
'name': 'Blackberry PlayBook',
|
'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+',
|
'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;
|
||||||
|
@ -19,12 +19,11 @@ import * as browsers from '../browser';
|
|||||||
import { FFBrowser } from './ffBrowser';
|
import { FFBrowser } from './ffBrowser';
|
||||||
import { BrowserFetcher, BrowserFetcherOptions, OnProgressCallback, BrowserFetcherRevisionInfo } from '../browserFetcher';
|
import { BrowserFetcher, BrowserFetcherOptions, OnProgressCallback, BrowserFetcherRevisionInfo } from '../browserFetcher';
|
||||||
import { WebSocketTransport, SlowMoTransport } from '../transport';
|
import { WebSocketTransport, SlowMoTransport } from '../transport';
|
||||||
import { DeviceDescriptors, DeviceDescriptor } from '../deviceDescriptors';
|
import { DeviceDescriptors } from '../deviceDescriptors';
|
||||||
import * as Errors from '../errors';
|
import * as Errors from '../errors';
|
||||||
|
import * as types from '../types';
|
||||||
import { FFLauncher, createBrowserFetcher } from './ffLauncher';
|
import { FFLauncher, createBrowserFetcher } from './ffLauncher';
|
||||||
|
|
||||||
type Devices = { [name: string]: DeviceDescriptor } & DeviceDescriptor[];
|
|
||||||
|
|
||||||
export class FFPlaywright {
|
export class FFPlaywright {
|
||||||
private _projectRoot: string;
|
private _projectRoot: string;
|
||||||
private _launcher: FFLauncher;
|
private _launcher: FFLauncher;
|
||||||
@ -61,11 +60,8 @@ export class FFPlaywright {
|
|||||||
return this._launcher.executablePath();
|
return this._launcher.executablePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
get devices(): Devices {
|
get devices(): types.Devices {
|
||||||
const result = DeviceDescriptors.slice() as Devices;
|
return DeviceDescriptors;
|
||||||
for (const device of DeviceDescriptors)
|
|
||||||
result[device.name] = device;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get errors(): any {
|
get errors(): any {
|
||||||
|
@ -92,3 +92,10 @@ export const mediaTypes: Set<MediaType> = new Set(['screen', 'print']);
|
|||||||
|
|
||||||
export type ColorScheme = 'dark' | 'light' | 'no-preference';
|
export type ColorScheme = 'dark' | 'light' | 'no-preference';
|
||||||
export const colorSchemes: Set<ColorScheme> = new Set(['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[];
|
||||||
|
@ -18,6 +18,7 @@ import * as browsers from '../browser';
|
|||||||
import { BrowserFetcher, BrowserFetcherOptions, OnProgressCallback, BrowserFetcherRevisionInfo } from '../browserFetcher';
|
import { BrowserFetcher, BrowserFetcherOptions, OnProgressCallback, BrowserFetcherRevisionInfo } from '../browserFetcher';
|
||||||
import { DeviceDescriptors } from '../deviceDescriptors';
|
import { DeviceDescriptors } from '../deviceDescriptors';
|
||||||
import * as Errors from '../errors';
|
import * as Errors from '../errors';
|
||||||
|
import * as types from '../types';
|
||||||
import { WKLauncher, LauncherLaunchOptions, createBrowserFetcher } from './wkLauncher';
|
import { WKLauncher, LauncherLaunchOptions, createBrowserFetcher } from './wkLauncher';
|
||||||
import { WKBrowser } from './wkBrowser';
|
import { WKBrowser } from './wkBrowser';
|
||||||
|
|
||||||
@ -52,11 +53,8 @@ export class WKPlaywright {
|
|||||||
return this._launcher.executablePath();
|
return this._launcher.executablePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
get devices(): any {
|
get devices(): types.Devices {
|
||||||
const result = DeviceDescriptors.slice();
|
return DeviceDescriptors;
|
||||||
for (const device of DeviceDescriptors)
|
|
||||||
result[device.name] = device;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get errors(): any {
|
get errors(): any {
|
||||||
|
Loading…
Reference in New Issue
Block a user