File size: 1,314 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { LaunchOptions, BrowserContextOptions, devices } from 'playwright';
import envVariables from '../env-variables';

const getTargetDeviceOptions = () => {
	const viewportName = envVariables.VIEWPORT_NAME;
	let deviceName: string;

	switch ( viewportName ) {
		case 'mobile':
			deviceName = 'Pixel 4a (5G)';
			break;
		case 'desktop':
			deviceName = 'Desktop Chrome HiDPI';
			break;
		default:
			throw new Error( 'No viewport specified.' );
	}

	if ( ! deviceName ) {
		throw Error( `Unsupported viewport: ${ viewportName }` );
	}

	const options = devices[ deviceName ];

	if ( ! options ) {
		throw Error( `Device options unavailable for ${ name }` );
	}

	return options;
};

const targetDeviceOptions = getTargetDeviceOptions();

// Options for the BrowserType.
// https://playwright.dev/docs/api/class-browsertype
const launchOptions: LaunchOptions = {
	headless: envVariables.HEADLESS,
	slowMo: envVariables.SLOW_MO,
	args: [ '--disable-quic' ],
};

// Options for the BrowserContext level.
// https://playwright.dev/docs/api/class-browsercontext
const contextOptions: BrowserContextOptions = {
	...targetDeviceOptions,
	userAgent: `${ targetDeviceOptions.userAgent } wp-e2e-tests`,
	locale: envVariables.TEST_LOCALES[ 0 ],
};

export default Object.freeze( {
	launchOptions,
	contextOptions,
} );