Rstest setup — agent execution prompt

Follow these steps in order to add Rstest to the current project. Read the repository first. Make the smallest correct change.

Fetch a linked doc page only after choosing that branch. Do not fetch docs for branches you did not select.

Guardrails

Step 0 — Repo-wide inventory (no changes yet)

Before editing anything, determine:

Step 1 — find the owning package

Choose in this order:

  1. Package containing the source files being tested
  2. Package containing existing tests for that source
  3. Package containing the relevant build config
  4. If single-package repo, the root

Note: deps, config, and scripts may live in different places. Determine separately:

Step 2 — Package-scoped inventory

Now inspect the owning package:

Step 3 — detect language

Determine from the owning package's actual source/test file extensions first. Use tsconfig.json or typescript dep only as a tiebreaker.

Step 4 — detect build tooling → pick adapter

An adapter auto-inherits plugins, aliases, and build config. If using an adapter, follow that guide first — only fetch a framework guide if the adapter guide does not already cover the required setup.

When using an adapter you may still need to set testEnvironment or browser — the adapter does not decide those.

Step 5 — choose test environment

Decide based on what the tests actually need, not solely from framework deps in package.json. See https://rstest.rs/config/test/test-environment.md for all options.

A. No DOM APIs needed → node (default)

Omit testEnvironment. No extra deps. If not using an adapter and no other options are needed:

import { defineConfig } from '@rstest/core';
export default defineConfig({});

B. DOM APIs needed, simulated DOM is sufficient → happy-dom / jsdom

Use for tests that render components or rely on DOM APIs.

C. Real browser behavior needed → browser mode (experimental)

Choose only when tests explicitly require Canvas, WebGL, CSS computed styles, Web Workers, or cross-browser testing. This is opt-in, not a default escalation. Vue Browser Mode is not yet supported. See https://rstest.rs/config/test/browser.md for all options.

→ Follow https://rstest.rs/guide/browser-testing/getting-started.md → For React component testing in browser, also follow https://rstest.rs/guide/browser-testing/framework-guides.md

Step 6 — install dependencies

Use the repo's existing package manager (pnpm add -D, npm i -D, yarn add -D, bun add -d) based on the lockfile. Fall back to the packageManager field in root package.json if no lockfile exists. Install only packages justified in previous steps.

Step 7 — create config

Keep it minimal — include only options justified by detection. → See https://rstest.rs/guide/basic/configure-rstest.md only if the selected guide above does not fully specify the config.

Config examples are in the guide pages linked in Steps 4–5. Do not copy examples blindly.

Step 8 — update scripts

If migration is intended, you should already be following the migration guide — skip this step.

Step 9 — verification test (only if needed)

Only if no tests exist and verification is needed:

Step 10 — validate

Run the test command from wherever the test script lives. If it fails, read the error and fix — do not leave a broken setup. If no tests exist and you skipped Step 9, confirm the setup is valid (config loads, rstest --passWithNoTests or equivalent succeeds).