Vitest helpers
Test Reion apps with Vitest—auto boot from reion.config, HTTP client, and minimal boilerplate.
@reionjs/vitest wraps Vitest so you can start a real HTTP server from your reion.config.* (using the project root / process.cwd()), run requests with fetch, and tear the server down automatically.
Install
Peer dependencies: reion, vitest.
npm exec reion add -p @reionjs/vitestyarn dlx reion add -p @reionjs/vitestbunx reion add -p @reionjs/vitestpnpm exec reion add -p @reionjs/vitestAlso install Vitest if you have not:
bun add -d vitestnpm install -D vitest @reionjs/vitestyarn add -D vitest @reionjs/vitestbun add -d vitest @reionjs/vitestpnpm add -D vitest @reionjs/vitestVitest config
Add a minimal vitest.config.ts at your project root:
import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
environment: "node",
},
});Writing tests
Import describe, it, and expect from @reionjs/vitest (not only from vitest) so each suite boots a Reion server from reion.config.* at process.cwd().
import { describe, it, expect } from "@reionjs/vitest";
describe("GET /api/hello", () => {
it("returns JSON", async ({ request }) => {
const res = await request.get("/api/hello");
expect(res.status).toBe(200);
expect(await res.json()).toEqual({ hello: "world" });
});
});The it callback receives:
request— helpers:get,post,put,patch,delete,fetch(rooted at the test server).baseUrl— e.g.http://localhost:<port>.server— metadata andclose()if you need manual teardown.
Custom setup
When you need custom boot behavior (different cwd, appDir, or host), use createTestServer() directly and build your request client from createRequestClient().
Escape hatch
You can still call createTestServer() and createRequestClient() from @reionjs/vitest for custom setups.
Run tests
bunx vitest run
# or
npx vitest runNext steps
- Routing — URL mapping and handlers.
- Middleware — order and
next().