# How to Run Kimi-Code Tests: A Complete Guide to Vitest Testing in the MoonshotAI Repository

> Learn how to run Kimi-Code tests with Vitest in the MoonshotAI repository. Execute the full test suite or specific files easily using pnpm commands.

- Repository: [Moonshot AI/kimi-code](https://github.com/MoonshotAI/kimi-code)
- Tags: how-to-guide
- Published: 2026-08-11

---

**Use `pnpm test` to run the full Vitest test suite across the Kimi-Code monorepo, or `pnpm exec vitest run <path>` for specific test files.**

Running tests in the [MoonshotAI/kimi-code](https://github.com/MoonshotAI/kimi-code) repository requires understanding its Vitest-based testing architecture. The project uses a monorepo structure with multiple packages and applications, each with their own test suites. This guide explains how to run Kimi-Code tests at every level—from the entire codebase down to individual files.

## Prerequisites for Running Kimi-Code Tests

Before executing any tests, verify your environment meets the minimum requirements specified in the root [`package.json`](https://github.com/MoonshotAI/kimi-code/blob/main/package.json):

- **Node.js ≥ 24.15.0**
- **pnpm 10.33.0**

Install all workspace dependencies once:

```bash
pnpm install

```

This command installs Vitest and all dependencies across the monorepo's packages and applications.

## Understanding the Kimi-Code Test Architecture

The Kimi-Code repository uses **Vitest** as its test runner with a multi-project configuration. The key configuration lives in [`vitest.config.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/vitest.config.ts) at the repository root:

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

```

Vitest discovers test files in three project scopes:

- **`packages/*`** — All library packages (e.g., `tree-sitter-bash`)
- **`apps/kimi-code`** — The CLI/TUI application
- **`apps/vscode`** — The VS Code extension

Test files follow the standard Vitest naming convention: `*.test.ts` or `*.spec.ts`.

## Running the Full Kimi-Code Test Suite

### CI-Style Test Run

Execute all tests once across the entire monorepo:

```bash
pnpm test

```

This runs `vitest run` as defined in the root [`package.json`](https://github.com/MoonshotAI/kimi-code/blob/main/package.json) `scripts.test` entry. The command exits with a non-zero code if any test fails, making it suitable for CI pipelines.

### Development Watch Mode

For local development with automatic re-runs on file changes:

```bash
pnpm test:watch

```

This invokes `vitest` without the `run` flag, enabling Vitest's file watcher.

### Coverage Report Generation

Generate an HTML coverage report in the `coverage/` directory:

```bash
pnpm test:coverage

```

This executes `vitest run --coverage` using the coverage configuration from [`vitest.config.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/vitest.config.ts).

## Running Specific Kimi-Code Tests

### Single Test File

Target a specific test file using a glob pattern:

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

```

### Package-Specific Tests

Some packages include their own [`vitest.config.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/vitest.config.ts) that narrows test discovery. For example, [`packages/tree-sitter-bash/vitest.config.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/tree-sitter-bash/vitest.config.ts) limits tests to `test/**/*.test.ts`:

```bash
cd packages/tree-sitter-bash
pnpm exec vitest run

```

The root configuration automatically merges package-level configs when it lists `packages/*` as a project.

### Interactive UI Mode

Launch Vitest's browser-based UI for test exploration:

```bash
pnpm exec vitest --ui

```

## Kimi-Code Test Commands Reference

| Command | Purpose |
|---------|---------|
| `pnpm test` | Run all tests once (CI mode) |
| `pnpm test:watch` | Watch mode for development |
| `pnpm test:coverage` | Full suite with coverage report |
| `pnpm exec vitest run <path>` | Run specific test file or pattern |
| `pnpm exec vitest --ui` | Interactive browser UI |

## Example: Running Bash Parser Tests

The `tree-sitter-bash` package demonstrates typical Kimi-Code test structure. Its tests reside in [`packages/tree-sitter-bash/test/parser-compound.test.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/tree-sitter-bash/test/parser-compound.test.ts) and use standard Vitest APIs (`describe`, `it`, `expect`):

```bash

# Install dependencies

pnpm install

# Run all tests (includes Bash parser tests)

pnpm test

# Run only Bash parser tests

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

# Watch mode for Bash package

cd packages/tree-sitter-bash && pnpm exec vitest

```

## Key Configuration Files for Kimi-Code Testing

| File | Location | Role |
|------|----------|------|
| [`package.json`](https://github.com/MoonshotAI/kimi-code/blob/main/package.json) | Repository root | Defines `test`, `test:watch`, `test:coverage` scripts |
| [`vitest.config.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/vitest.config.ts) | Repository root | Multi-project Vitest configuration with three scopes |
| [`vitest.config.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/vitest.config.ts) | `packages/tree-sitter-bash/` | Package-level config limiting discovery to `test/**/*.test.ts` |
| [`parser-compound.test.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/parser-compound.test.ts) | `packages/tree-sitter-bash/test/` | Example test suite for the Bash parser |

## Summary

- **Kimi-Code uses Vitest** configured as a monorepo test runner via [`vitest.config.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/vitest.config.ts)
- **`pnpm test`** runs the complete test suite suitable for CI
- **`pnpm test:watch`** enables file-watching for development
- **Individual tests** execute with `pnpm exec vitest run <path>`
- **Package-level configs** in `packages/*/vitest.config.ts` extend the root configuration
- **Coverage reports** generate with `pnpm test:coverage`

## Frequently Asked Questions

### Why does Kimi-Code use Vitest instead of Jest?

Vitest provides native ESM support, faster execution through Vite's esbuild integration, and built-in TypeScript handling without additional configuration. As implemented in MoonshotAI/kimi-code, the unified Vitest configuration manages multiple projects through a single [`vitest.config.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/vitest.config.ts) file rather than separate Jest configurations per package.

### How do I debug a failing test in Kimi-Code?

Use the interactive UI with `pnpm exec vitest --ui` or add `--reporter=verbose` to any command for detailed output. You can also isolate a single test with `it.only()` or `describe.only()` in your test file, then run `pnpm test:watch` for rapid iteration.

### Can I run tests without installing all dependencies?

No. The monorepo structure requires `pnpm install` at the root to properly link workspace dependencies. Individual packages depend on shared utilities in `packages/*`, so the full installation is mandatory for tests to resolve imports correctly.