ci: provide WebSocket polyfill for tests on Node 20#63
Merged
Conversation
App.test.tsx fails to run in CI with "WebSocket implementation missing": it imports App -> src/graphql/ApolloClient.ts, which eagerly calls graphql-ws createClient at module load, requiring a WebSocket impl. CI pins Node 20 (no global WebSocket); Node 22+ provides it, which masks the issue in local dev. `ws` is already a dependency, so alias it onto global.WebSocket in jest.setup.js. Verified under Node 20: full suite 18/18 suites, 142 tests pass. Second half of the CI test fix (follows the .env provisioning in #62).
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.
Problem
After #62 fixed the
.envprovisioning, thetestjob still failed on one suite —__tests__/App.test.tsx:Root cause — a Node-version trap
ApolloClient.tseagerly callsgraphql-wscreateClientat module load, which needs aWebSocketimplementation. CI pins Node 20, wheretypeof WebSocket === "undefined", so it throws and the suite fails to run. Node 22+ exposesWebSocketas a global, which is why the failure is invisible in local dev (and why it looked like #62 should have been enough).Confirmed both ways: under Node 24 the suite passes; nvm'd to Node 20 (CI's version) it reproduces the exact error.
Fix
wsis already a dependency (7.5.11) andjest.setup.jsalready exists, so alias it ontoglobal.WebSocket. Version-agnostic and minimal (vs. bumping CI's Node, which has broader ripple effects).Verification
Applied locally, switched Node to 20 (matching CI), ran the full suite:
Together with #62 this takes the
testcheck fully green onmainand every open PR (incl. #61).🤖 Generated with Claude Code