chore: make generate_types not depend on the source (#5040)

The only dependency is a list of devices that we
can turn into a js file.
This commit is contained in:
Dmitry Gozman 2021-01-17 12:09:20 -08:00 committed by GitHub
parent 1fc02e8823
commit 17e953c2d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 8 deletions

View file

@ -95,7 +95,7 @@ $ python -m playwright wk example.com
``` ```
### Emulate devices ### Emulate devices
`open` can emulate mobile and tablet devices ([see all devices](https://github.com/microsoft/playwright/blob/master/src/server/deviceDescriptors.ts)). `open` can emulate mobile and tablet devices from the [`playwright.devices`](https://playwright.dev/docs/api/class-playwright#playwrightdevices) list.
```sh js ```sh js
# Emulate iPhone 11. # Emulate iPhone 11.

View file

@ -15,17 +15,18 @@
*/ */
import * as channels from '../protocol/channels'; import * as channels from '../protocol/channels';
import { DeviceDescriptors } from '../server/deviceDescriptors';
import { Playwright } from '../server/playwright'; import { Playwright } from '../server/playwright';
import { AndroidDispatcher } from './androidDispatcher'; import { AndroidDispatcher } from './androidDispatcher';
import { BrowserTypeDispatcher } from './browserTypeDispatcher'; import { BrowserTypeDispatcher } from './browserTypeDispatcher';
import { Dispatcher, DispatcherScope } from './dispatcher'; import { Dispatcher, DispatcherScope } from './dispatcher';
import { ElectronDispatcher } from './electronDispatcher'; import { ElectronDispatcher } from './electronDispatcher';
import { SelectorsDispatcher } from './selectorsDispatcher'; import { SelectorsDispatcher } from './selectorsDispatcher';
import * as types from '../server/types';
export class PlaywrightDispatcher extends Dispatcher<Playwright, channels.PlaywrightInitializer> implements channels.PlaywrightChannel { export class PlaywrightDispatcher extends Dispatcher<Playwright, channels.PlaywrightInitializer> implements channels.PlaywrightChannel {
constructor(scope: DispatcherScope, playwright: Playwright) { constructor(scope: DispatcherScope, playwright: Playwright) {
const deviceDescriptors = Object.entries(DeviceDescriptors) const descriptors = require('../server/deviceDescriptors') as types.Devices;
const deviceDescriptors = Object.entries(descriptors)
.map(([name, descriptor]) => ({ name, descriptor })); .map(([name, descriptor]) => ({ name, descriptor }));
super(scope, playwright, 'Playwright', { super(scope, playwright, 'Playwright', {
chromium: new BrowserTypeDispatcher(scope, playwright.chromium), chromium: new BrowserTypeDispatcher(scope, playwright.chromium),

View file

@ -15,9 +15,10 @@
* limitations under the License. * limitations under the License.
*/ */
import * as types from './types'; /**
* @type {import('./types').Devices}
export const DeviceDescriptors: types.Devices = { */
module.exports = {
'Blackberry PlayBook': { '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+',
'viewport': { 'viewport': {

View file

@ -23,7 +23,7 @@ it('should require top-level Errors', async ({}) => {
}); });
it('should require top-level DeviceDescriptors', async ({playwright}) => { it('should require top-level DeviceDescriptors', async ({playwright}) => {
const Devices = require('../lib/server/deviceDescriptors.js').DeviceDescriptors; const Devices = require('../lib/server/deviceDescriptors.js');
expect(Devices['iPhone 6']).toBeTruthy(); expect(Devices['iPhone 6']).toBeTruthy();
expect(Devices['iPhone 6']).toEqual(playwright.devices['iPhone 6']); expect(Devices['iPhone 6']).toEqual(playwright.devices['iPhone 6']);
}); });

View file

@ -17,7 +17,7 @@
//@ts-check //@ts-check
const path = require('path'); const path = require('path');
const os = require('os'); const os = require('os');
const {devices} = require('../..'); const devices = require('../../src/server/deviceDescriptors');
const Documentation = require('../doclint/documentation'); const Documentation = require('../doclint/documentation');
const PROJECT_DIR = path.join(__dirname, '..', '..'); const PROJECT_DIR = path.join(__dirname, '..', '..');
const fs = require('fs'); const fs = require('fs');