Skip to content

100% line/statement/function coverage, 97% branch#12

Merged
jackparnell merged 1 commit intomasterfrom
full-coverage
Apr 10, 2026
Merged

100% line/statement/function coverage, 97% branch#12
jackparnell merged 1 commit intomasterfrom
full-coverage

Conversation

@ColonistOne
Copy link
Copy Markdown
Collaborator

Summary

48 new unit tests covering every previously-untested method in `ColonyClient`. Coverage went from 62% → 100% lines/statements/functions and 73% → 97% branches.

Coverage results

Metric Before After
Statements 73.67% 100%
Branches 80.52% 97.18%
Functions 63.38% 100%
Lines 73.67% 100%

What was uncovered

The gap was 25+ methods that were thin `rawRequest` wrappers (comments, messaging, search, directory, following, notifications, colonies, webhooks, polls, deletePost, voteComment, getUser, getPoll) — exercised by integration tests against the live API but not by mocked unit tests.

What was added

  • Unit tests for every previously-untested method (correct URL, HTTP method, request body, response shape)
  • Branch-coverage tests for optional parameter paths (`offset`, `colony`, `tag`, `search`, `unreadOnly`, `signal`, etc.)
  • Edge case tests: empty 200 response, non-Error thrown from fetch, token cache eviction on 401 auto-refresh, `rotateKey` with signal + cache, `iterComments` empty first page, `extractItems` no-matching-key fallback

Remaining 3% branch gap

7 branches that are defensive code paths unreachable in unit tests:

  • Optional-chaining `?.signal` false branches on methods tested without signal (v8 counts each `?.` as its own branch)
  • `register()` `options.fetch ?? globalThis.fetch` fallback
  • `register()` non-Error catch branch

140 unit tests total (was 92), all green.

Test plan

  • `npm run lint` — clean
  • `npm run typecheck` — clean
  • `npm run format:check` — clean
  • `npm test` — 140/140 passing
  • `npm run test:coverage` — 100% lines, 97% branches
  • CI green

Added 48 new unit tests covering every previously-untested method in
ColonyClient — the coverage gap was thin wrappers around rawRequest
(comments, messaging, search, directory, following, notifications,
colonies, webhooks, polls, deletePost, voteComment, getUser, getPoll)
that were exercised only by integration tests but not by mocked unit
tests. Also added branch-coverage tests for optional parameter paths,
empty responses, non-Error fetch throws, token cache eviction on 401,
rotateKey with signal+cache, iterComments empty page, and the
extractItems no-matching-key fallback.

Coverage results:
  Statements: 100%
  Functions:  100%
  Lines:      100%
  Branches:   97.18% (remaining 7 are defensive optional-chaining
              branches and the register() globalThis.fetch fallback
              that can't be meaningfully hit in unit tests)

140 unit tests total (was 92), all green.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jackparnell jackparnell merged commit 13abfa5 into master Apr 10, 2026
3 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.

3 participants