Skip to content

warnings-as-errors

Turns Node process warnings into test failures.

A Node 'warning' event (e.g. an ExperimentalWarning, a DeprecationWarning, or a MaxListenersExceededWarning) normally prints to stderr and is otherwise ignored. During tests that silently hides real problems — the environment or a dependency is doing something Node flags as risky, and the signal scrolls past unread. installWarningsAsErrors registers a 'warning' listener that rethrows, surfacing as an uncaught exception so the test run fails. This forces the underlying cause to be addressed (or the warning to be eliminated at its source) rather than masked.

Function Description
installWarningsAsErrors Registers a process 'warning' listener that turns every Node warning into a test failure. Idempotent: calling it more than once (e.g. from several setup files sharing one worker) registers the listener at most once, so it does not itself trigger a MaxListenersExceededWarning. The check is by marker rather than by function identity, so it holds across module realms as well — under a VM-backed pool each test file evaluates this module separately and an identity check would miss.
throwOnWarning A process 'warning' listener that rethrows the warning as an error, failing the test run.