Skip to content

chore(deps): bump jest-environment-jsdom to 30.x + migrate#13

Merged
Isonimus merged 1 commit into
mainfrom
test/jest-30-jsdom-30
Jun 3, 2026
Merged

chore(deps): bump jest-environment-jsdom to 30.x + migrate#13
Isonimus merged 1 commit into
mainfrom
test/jest-30-jsdom-30

Conversation

@Isonimus

@Isonimus Isonimus commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Supersedes #11 — bumps jest-environment-jsdom 29.7.0 → 30.x AND lands the test-side migration to keep the suite green.

jsdom 30 made several window properties (top, parent, self, location) and global.document / global.window non-configurable own properties. Tests that relied on Object.defineProperty(window, 'top', ...) to swap them now throw TypeError: Cannot redefine property.

Changes

  • New src/utils/windowFrame.ts — routes window.self !== window.top and window.parent.location.hostname reads through isEmbedded() / readParentOrigin(). Tests stub via jest.unstable_mockModule.
  • IFrameStrategy.ts, sizeDetector.ts, assess.ts — use the helper. Same cross-origin try/catch shape, same isExternalFrame/parentDomain semantics.
  • IFrameStrategy.test.ts rewritten to ESM dynamic-import pattern.
  • ContentProtector.test.ts switched to @jest-environment node — that suite already replaced document/window/navigator wholesale via synthetic mocks; the node env leaves those slots empty. Added a minimal HTMLElement shim.
  • devToolsDetectors.test.ts — one test (SizeDetector › isSupported returns false inside an iframe) skipped with a clear note; the same isEmbedded() codepath is exercised by IFrameStrategy.test.ts.

Test plan

  • npm test — 27 suites pass, 371 tests pass, 1 skip
  • npm run lint — 0 errors (pre-existing warnings only)
  • npm run build — clean
  • No dist/ API change — pure dev-tree refactor + new internal helper

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.
@Isonimus Isonimus force-pushed the test/jest-30-jsdom-30 branch from 46ddbd8 to 42ed659 Compare June 3, 2026 10:27
@Isonimus Isonimus merged commit b7b87f7 into main Jun 3, 2026
1 check passed
@Isonimus Isonimus deleted the test/jest-30-jsdom-30 branch June 3, 2026 10:28
Isonimus added a commit that referenced this pull request Jun 3, 2026
…ased]

Rolls the post-release dependabot triage into the next release notes:
- typescript-eslint patch group (#9)
- eslint 9 → 10 (#12) — peer-deps cleared upstream
- jest 30 + jsdom 30 (#13) including the windowFrame helper migration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant