Skip to content

[Bug]: Jest 30 beta causes random ERR_INVALID_THIS errors #15632

@faulpeltz

Description

@faulpeltz

Version

30.0.0-beta

Steps to reproduce

  1. Use https://github.com/faulpeltz/jest-issue-repro
  2. Run jest

Expected behavior

Tests pass

Actual behavior

The test which is executed after the first fails with:
TypeError: Value of "this" must be of type EventTarget

Note that using worker_threads in my example is just one of many Node-builtin locations where this causes issues (in my actual test suite), mostly related to streams, child processes, etc.

Additional context

The issue cannot be reproduced in alpha.7, and I was able to track it down to this commit: 999bb65

This introduces a cleanup of the global object but it looks like it cleans up way to much - in my example EventTarget is removed after the first test file, causing the second to fail.
In this example this is caused by the cleanup of Symbol(nodejs.event_target) which is only defined after the initial setup phase and then is cleaned up - and probably other things as well. It seems that many Node builtin APIs lazily intialize some symbol properties on the global object when first used, and cleaning those up is probably unsafe.

If symbol-properties are skipped for cleanup, then things work normally

Environment

Linux Mint, x64, Node v22.16.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions