webcomponents / polyfills

Web Components Polyfills
BSD 3-Clause "New" or "Revised" License
1.13k stars 165 forks source link

[scoped-custom-element-registry] Add basic jsdom tests #530

Open bicknellr opened 1 year ago

bicknellr commented 1 year ago

jsdom currently has a bug where it reads the global custom elements registry by looking through the sandbox-facing customElements property of its global object. This means that scripts running in that context can break jsdom's custom elements implementation by overwriting or deleting the customElements global.

I'm making a PR to fix jsdom upstream. Once jsdom and jest-environment-jsdom are released with updated versions, these tests should pass.

Closes https://github.com/webcomponents/polyfills/issues/459.

bicknellr commented 1 year ago

jsdom 20.0.2 contains the PR with the fix. jest-environment-jsdom depends on jsdom@^20.0.0 so its not guaranteed to use 20.0.2. Adding jsdom@^20.0.2 as a dev dependency here would satisfy node's deduping during installation of jest-environment-jsdom, but I don't think it's a great idea to rely on that behavior so I'll keep this open until it depends on at least 20.0.2.

bicknellr commented 1 year ago

Adding jsdom@^20.0.2 as a dev dependency here would satisfy node's deduping during installation of jest-environment-jsdom

I'm trying this out here: https://github.com/webcomponents/polyfills/commit/39e3f06c7b2be69bbe9b0b1c3220480a81409095

bicknellr commented 1 year ago

Except for the formatting, the tests passed on that commit. I reformatted and pushed here. (These still won't pass until jest-environment-jsdom is updated.)

bicknellr commented 1 year ago

Added "Skip Changelog" label because there are no user-facing changes.