test(fetch): add full test coverage for fetchHeaders#85
Open
dmchaledev wants to merge 1 commit into
Open
Conversation
The HTTP layer (fetch.ts) had 0% test coverage despite being a critical production path. This adds 14 tests covering request shape, header normalization, body cleanup, timeout behavior, and error propagation. Overall statement coverage rises from ~91.8% to 98.8%; functions reach 100%. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ESVT2ALHK9VjPbeZh6Ky6Q
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
fetch.ts— the HTTP layer responsible for fetching remote headers — had 0% test coverage despite being a critical production path. A regression here could cause silent hangs, memory leaks, or wrong headers returned to callers with no failing tests to catch it.This PR adds 14 focused tests in
test/fetch.test.tsthat cover every behavior infetchHeaders:GET, follows redirects, attaches anAbortSignal{}res.body?.cancel()is called to avoid reading/retaining the response body;nullbody is handled gracefully; errors fromcancel()are swallowed (matching the existing/* body may be absent or already closed */comment)timeoutMsoption is forwarded tosetTimeout; defaults to 10 000 ms; theAbortControllerfires at exactly the right moment; the timer is cleared in both success and error paths (viafinally)fetchbubble up unchangedCoverage impact
fetch.tslinesTest plan
npm test— all 99 tests pass (85 existing + 14 new)npm run test:coverage—fetch.tsno longer appears in the uncovered-lines tablenpm run typecheck— no TypeScript errorsGenerated by Claude Code