(path = '/', opts?: { retries?: number })
| 9 | import { isRenderingJson } from './matrix' |
| 10 | |
| 11 | export async function renderPage (path = '/', opts?: { retries?: number }) { |
| 12 | const ctx = useTestContext() |
| 13 | if (!ctx.options.browser) { |
| 14 | throw new Error('`renderPage` require `options.browser` to be set') |
| 15 | } |
| 16 | |
| 17 | const browser = await getBrowser() |
| 18 | const page = await browser.newPage({}) |
| 19 | const pageErrors: Error[] = [] |
| 20 | const requests: string[] = [] |
| 21 | const consoleLogs: { type: string, text: string }[] = [] |
| 22 | |
| 23 | page.on('console', (message) => { |
| 24 | consoleLogs.push({ |
| 25 | type: message.type(), |
| 26 | text: message.text(), |
| 27 | }) |
| 28 | }) |
| 29 | page.on('pageerror', (err) => { |
| 30 | pageErrors.push(err) |
| 31 | }) |
| 32 | page.on('request', (req) => { |
| 33 | try { |
| 34 | requests.push(req.url().replace(url('/'), '/')) |
| 35 | } catch { |
| 36 | // TODO |
| 37 | } |
| 38 | }) |
| 39 | |
| 40 | if (path) { |
| 41 | await gotoPath(page, path, opts?.retries) |
| 42 | } |
| 43 | |
| 44 | return { |
| 45 | page, |
| 46 | pageErrors, |
| 47 | requests, |
| 48 | consoleLogs, |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | export async function expectNoClientErrors (path: string) { |
| 53 | const ctx = useTestContext() |
no test coverage detected
searching dependent graphs…