Skip to content

Commit

Permalink
feat(testing): allow to disable network error logging via 'logFailing…
Browse files Browse the repository at this point in the history
…NetworkRequests' option (#5839)

* feat(testing): allow to disable network error logging via 'logFailingNetworkRequests' option

* keep current default behavior
  • Loading branch information
christian-bromann authored Jun 18, 2024
1 parent 5c10ebf commit dac3e33
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/testing/puppeteer/puppeteer-declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T, K> = Pick<T, Exclude<keyof T, K>>;
Expand Down
4 changes: 3 additions & 1 deletion src/testing/puppeteer/puppeteer-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export async function newE2EPage(opts: NewE2EPageOptions = {}): Promise<E2EPage>

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') {
Expand Down Expand Up @@ -145,7 +147,7 @@ export async function newE2EPage(opts: NewE2EPageOptions = {}): Promise<E2EPage>
});
if (failOnNetworkError) {
throw new Error(req.failure().errorText);
} else {
} else if (logFailingNetworkRequests) {
console.error('requestfailed', req.url());
}
});
Expand Down

0 comments on commit dac3e33

Please sign in to comment.