Skip to content

fix: running Happy DOM in the global scope#859

Merged
9aoy merged 3 commits intomainfrom
happy-dom-text-endcoder
Jan 12, 2026
Merged

fix: running Happy DOM in the global scope#859
9aoy merged 3 commits intomainfrom
happy-dom-text-endcoder

Conversation

@9aoy
Copy link
Copy Markdown
Collaborator

@9aoy 9aoy commented Jan 12, 2026

Summary

running Happy DOM in the global scope.

test('should work', () => {
  expect([1]).toEqual([1]);
  expect(new TextEncoder().encode('a')).toEqual(new TextEncoder().encode('a'));
  expect(Uint8Array.from([97])).toEqual(new TextEncoder().encode('a'));
});

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings January 12, 2026 08:29
@netlify
Copy link
Copy Markdown

netlify bot commented Jan 12, 2026

Deploy Preview for rstest-dev ready!

Name Link
🔨 Latest commit fd85c35
🔍 Latest deploy log https://app.netlify.com/projects/rstest-dev/deploys/6964b4b461659500086cabe0
😎 Deploy Preview https://deploy-preview-859--rstest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where Happy DOM wasn't running correctly in the global scope, causing problems with global objects like TextEncoder and Uint8Array. The fix uses the new GlobalWindow class from happy-dom when available, with a fallback to the regular Window class for backward compatibility.

Changes:

  • Updated the happy-dom environment setup to use GlobalWindow instead of Window when available
  • Added an end-to-end test to verify TextEncoder and Uint8Array work correctly in happy-dom

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/core/src/runtime/worker/env/happyDom.ts Modified to import and use GlobalWindow with fallback to Window for backward compatibility
e2e/dom/index.test.ts Added test case for TextEncoder functionality in happy-dom
e2e/dom/fixtures/test/textEncoder.test.tsx New test file verifying TextEncoder and Uint8Array work correctly with happy-dom

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

9aoy and others added 2 commits January 12, 2026 16:45
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@9aoy 9aoy merged commit 37006c1 into main Jan 12, 2026
15 checks passed
@9aoy 9aoy deleted the happy-dom-text-endcoder branch January 12, 2026 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants