Chore: Fixes #14834: Mobile: JSDOM scroll polyfill in ExtendedWebView#14896
Chore: Fixes #14834: Mobile: JSDOM scroll polyfill in ExtendedWebView#14896divyanshkhurana06 wants to merge 3 commits intolaurent22:devfrom
Conversation
…edWebView mock Polyfill scrollIntoView/scrollTo/scrollBy only on the nested JSDOM window used by the ExtendedWebView Jest mock (and iframe contentWindows), avoiding global Element patches that break handleAnchorClick tests. Clear the note focus polling interval on unmount to avoid stray logs and open handles after tests.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdds a Jest JSDOM polyfill to define missing scroll methods on element prototypes (applied to window and iframe contentWindows) and clears the Note component's focus-update interval on unmount to prevent post-unmount callbacks. Changes
Sequence Diagram(s)sequenceDiagram
participant JestInit
participant Window
participant Iframe
participant ElementProto
JestInit->>Window: define __joplinJestPolyfillScroll(win)
JestInit->>Window: call polyfill on Window
Window->>ElementProto: ensure scrollIntoView/scrollTo/scrollBy (no-op if missing)
JestInit->>Iframe: create/patch iframe contentWindow
Iframe->>ElementProto: apply same polyfill to contentWindow
JestInit->>Iframe: attach message / parent.postMessage shims
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/app-mobile/components/ExtendedWebView/index.jest.tsx`:
- Around line 59-67: The polyfill unconditionally overwrites
Element/HTMLElement/SVGElement.scrollIntoView inside
window.__joplinJestPolyfillScroll; change it to only assign scrollNoop when the
method is missing to avoid clobbering existing implementations or test
spies—inside the function that iterates Ctor (used in
window.__joplinJestPolyfillScroll) check if Ctor.prototype.scrollIntoView is
falsy before setting it, keeping the existing conditional assignments for
scrollTo and scrollBy intact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 262c2a52-7530-4bc1-bbe7-a432ef082445
📒 Files selected for processing (2)
packages/app-mobile/components/ExtendedWebView/index.jest.tsxpackages/app-mobile/components/screens/Note/Note.tsx
In the ExtendedWebView Jest JSDOM polyfill, only define scrollIntoView/scrollTo/scrollBy when missing, so existing test spies are preserved.
|
When you copy and paste from your AI bot, make sure you include the formatting, or fix it afterwards. Pasting things like this makes it hard to read and it looks unprofessional |
hello laurent, sorry didn't mean to do this on purpose, just was in a hurry so might have mixed things up. I will keep this in mind from the next time. |
Fixes #14834
Problem
Running the mobile test suite could finish with Jest reporting “Cannot log after tests are done” after Note.test.tsx. The underlying error was TypeError: scrollIntoView is not a function inside the ExtendedWebView Jest mock’s nested JSDOM: renderer code schedules scrolling (e.g. hash / afterFullPageRender) on a timer, but JSDOM does not implement layout APIs like scrollIntoView. That led to uncaught errors after the test had already completed.
Separately, the Note screen could leave a focus polling interval running briefly after unmount in tests, which contributed to stray logging / teardown issues.
Solution
Scoped polyfill, not global: scrollIntoView / scrollTo / scrollBy are polyfilled only on the nested JSDOM window used by the ExtendedWebView test mock (and again for iframe contentWindows when the existing iframe polyfill runs). This fixes the renderer timers without patching the global Jest/jsdom Element prototype, which would break tests that assign their own scrollIntoView mock (e.g. index.handleAnchorClick.test.ts).
Lifecycle: clear the Note editor focus update interval in componentWillUnmount so it cannot keep firing after the screen is torn down in tests.
No change to production mobile behaviour; test / mock behaviour only (plus safe unmount cleanup).
Test Plan
yarn workspace @joplin/app-mobile test components/screens/Note/Note.test.tsx
yarn workspace @joplin/app-mobile test contentScripts/rendererBundle/contentScript/index.handleAnchorClick.test.ts