diff --git a/src/testing/puppeteer/puppeteer-declarations.ts b/src/testing/puppeteer/puppeteer-declarations.ts index fd454e131d4..3a440908f41 100644 --- a/src/testing/puppeteer/puppeteer-declarations.ts +++ b/src/testing/puppeteer/puppeteer-declarations.ts @@ -18,8 +18,19 @@ export type PageCloseOptions = { export interface NewE2EPageOptions extends WaitForOptions { url?: string; html?: string; + /** + * If set to `true`, Stencil will throw an error if a console error occurs + */ failOnConsoleError?: boolean; + /** + * If set to `true`, Stencil will throw an error if a network request fails + */ failOnNetworkError?: boolean; + /** + * If set to `true`, Stencil will log failing network requests + * @default true + */ + logFailingNetworkRequests?: boolean; } type Omit = Pick>; diff --git a/src/testing/puppeteer/puppeteer-page.ts b/src/testing/puppeteer/puppeteer-page.ts index a7483708187..6edf2436606 100644 --- a/src/testing/puppeteer/puppeteer-page.ts +++ b/src/testing/puppeteer/puppeteer-page.ts @@ -115,6 +115,8 @@ export async function newE2EPage(opts: NewE2EPageOptions = {}): Promise const failOnConsoleError = opts.failOnConsoleError === true; const failOnNetworkError = opts.failOnNetworkError === true; + const logFailingNetworkRequests = + typeof opts.logFailingNetworkRequests === 'boolean' ? opts.logFailingNetworkRequests : true; page.on('console', (ev) => { if (ev.type() === 'error') { @@ -145,7 +147,7 @@ export async function newE2EPage(opts: NewE2EPageOptions = {}): Promise }); if (failOnNetworkError) { throw new Error(req.failure().errorText); - } else { + } else if (logFailingNetworkRequests) { console.error('requestfailed', req.url()); } });