| 143 | } |
| 144 | |
| 145 | async function openPage(browser, server, scenario, arm, options, expected, trace = false) { |
| 146 | let context = await browser.newContext({ |
| 147 | viewport: {width: 1280, height: 900}, |
| 148 | deviceScaleFactor: 1, |
| 149 | locale: 'en-US', |
| 150 | timezoneId: 'America/Chicago', |
| 151 | colorScheme: 'light', |
| 152 | reducedMotion: 'no-preference' |
| 153 | }); |
| 154 | let page = await context.newPage(); |
| 155 | page.setDefaultTimeout(15000); |
| 156 | let errors = []; |
| 157 | page.on('pageerror', error => errors.push(error.message)); |
| 158 | page.on('console', message => { |
| 159 | if (message.type() === 'error') { |
| 160 | errors.push(message.text()); |
| 161 | } |
| 162 | }); |
| 163 | let session = await context.newCDPSession(page); |
| 164 | await session.send('Emulation.setCPUThrottlingRate', {rate: options.cpu}); |
| 165 | let size = sizes[scenario.fixture] * options.scale; |
| 166 | let params = new URLSearchParams({ |
| 167 | fixture: scenario.fixture, |
| 168 | size: String(size), |
| 169 | ...(trace && {trace: '1'}), |
| 170 | delay: String(arm === 'candidate' ? options.delay : 0), |
| 171 | delayMode: options.delayMode |
| 172 | }); |
| 173 | await page.goto(`${server.url}/${arm}/index.html?${params}`); |
| 174 | await page.waitForFunction(() => !!window.__bench); |
| 175 | let info = await page.evaluate(() => window.__bench.info); |
| 176 | if (!info.production || info.react !== expected.versions.react || info.size !== size) { |
| 177 | throw new Error('Runtime production/version/fixture verification failed.'); |
| 178 | } |
| 179 | return {page, context, session, size, errors}; |
| 180 | } |
| 181 | |
| 182 | async function saveTrace(session, file, operation) { |
| 183 | await session.send('Tracing.start', { |