MCPcopy Create free account
hub / github.com/TanStack/cli / attachRuntimeGuards

Function attachRuntimeGuards

packages/cli/tests-e2e/helpers.ts:501–599  ·  view source on GitHub ↗
(page: Page, appUrl: string)

Source from the content-addressed store, hash-verified

499}
500
501export function attachRuntimeGuards(page: Page, appUrl: string): RuntimeGuards {
502 const appOrigin = new URL(appUrl)
503 const pageErrors: Array<string> = []
504 const consoleErrors: Array<string> = []
505 const requestFailures: Array<string> = []
506 const httpErrors: Array<string> = []
507
508 const onPageError = (error: Error) => {
509 pageErrors.push(error.message)
510 }
511
512 const onConsole = (message: { type: () => string; text: () => string }) => {
513 if (message.type() === 'error') {
514 const text = message.text()
515 if (isBlockedByClientError(text)) {
516 return
517 }
518 consoleErrors.push(text)
519 }
520 }
521
522 const onRequestFailed = (request: {
523 method: () => string
524 url: () => string
525 failure: () => { errorText?: string } | null
526 }) => {
527 const url = request.url()
528 if (!toSameOrigin(url, appOrigin)) {
529 return
530 }
531 const errorText = request.failure()?.errorText || 'unknown error'
532
533 if (errorText.includes('ERR_ABORTED') || isBlockedByClientError(errorText)) {
534 return
535 }
536
537 requestFailures.push(`${request.method()} ${url} :: ${errorText}`)
538 }
539
540 const onResponse = (response: {
541 url: () => string
542 status: () => number
543 request: () => { method: () => string }
544 }) => {
545 const url = response.url()
546 if (!toSameOrigin(url, appOrigin)) {
547 return
548 }
549
550 const status = response.status()
551 if (status >= 400) {
552 httpErrors.push(`${response.request().method()} ${status} ${url}`)
553 }
554 }
555
556 page.on('pageerror', onPageError)
557 page.on('console', onConsole)
558 page.on('requestfailed', onRequestFailed)

Calls

no outgoing calls

Tested by

no test coverage detected