#71
test: add unit tests for src/cost.ts
Adds test/cost.test.ts covering the four exports of src/cost.ts:
- JEV_USD_PER_MTOK: matches the published rate
- newMeter: starts at zero
- addJevCost: correct token→USD math, accumulation, edge cases (NaN, Infinity, negative, zero, non-numbers, numeric strings), undefined meter safety
- addUsd: exact addition, accumulation, same edge cases
12 tests, all pass under bun test.
🤖 Generated with Claude Code
Summary by CodeRabbit
- Tests
- Added coverage for cost calculations, including token-to-USD conversion and accumulated totals.
- Verified handling of numeric strings and invalid inputs.
- Confirmed meter initialization and exact USD additions.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID:
7a453d45-db57-4ae9-9186-368f509908b8📥 Commits
Reviewing files that changed from the base of the PR and between 5c241afbb44e01f9e60a2d6184b6ce3621c83b36 and abea66b0c5ba48757997e7d4c7b8e3fa03c5cd06.
📒 Files selected for processing (1)
test/cost.test.tsIncluded review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.
📝 Walkthrough
Walkthrough
The pull request adds
test/cost.test.ts. The tests cover the exported JEV rate, meter initialization, JEV cost conversion, USD additions, accumulation, numeric strings, and invalid inputs.Changes
Cost module tests
test/cost.test.tsJEV_USD_PER_MTOK,newMeter(),addJevCost, andaddUsd. The tests cover conversion, accumulation, numeric strings, invalid values, and an undefined meter.Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Other
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.