test(cloudflare-workers): add comprehensive tests for websocket and conninfo adapters#4748
Open
rokasta12 wants to merge 1 commit intohonojs:mainfrom
Open
test(cloudflare-workers): add comprehensive tests for websocket and conninfo adapters#4748rokasta12 wants to merge 1 commit intohonojs:mainfrom
rokasta12 wants to merge 1 commit intohonojs:mainfrom
Conversation
…onninfo adapters Add 12 new tests to websocket.test.ts covering the complete upgradeWebSocket implementation: 101 response with webSocket client, server.accept() call, onClose/onError event handlers, conditional addEventListener (no-handler case), WSContext delegation (send, close), and WSContext properties (protocol, readyState, url, raw). Achieves 100% coverage of websocket.ts. Add 1 new test to conninfo.test.ts for absent cf-connecting-ip header, matching the pattern used in the Cloudflare Pages adapter tests.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4748 +/- ##
==========================================
+ Coverage 91.48% 91.50% +0.01%
==========================================
Files 177 177
Lines 11556 11556
Branches 3357 3364 +7
==========================================
+ Hits 10572 10574 +2
+ Misses 983 981 -2
Partials 1 1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Summary
websocket.test.ts(14 total, up from 2), achieving 100% statement/branch/function/line coverage ofwebsocket.tsconninfo.test.tsfor absentcf-connecting-ipheader, matching the pattern in the Cloudflare Pages adapterWebSocket Tests Added
Test Infrastructure
createMockWebSocketPair()helper that creates isolated mocks per test (EventTarget-based server withaccept/close/sendasvi.fn())CloseEventpolyfill for Node.js/vitest environmentResponseconstructor for the 101 status test (Node.js restricts status to 200-599, but Cloudflare Workers allows 101)Conninfo Test Added
getConnInfo()returnsundefinedaddress whencf-connecting-ipheader is absent (matches the existing pattern incloudflare-pages/conninfo.test.ts)Checklist
npx vitest --run src/adapter/cloudflare-workers/websocket.test.ts(14/14)npx vitest --run src/adapter/cloudflare-workers/conninfo.test.ts(2/2)npx tsc --noEmit— zero errorsbun run format:fix— no changes neededbun run lint:fix— zero errors (only pre-existing warnings)