test: configure in-source testing by ryoppippi · Pull Request #97 · ccusage/ccusage · GitHub
Skip to content

test: configure in-source testing#97

Merged
ryoppippi merged 9 commits into
mainfrom
vitest-in-source-testing
Jun 17, 2025
Merged

test: configure in-source testing#97
ryoppippi merged 9 commits into
mainfrom
vitest-in-source-testing

Conversation

@ryoppippi

@ryoppippi ryoppippi commented Jun 17, 2025

Copy link
Copy Markdown
Member

use vitest in-source testing

Summary by CodeRabbit

  • New Features

    • Introduced a terminal-adaptive table rendering feature for improved display in command-line output.
  • Refactor

    • Consolidated and reorganized internal imports for cleaner code structure.
    • Changed some internal type and function visibility to improve encapsulation.
  • Bug Fixes

    • No user-facing bug fixes in this release.
  • Tests

    • Replaced existing test suites with new, comprehensive unit and integration tests covering data loading, cost calculation, table rendering, and utility functions.
  • Chores

    • Updated configuration files for improved test environment setup and code formatting.

@coderabbitai

coderabbitai Bot commented Jun 17, 2025

Copy link
Copy Markdown

@pkg-pr-new

pkg-pr-new Bot commented Jun 17, 2025

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/ryoppippi/ccusage@97

commit: b566cc7

@ryoppippi ryoppippi force-pushed the vitest-in-source-testing branch from 36b262f to b566cc7 Compare June 17, 2025 19:55

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @ryoppippi, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request fundamentally changes how tests are structured and executed within the project by adopting an in-source testing approach with Vitest. This involves embedding test logic directly within the application's source files, significantly expanding test coverage for critical components like cost calculation, data loading, debugging utilities, pricing fetching, and session block identification. The accompanying build system updates ensure that these test-specific code blocks are automatically excluded from the final production bundles, maintaining code efficiency while enhancing development-time testability.

Highlights

  • In-source Testing Adoption: The project is transitioning to an in-source testing strategy using Vitest, embedding test logic directly within source files. This allows tests to live alongside the code they validate.
  • Extensive Test Coverage: Significant new test suites have been added across multiple core modules, including calculate-cost, data-loader, debug, pricing-fetcher, session-blocks, and utils, to validate existing functionality and ensure robustness.
  • Build System Integration for Test Stripping: The build configuration (tsdown.config.ts) has been updated to automatically remove these in-source test blocks from production builds, ensuring that test code does not ship with the final application bundle.
  • Module Consolidation and Refactoring: The ResponsiveTable utility has been moved from its dedicated file (utils.table.ts) into utils.internal.ts, streamlining the project's utility module structure and simplifying imports across various command files.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@ryoppippi ryoppippi merged commit 887e86b into main Jun 17, 2025
12 of 13 checks passed
@ryoppippi ryoppippi deleted the vitest-in-source-testing branch June 17, 2025 19:59
@ryoppippi

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces in-source testing with Vitest and a new ResponsiveTable class. The addition of tests is a positive step. However, several types in src/session-blocks.internal.ts need to be exported, and the ResponsiveTable class could benefit from improved maintainability and dedicated unit tests.

* Aggregated token counts for different token types
*/
export type TokenCounts = {
type TokenCounts = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The TokenCounts type is used in the exported SessionBlock type but is not exported itself. This can cause issues for TypeScript consumers of this library when trying to use SessionBlock or during declaration file generation.

Suggested change
type TokenCounts = {
export type TokenCounts = {

* Represents usage burn rate calculations
*/
export type BurnRate = {
type BurnRate = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The BurnRate type is the return type of the exported function calculateBurnRate but is not exported itself. Exporting it ensures type safety and proper declaration file generation.

Suggested change
type BurnRate = {
export type BurnRate = {

* Represents projected usage for remaining time in a session block
*/
export type ProjectedUsage = {
type ProjectedUsage = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The ProjectedUsage type is the return type of the exported function projectBlockUsage but is not exported itself. Exporting it is necessary for the module's public API to be correctly typed.

Suggested change
type ProjectedUsage = {
export type ProjectedUsage = {

Comment thread src/utils.internal.ts
Comment on lines +81 to +92

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ResponsiveTable class uses hardcoded indices to determine column widths. This makes the class tightly coupled to the specific column order. Consider using column type hints in TableOptions instead.

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.

1 participant