Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOM testing recommendations result in TypeError: Attempted to assign to readonly property. when setting global ReadableStream #5845

Closed
lgarron opened this issue Sep 21, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@lgarron
Copy link
Contributor

lgarron commented Sep 21, 2023

What version of Bun is running?

1.0.0+822a00c4d508b54f650933a73ca5f4a3af9a7983

What platform is your computer?

Darwin 22.6.0 arm64 arm

What steps can reproduce the bug?

Follow the exact steps from https://bun.sh/docs/test/dom#happy-dom

This is reproducible in a repo:

git clone https://github.com/lgarron/bun-happy-dom-TypeError && cd bun-happy-dom-TypeError
bun test

What is the expected behavior?

happy-dom global registration is successful.

What do you see instead?

bun test v1.0.0 (822a00c4)

dom.test.ts:
16 |         this.registered = {};
17 |         for (const key of Object.keys(window)) {
18 |             if (global[key] !== window[key] && !IGNORE_LIST.includes(key)) {
19 |                 this.registered[key] =
20 |                     global[key] !== window[key] && global[key] !== undefined ? global[key] : null;
21 |                 global[key] = typeof window[key] === 'function' ? window[key].bind(global) : window[key];
                    ^
TypeError: Attempted to assign to readonly property.
      at register (/Users/lgarron/Code/git/github.com/lgarron/bun-happy-dom-TypeError/node_modules/@happy-dom/global-registrator/lib/GlobalRegistrator.js:21:16)
      at /Users/lgarron/Code/git/github.com/lgarron/bun-happy-dom-TypeError/happydom.ts:3:0

 0 pass
 1 fail
Ran 1 tests across 1 files. [68.00ms]
make: *** [repro] Error 1
bun test

This seems to happen for the key ReadableStream. The following may be a smaller repro:

globalThis.ReadableStream = 4;

Additional information

happy-dom should really be using globalThis. But in any case, if this is the recommended approach for DOM testing with bun then it should probably not error out of the box.

@lgarron lgarron added the bug Something isn't working label Sep 21, 2023
@lgarron lgarron changed the title DOM testing recommendations result in TypeError: Attempted to assign to readonly property. DOM testing recommendations result in TypeError: Attempted to assign to readonly property. when setting ReadableStream Sep 21, 2023
@lgarron lgarron changed the title DOM testing recommendations result in TypeError: Attempted to assign to readonly property. when setting ReadableStream DOM testing recommendations result in TypeError: Attempted to assign to readonly property. when setting global ReadableStream Sep 21, 2023
@lgarron
Copy link
Contributor Author

lgarron commented Sep 21, 2023

This seems to happen for the key ReadableStream. The following may be a smaller repro:

globalThis.ReadableStream = 4;

Yeah, I think this is it. node and browsers allow this.

@dylan-conway
Copy link
Member

Could you try with v1.0.2? I think this should be fixed

@lgarron
Copy link
Contributor Author

lgarron commented Sep 21, 2023

Could you try with v1.0.2? I think this should be fixed

Ah, excellent, thanks! 🤩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants