-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5071b8
commit 3a51e0c
Showing
3 changed files
with
54 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { type ConsoleMessage, type Page } from '@playwright/test'; | ||
|
||
const messagesToIgnore = [ | ||
/Ignoring Event: localhost/, | ||
/\[vite\] connecting\.\.\./, | ||
/\[vite\] connected\./, | ||
/\[vite\] ready\./, | ||
/Download the React DevTools for a better development experience: https:\/\/reactjs\.org\/link\/react-devtools/, | ||
/\[astro-island\] Error hydrating .* TypeError: Importing a module script failed\./, // Fires in `astro dev` mode only | ||
/downloadable font: kern: Too large subtable/, | ||
/downloadable font: Table discarded/, | ||
/Target page, context or browser has been closed/, | ||
]; | ||
|
||
export function throwOnConsole(page: Page) { | ||
const listener = (message: ConsoleMessage) => { | ||
if (messagesToIgnore.some((regex) => regex.test(message.text()))) { | ||
return; | ||
} | ||
if (message.type() !== 'error') { | ||
return; | ||
} | ||
throw new Error(`[${message.type()}]: '${message.text()}'`); | ||
}; | ||
|
||
page.on('console', listener); | ||
|
||
return () => page.removeListener('console', listener); | ||
} |