How to Run Tests in Kimi-Code: Complete Vitest Guide for the Monorepo

To run tests in the Kimi-Code repository, execute pnpm test at the root to launch Vitest across the entire monorepo, or use pnpm test:watch for continuous testing during development.

The MoonshotAI/kimi-code project uses Vitest as its test runner within a pnpm-managed workspace. Testing is configured centrally through the root vitest.config.ts while allowing package-level overrides for specific modules like the Bash parser.

Prerequisites: Node.js and pnpm Requirements

Before running tests, ensure your environment matches the engine specifications defined in the root package.json. You need Node.js ≥ 24.15.0 and pnpm 10.33.0. Install all workspace dependencies first:

pnpm install

This command installs Vitest and all dependencies across the packages/* and apps/* directories.

Running the Full Test Suite

The root package.json defines the main test script that executes vitest run:

pnpm test

This command references the global configuration in vitest.config.ts, which specifies three project scopes for test discovery:

// vitest.config.ts
export default defineConfig({
  test: {
    projects: ['packages/*', 'apps/kimi-code', 'apps/vscode'],
    coverage: { /* ... */ },
  },
});

Vitest automatically discovers all *.test.ts and *.spec.ts files within these directories:

  • packages/* – Library packages including tree-sitter-bash
  • apps/kimi-code – The CLI/TUI application
  • apps/vscode – The VS Code extension

For example, the Bash parser tests reside in packages/tree-sitter-bash/test/parser-compound.test.ts and are executed as part of the full suite.

Running Specific Tests and Watch Mode

To run a single test file rather than the entire suite, pass a glob or specific path directly to Vitest:

pnpm exec vitest run packages/tree-sitter-bash/test/parser-compound.test.ts

For development workflows, use watch mode to automatically re-run affected tests when files change:

pnpm test:watch

The test:watch script is defined as "vitest" in the root package.json, launching Vitest's persistent watch process.

Generating Coverage Reports

To produce an HTML coverage report in the coverage/ directory, run:

pnpm test:coverage

This executes vitest run --coverage using the coverage configuration defined in the root vitest.config.ts.

Package-Level Configuration

Individual packages can define their own Vitest configurations that merge with the root settings. For instance, packages/tree-sitter-bash/vitest.config.ts limits test discovery to that package's local test/ directory:

// packages/tree-sitter-bash/vitest.config.ts
export default defineConfig({
  test: {
    include: ['test/**/*.test.ts'],
  },
});

When the root config lists packages/* as a project, Vitest automatically respects these package-level overrides while maintaining the global test context.

Summary

  • Use pnpm test to execute the complete Vitest suite across all monorepo projects (packages/*, apps/kimi-code, apps/vscode).
  • Use pnpm test:watch for continuous testing during local development.
  • Use pnpm exec vitest run <path> to target specific test files like packages/tree-sitter-bash/test/parser-compound.test.ts.
  • Use pnpm test:coverage to generate HTML coverage reports.
  • The root vitest.config.ts controls global configuration, while individual packages like tree-sitter-bash can provide project-specific settings.

Frequently Asked Questions

What test runner does the kimi-code repository use?

Kimi-code uses Vitest as its test runner. The configuration is centralized in the root vitest.config.ts file, which defines the monorepo project structure and coverage settings according to the MoonshotAI/kimi-code source code.

How do I run tests for only one package in kimi-code?

Navigate to the specific package directory (e.g., packages/tree-sitter-bash) and run pnpm exec vitest run, or specify the path from the root using pnpm exec vitest run packages/<package-name>/test/<file>.test.ts. The root configuration automatically merges with any package-local vitest.config.ts files.

What Node.js version is required to run tests?

The repository requires Node.js ≥ 24.15.0 and pnpm 10.33.0, as specified in the engines field of the root package.json. These versions ensure compatibility with the Vitest configuration and workspace protocols used in the monorepo.

How do I generate a test coverage report in kimi-code?

Run pnpm test:coverage from the repository root. This executes vitest run --coverage and outputs an HTML report to the coverage/ directory, utilizing the coverage configuration defined in the root vitest.config.ts.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →