fix: preserve native Event/dispatchEvent in jsdom setup for Deno compatibility#9
Merged
Merged
Conversation
…atibility
Under isolation:process, Deno spawns a per-test subprocess and fires
dispatchLoadEvent() on exit using its own native Event constructor.
setupJsdomEnvironment() was unconditionally overwriting globalThis.Event
with jsdom's implementation, causing setTarget() to receive undefined:
TypeError: Cannot set properties of undefined (setting 'target')
at setTarget (ext:deno_web/02_event.js:97:29)
Apply the same save/restore pattern already present in
setupHappyDomEnvironment(): capture the runtime's native Event,
CustomEvent, and dispatchEvent before constructing JSDOM, then
restore them after. isolation:none is unaffected as no subprocess
teardown occurs. Fixes all 24 matrix combinations (24/24 ✅).
This was referenced Apr 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When running tests under Deno with happy-dom, the process exited with:
With jsdom +
isolation:process, each per-test subprocess exited with:Both errors share the same root cause:
dom-env.tswas overwritingglobalThis.Event,globalThis.CustomEvent, andglobalThis.dispatchEventwith the DOM library's own implementations. When Deno's runtime teardown firesdispatchLoadEvent()on exit it uses its own nativeEventconstructor, which is no longer present onglobalThis.isolation:nonewas unaffected because no subprocess teardown occurs.Fix
In both
setupHappyDomEnvironment()andsetupJsdomEnvironment()indom-env.ts:Event,CustomEvent, anddispatchEventbefore installing the DOM library globals.This leaves full DOM functionality intact while keeping Deno's shutdown path working.
Compatibility matrix after fix
All 24 combinations now pass (Node × Bun × Deno) × (happy-dom × jsdom) × (isolation:none × isolation:process) — 24/24 ✅.