Repository navigation
test(vitest): adapt happy-dom OffscreenCanvas canvas mocks - #17336
Conversation
Greptile SummaryThis PR adds a test-only compatibility layer that lets adapter-less happy-dom OffscreenCanvas 2D requests reuse the existing HTML canvas mock.
Confidence Score: 5/5The PR appears safe to merge with no actionable correctness or security issues identified. The compatibility layer is limited to test environments, safely no-ops when required DOM globals are absent, preserves existing OffscreenCanvas contexts, and delegates only null 2D results to the established HTML canvas mock.
|
| Filename | Overview |
|---|---|
| config/scripts/happy-dom-offscreen-canvas.ts | Adds a guarded, idempotent OffscreenCanvas 2D fallback that preserves available adapters and unsupported context behavior. |
| config/scripts/happy-dom-offscreen-canvas.test.ts | Covers adapter-less delegation, non-2D isolation, and successful xterm DOM renderer initialization. |
| config/vitest.config.ts | Loads the compatibility shim through the existing shared Vitest setup sequence. |
Sequence Diagram
sequenceDiagram
participant X as xterm
participant O as OffscreenCanvas
participant C as Compatibility wrapper
participant H as HTMLCanvasElement mock
X->>O: getContext("2d")
O->>C: adapter result
alt Existing adapter returns a context
C-->>X: existing context
else Adapter returns null
C->>H: getContext("2d")
H-->>C: test context
C-->>X: delegated context
end
Reviews (1): Last reviewed commit: "test: bridge happy-dom OffscreenCanvas c..." | Re-trigger Greptile
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughAdds a happy-dom compatibility shim for Merge Risk: ⚪ Minimal · up to This change adds a localized test-environment compatibility shim so xterm tests can construct canvas-backed renderers under newer happy-dom versions without changing production behavior. No actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description explains the root cause, fix, regression tests, verification, and scope. However, it does not follow the required template and omits required information, including an explicit Linked Issue entry, Visual Proof or the exact N/A statement, testing checklist and platform details, AI Disclosure, Review, Agent skill upstream boundary, Notes, and the final Checklist. Resolution Rewrite the description using all template headings. Add the issue reference in the Linked Issue section, provide visual proof or write exactly N/A with a reason, complete the Testing checklist with platforms tested, complete AI Disclosure when applicable, complete Review, Agent skill upstream boundary, Notes, and Checklist sections, and retain the existing root cause, fix, regression proof, and verification details.
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
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 |
|
CI result for head |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- OffscreenCanvas shim —
config/scripts/happy-dom-offscreen-canvas.tspatchesOffscreenCanvas.prototype.getContextso an adapter-less2dcontext delegates to the existingHTMLCanvasElement.prototype.getContextdouble; non-2d and real-adapter results pass through unchanged. Mirrors the establishedhappy-dom-mutation-observer-retention.tspattern (idempotency symbol, self-install, no-op when globals are absent). - Setup wiring —
config/vitest.config.tsregisters the shim as the firstsetupFilesentry. - Regression coverage —
config/scripts/happy-dom-offscreen-canvas.test.tsproves 2d delegation, non-2d isolation, and a realTerminal.open()succeeding against the current happy-dom DOM renderer.
The delegation reads HTMLCanvasElement.prototype.getContext at call time, so per-test vi.spyOn(...).mockReturnValue(...) doubles are picked up correctly, and the shim is a no-op in the default node environment (no OffscreenCanvas/HTMLCanvasElement/document). All three assertions would fail if the shim regressed, so the coverage is real rather than theatre. No production, IPC, wire, or rendering surface is touched.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
|
CI baseline note: all eight Node 24 test shards, typecheck, guards, LoC, Pullfrog, and Greptile pass. The only red is static analysis (and its aggregate verify), caused by the pre-existing NativeChatView max-lines violation at line 461; the same failure reproduces on origin/main and is isolated in #17339. The OffscreenCanvas compatibility diff itself has no lint findings and is ready for direct merge; #17339 clears the independent lint baseline separately. |

Root cause
happy-dom@20.11.8now exposesOffscreenCanvas, but without a configured canvas adapter itsgetContext("2d")returnsnull. xterm intentionally prefers that API and throws while creating itsWidthCache, so otherwise-unrelated unit shards fail before reaching their assertions. The same failure reproduces on the dependency upgrade PR #17330.Fix
Install one idempotent Vitest compatibility setup: when an OffscreenCanvas 2D context is adapter-less, delegate to the existing
HTMLCanvasElement.prototype.getContexttest double. Real adapters and non-2D contexts are returned unchanged. Production/browser code is untouched.Regression proof
Terminal.open()regression proving the current happy-dom setup can construct the DOM renderer.Local verification
oxlint --deny-warnings,oxfmt --check, andgit diff --check: passed.Readiness / elegance
Closes the post-#17330 test baseline regression affecting #17169, #17170, and #17172.