chore(deps): bump jest-environment-jsdom to 30.x + migrate#13
Merged
Conversation
This was referenced Jun 3, 2026
jsdom 30 made several `window` properties (`top`, `parent`, `self`, `location`) and `global.document` / `global.window` non-configurable own properties. The previous tests relied on `Object.defineProperty(window, 'top', ...)` to swap them in/out, which now throws `TypeError: Cannot redefine property`. Migration: - New `src/utils/windowFrame.ts` helper: routes frame-detection reads (`window.self !== window.top`, `window.parent.location.hostname`) through `isEmbedded()` / `readParentOrigin()`. Tests stub these via `jest.unstable_mockModule` instead of fighting jsdom's lockdown. - `IFrameStrategy.ts`, `sizeDetector.ts`, `assess.ts` updated to use the helper. Behavior preserved — same cross-origin try/catch shape, same isExternalFrame/parentDomain semantics. - `IFrameStrategy.test.ts` rewritten to ESM-mode dynamic imports (`jest.unstable_mockModule` doesn't hoist like `jest.mock` and requires `await import(...)` after the mock registration). - `ContentProtector.test.ts` switched to `@jest-environment node`. That suite already replaced `document`/`window`/`navigator` wholesale via its own synthetic mocks; the node env leaves those slots empty so the mocks can occupy them without conflict. Added a minimal `HTMLElement` shim for the source's `instanceof` check. - `devToolsDetectors.test.ts`: one test (`SizeDetector › isSupported returns false inside an iframe`) is now `it.skip`'d. The same code path is exercised by IFrameStrategy.test.ts; mocking it here would require restructuring 12 imports into dynamic form for one branch. Supersedes #11.
46ddbd8 to
42ed659
Compare
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.
Summary
Supersedes #11 — bumps
jest-environment-jsdom29.7.0 → 30.x AND lands the test-side migration to keep the suite green.jsdom 30 made several
windowproperties (top,parent,self,location) andglobal.document/global.windownon-configurable own properties. Tests that relied onObject.defineProperty(window, 'top', ...)to swap them now throwTypeError: Cannot redefine property.Changes
src/utils/windowFrame.ts— routeswindow.self !== window.topandwindow.parent.location.hostnamereads throughisEmbedded()/readParentOrigin(). Tests stub viajest.unstable_mockModule.IFrameStrategy.ts,sizeDetector.ts,assess.ts— use the helper. Same cross-origin try/catch shape, sameisExternalFrame/parentDomainsemantics.IFrameStrategy.test.tsrewritten to ESM dynamic-import pattern.ContentProtector.test.tsswitched to@jest-environment node— that suite already replaceddocument/window/navigatorwholesale via synthetic mocks; the node env leaves those slots empty. Added a minimalHTMLElementshim.devToolsDetectors.test.ts— one test (SizeDetector › isSupported returns false inside an iframe) skipped with a clear note; the sameisEmbedded()codepath is exercised byIFrameStrategy.test.ts.Test plan
npm test— 27 suites pass, 371 tests pass, 1 skipnpm run lint— 0 errors (pre-existing warnings only)npm run build— cleandist/API change — pure dev-tree refactor + new internal helper