Skip to content

test(fetch): add full test coverage for fetchHeaders#85

Open
dmchaledev wants to merge 1 commit into
mainfrom
claude/nice-mendel-wvbny2
Open

test(fetch): add full test coverage for fetchHeaders#85
dmchaledev wants to merge 1 commit into
mainfrom
claude/nice-mendel-wvbny2

Conversation

@dmchaledev

Copy link
Copy Markdown
Contributor

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.ts that cover every behavior in fetchHeaders:

  • Request shape — uses GET, follows redirects, attaches an AbortSignal
  • Header normalization — all response header keys are lowercased; empty headers return {}
  • Body cleanupres.body?.cancel() is called to avoid reading/retaining the response body; null body is handled gracefully; errors from cancel() are swallowed (matching the existing /* body may be absent or already closed */ comment)
  • TimeouttimeoutMs option is forwarded to setTimeout; defaults to 10 000 ms; the AbortController fires at exactly the right moment; the timer is cleared in both success and error paths (via finally)
  • Error propagation — network errors from fetch bubble up unchanged

Coverage impact

Metric Before After
Statements 91.8% 98.8%
Branches 96% 97.4%
Functions ~96% 100%
fetch.ts lines 0% 100%

Test plan

  • npm test — all 99 tests pass (85 existing + 14 new)
  • npm run test:coveragefetch.ts no longer appears in the uncovered-lines table
  • npm run typecheck — no TypeScript errors

Generated by Claude Code

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
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.

2 participants