pnpm sonamu test command runs tests through the Vitest instance hosted in the dev server. Since the dev server reuses already-loaded modules, you get faster feedback compared to pnpm test, which initializes everything from scratch each time.
Prerequisites
Two things are required to use this command:- Enable
devRunnerinsonamu.config.ts - Have the dev server running via
pnpm dev
sonamu.config.ts Configuration
api/src/sonamu.config.ts
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
enabled | boolean | false | Whether to enable DevRunner |
routePrefix | string | "/__test__" | Path prefix for test endpoints |
vitestConfigPath | string | - | Path to vitest.config.ts (relative to api-root) |
Basic Usage
Options
| Option | Short | Description |
|---|---|---|
--pattern <name> | -p <name> | Filter tests by name pattern |
How It Works
pnpm sonamu test invokes the resident Vitest instance inside the dev server via an HTTP request.
- The CLI sends a POST request to the dev serverโs
/__test__/runendpoint. - The dev serverโs
DevVitestManagerruns the tests using the resident Vitest instance. - Results are returned as JSON, and the CLI prints a summary.
Comparison with pnpm test
pnpm test | pnpm sonamu test | |
|---|---|---|
| Server required | No | pnpm dev must be running |
| Execution speed | Re-initializes each time | Reuses Vitest instance (fast) |
| HMR integration | None | Code changes reflected immediately |
| Use case | CI, full test suite | Quick feedback during development |
When to use which?
- During development: Use
pnpm sonamu testfor quick feedback. You can modify code and immediately run tests. - CI/CD: Use
pnpm test. It runs the full test suite in an isolated environment.
Status Check
To check the DevRunner status on the dev server, use the/__test__/status endpoint:
| Field | Description |
|---|---|
ready | Whether the Vitest instance is ready |
running | Whether tests are currently running |
lastRunAt | Timestamp of the last test run |
Troubleshooting
Cannot connect to dev server
pnpm dev.
DevRunner not enabled
test.devRunner.enabled to true in sonamu.config.ts and restart the dev server.