Skip to content

Broken regex in global uncaught:exception handler silently swallows real test errors across all 194 Cypress specs #1989

Description

@zhongnansu

Description

The global Cypress uncaught:exception handler in cypress/support/index.js contains a broken regex that inverts its intended behavior. It was meant to suppress only ResizeObserver loop limit exceeded errors but instead suppresses nearly all real JavaScript errors while failing to suppress the ResizeObserver error it targets.

This affects all 194 Cypress test files in the repository.

The bug

// cypress/support/index.js:48-54
const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/;
Cypress.on('uncaught:exception', (err) => {
  if (resizeObserverLoopErrRe.test(err.message)) {
    return false;
  }
});

[^(...)] in regex is a negated character class, not a negated string match. It decomposes the string into individual characters (R, e, s, i, z, O, b, etc.) and matches any message whose first character is not one of those 20 chars.

Actual behavior

Error message Intended Actual
ResizeObserver loop limit exceeded Suppressed NOT suppressed (first char R is in the class)
TypeError: Cannot read properties Fails the test Suppressed (first char T is not in the class)
SyntaxError: Unexpected token Fails the test Suppressed
Failed to fetch Fails the test Suppressed
DOMException: ... Fails the test Suppressed
NetworkError: ... Fails the test Suppressed

Impact

  • Every real uncaught JavaScript error (TypeError, SyntaxError, NetworkError, etc.) is silently swallowed across all 194 test specs
  • The ResizeObserver error it was meant to suppress is not suppressed
  • Tests pass even when the application throws real errors, defeating the purpose of E2E testing
  • Genuine application bugs are hidden behind false-positive green CI checks

Suggested fix

One-line change at cypress/support/index.js:48:

- const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/;
+ const resizeObserverLoopErrRe = /ResizeObserver loop/;

The handler logic stays the same — now the regex correctly matches only ResizeObserver errors, and return false suppresses only those.

Or drop regex entirely:

if (err.message.includes('ResizeObserver loop')) {
  return false;
}

After fixing

Some tests may start failing because they were previously passing only due to real exceptions being silently swallowed. Those failures are genuine bugs in the application code or test setup that were being masked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions