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

> Learn to run tests in Kimi-Code with Vitest. Execute pnpm test at the monorepo root or use pnpm test:watch for continuous development testing.

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

---

**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`](https://github.com/MoonshotAI/kimi-code/blob/main/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`](https://github.com/MoonshotAI/kimi-code/blob/main/package.json). You need **Node.js ≥ 24.15.0** and **pnpm 10.33.0**. Install all workspace dependencies first:

```bash
pnpm install

```

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

## Running the Full Test Suite

The root [`package.json`](https://github.com/MoonshotAI/kimi-code/blob/main/package.json) defines the main test script that executes `vitest run`:

```bash
pnpm test

```

This command references the global configuration in **[`vitest.config.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/vitest.config.ts)**, which specifies three project scopes for test discovery:

```typescript
// 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`](https://github.com/MoonshotAI/kimi-code/blob/main/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:

```bash
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:

```bash
pnpm test:watch

```

The `test:watch` script is defined as `"vitest"` in the root [`package.json`](https://github.com/MoonshotAI/kimi-code/blob/main/package.json), launching Vitest's persistent watch process.

## Generating Coverage Reports

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

```bash
pnpm test:coverage

```

This executes `vitest run --coverage` using the coverage configuration defined in the root [`vitest.config.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/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`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/tree-sitter-bash/vitest.config.ts)** limits test discovery to that package's local `test/` directory:

```typescript
// 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`](https://github.com/MoonshotAI/kimi-code/blob/main/packages/tree-sitter-bash/test/parser-compound.test.ts).
- **Use `pnpm test:coverage`** to generate HTML coverage reports.
- The root [`vitest.config.ts`](https://github.com/MoonshotAI/kimi-code/blob/main/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`](https://github.com/MoonshotAI/kimi-code/blob/main/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`](https://github.com/MoonshotAI/kimi-code/blob/main/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`](https://github.com/MoonshotAI/kimi-code/blob/main/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`](https://github.com/MoonshotAI/kimi-code/blob/main/vitest.config.ts).