Skip to content

ci: provide WebSocket polyfill for tests on Node 20#63

Merged
islandbitcoin merged 1 commit into
mainfrom
fix/ci-websocket-polyfill-node20
Jul 8, 2026
Merged

ci: provide WebSocket polyfill for tests on Node 20#63
islandbitcoin merged 1 commit into
mainfrom
fix/ci-websocket-polyfill-node20

Conversation

@islandbitcoin

Copy link
Copy Markdown
Contributor

Problem

After #62 fixed the .env provisioning, the test job still failed on one suite — __tests__/App.test.tsx:

WebSocket implementation missing; on Node you can `import WebSocket from 'ws'` …
  at createClient (graphql-ws)  ← src/graphql/ApolloClient.ts:21  ← App.tsx  ← App.test.tsx

Root cause — a Node-version trap

ApolloClient.ts eagerly calls graphql-ws createClient at module load, which needs a WebSocket implementation. CI pins Node 20, where typeof WebSocket === "undefined", so it throws and the suite fails to run. Node 22+ exposes WebSocket as 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

ws is already a dependency (7.5.11) and jest.setup.js already exists, so alias it onto global.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:

Test Suites: 18 passed, 18 total
Tests:       142 passed, 142 total

Together with #62 this takes the test check fully green on main and every open PR (incl. #61).

🤖 Generated with Claude Code

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).
@islandbitcoin islandbitcoin merged commit 7672791 into main Jul 8, 2026
2 checks passed
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