-
Notifications
You must be signed in to change notification settings - Fork 1
/
puppeteer.setup.js
80 lines (63 loc) · 1.82 KB
/
puppeteer.setup.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* global page, targetEnv */
const puppeteer = require('puppeteer-core');
const {ipAddress} = require('./performance/utils');
global.maxCLS = 0.1;
global.maxDCL = 2000;
global.maxFCP = 1800;
global.maxINP = 200;
global.maxLCP = 2500;
global.minFPS = 20;
global.passRatio = 0.7;
global.stepNumber = 5;
let browser;
const targetCPUThrottling = process.argv.filter((x) => x.startsWith('--throttling='))[0];
const targetEnvArg = process.argv.filter((x) => x.startsWith('--target='))[0];
global.CPUThrottling = targetCPUThrottling ? parseInt(targetCPUThrottling.split('=')[1]) : 1;
global.targetEnv = targetEnvArg ? targetEnvArg.split('=')[1] : 'PC';
global.serverAddr = `${ipAddress()}:8080`;
global.webVitalsURL = 'https://unpkg.com/web-vitals@4.2.3/dist/web-vitals.iife.js';
if (targetEnv === 'PC') {
global.beforeAll(async () => {
browser = await puppeteer.launch({
args: ['--window-size=1920,1080'],
executablePath: require('puppeteer').executablePath(),
headless: true
});
global.testMultiple = browser;
});
global.beforeEach(async () => {
const newPage = await browser.newPage();
await newPage.setViewport({
width: 1920,
height: 1080
});
global.page = newPage;
});
global.afterEach(async () => {
await page.close();
});
global.afterAll(async () => {
await browser.close();
});
} else if (targetEnv === 'TV') {
global.beforeAll(async () => {
const TVAddr = process.env.TV_IP;
browser = await puppeteer.connect({
browserURL: `http://${TVAddr}:9998`,
ignoreHTTPSErrors: true
});
const pages = await browser.pages();
global.testMultiple = browser;
global.testPage = pages[0];
});
global.beforeEach(async () => {
global.page = global.testPage;
await global.page.setViewport({
width: 1920,
height: 1080
});
});
global.afterAll(async () => {
await browser.close();
});
}