Skip to content

Commit

Permalink
Fix RedirectError incorrectly failing Cypress tests (#2655)
Browse files Browse the repository at this point in the history
(patch)
  • Loading branch information
akbo authored Aug 18, 2021
1 parent fb41714 commit 99f3f83
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions nextjs/packages/next/client/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,27 @@ if (process.env.NODE_ENV === 'development') {
}
}
window.addEventListener('error', onUnhandledError)

if ('Cypress' in window) {
// Hide some errors from Cypress, so they don't fail Cypress tests
// https://github.com/cypress-io/cypress/issues/7196

const cypressOnErrorFun = window.onerror

window.onerror = (message, source, lineno, colno, err) => {
if (
cypressOnErrorFun &&
!(
err instanceof RedirectError ||
err instanceof AuthenticationError ||
err instanceof AuthorizationError ||
err instanceof NotFoundError
)
) {
cypressOnErrorFun(message, source, lineno, colno, err)
}
}
}
}

if (process.env.__NEXT_I18N_SUPPORT) {
Expand Down

0 comments on commit 99f3f83

Please sign in to comment.