Plugins

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/vitest
yarn dlx reion add -p @reionjs/vitest
bunx reion add -p @reionjs/vitest
pnpm exec reion add -p @reionjs/vitest

Also install Vitest if you have not:

bun add -d vitest
npm install -D vitest @reionjs/vitest
yarn add -D vitest @reionjs/vitest
bun add -d vitest @reionjs/vitest
pnpm add -D vitest @reionjs/vitest

Vitest config

Add a minimal vitest.config.ts at your project root:

vitest.config.ts
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().

src/router/api/hello/hello.test.ts
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 and close() 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 run

Next steps