Skip to content

test: increase coverage for token-usage.ts (55%→95%) and vscode-sessions.ts (45%→92%) - #172

Open
kannupriyakalra wants to merge 1 commit into
mainfrom
feat/coverage-token-usage-vscode
Open

test: increase coverage for token-usage.ts (55%→95%) and vscode-sessions.ts (45%→92%)#172
kannupriyakalra wants to merge 1 commit into
mainfrom
feat/coverage-token-usage-vscode

Conversation

@kannupriyakalra

Copy link
Copy Markdown
Collaborator

Summary

  • token-usage.ts: 55% → 95% statements
  • vscode-sessions.ts: 45% → 92% statements
  • 33 new tests added across two test files, all 147 tests pass

What was added

token-usage.test.ts

  • Full coverage of parseClaudeCodeJsonl: sidechain skip, <synthetic> model skip, missing usage, zero-total skip, malformed JSON, multi-line files
  • getTokenUsage source filtering tests (copilot-cli / claude-code / all) using temp-dir fixtures + vi.mock("os")
  • Weekly/monthly bucket tests and per-model token breakdown for aggregate

vscode-sessions-api.test.ts (new file)

  • Tests listVSCodeSessions, getVSCodeSession, isVSCodeSession, getVSCodeAnalytics against real temp-dir session JSON files
  • Configurable better-sqlite3 mock via mockDatabase() helper
  • Key finding: Vitest 4 requires regular function expressions (not arrow functions) in mockImplementation when the mock is called with new — arrow functions throw "is not a constructor"

Test plan

  • Run npm test — all 147 tests pass
  • Run npx vitest run --coverage — confirm token-usage.ts ≥ 95%, vscode-sessions.ts ≥ 90%

Closes #170
Closes #171

🤖 Generated with Claude Code

token-usage.ts: 55% → 95% statements
- Adds tests for parseClaudeCodeJsonl (0% → fully covered): sidechain skip,
  synthetic model skip, missing usage, zero-total skip, malformed JSON lines,
  multi-line files
- Adds tests for getTokenUsage source filtering (copilot-cli / claude-code / all)
  using temp-dir fixtures + vi.mock("os")
- Adds weekly/monthly bucket and per-model breakdown tests to aggregate suite

vscode-sessions.ts: 45% → 92% statements
- New vscode-sessions-api.test.ts tests the public API (listVSCodeSessions,
  getVSCodeSession, isVSCodeSession, getVSCodeAnalytics) with a configurable
  better-sqlite3 mock and temp-dir session JSON fixtures
- Key fix: Vitest 4 requires regular functions (not arrow functions) in
  mockImplementation when the mock is called with `new`

Closes #170
Closes #171

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Increase test coverage for vscode-sessions.ts (45% → 80%) Increase test coverage for token-usage.ts (55% → 80%)

1 participant