Open History to see the last commit
1import { test as base, expect } from '@playwright/test'
2β
3export interface TestFixtureOptions {
4 whitelistErrors: Array<RegExp | string>
5}
6export const test = base.extend<TestFixtureOptions>({
7 whitelistErrors: [[], { option: true }],
8 page: async ({ page, whitelistErrors }, use) => {
9 const errorMessages: Array<string> = []
10 page.on('console', (m) => {
11 if (m.type() === 'error') {
12 const text = m.text()
13 for (const whitelistError of whitelistErrors) {
14 if (
15 (typeof whitelistError === 'string' &&
16 text.includes(whitelistError)) ||
17 (whitelistError instanceof RegExp && whitelistError.test(text))
18 ) {
19 return
20 }
21 }
22 errorMessages.push(text)
23 }
24 })
25 await use(page)
26 expect(errorMessages).toEqual([])
27 },
28})