MCPInstall

rstest-best-practices

Set up, write, or review Rstest tests and configuration, including environments, mocks, snapshots, coverage, and CI.

Installs
1.4K
Last 24h
—
Trending rank
—
Security
Not audited

Install

Works with every agent the skills CLI supports.

npx skills add https://github.com/rstackjs/agent-skills --skill rstest-best-practices
  1. 01

    Install

    Run the command in your project. The CLI asks which agents to install for.

  2. 02

    Describe the task

    Ask your agent for something this skill covers. It loads rstest-best-practices automatically when relevant.

  3. 03

    Review the result

    The agent follows the SKILL.md steps, scripts and references bundled with the skill.

SKILL.md

The instructions your agent reads when the skill is triggered.

Rstest best practices

Apply these rules when setting up, writing, or reviewing Rstest projects.

Workflow

  • Inspect the existing package manager, dependency policy, module mode, build configuration, test layout, and framework conventions before editing.
  • Add @rstest/core, a package-local test script, and a config file whose extension matches the package's module mode.
  • Reuse existing build configuration only when doing so lowers maintenance cost and remains compatible. An adapter is optional; use an independent Rstest config when adapter integration is incompatible or disproportionately costly, and explicitly reproduce required aliases, plugins, defines, environments, and externals.
  • Configure test discovery, environment, and setup files intentionally. Do not enable passWithNoTests unless an empty test set is an expected and documented state.
  • Verify test discovery with rstest list, then run focused tests, the full suite, and the project's existing build or type-check command.

Configuration and environments

  • Use defineConfig from @rstest/core and a config file extension compatible with the package's module mode.
  • Prefer explicit imports from @rstest/core over globals: true.
  • Use setupFiles for shared matchers and cleanup; use plugins, resolve, or source for ordinary build integration and low-level tools only when necessary.
  • Set include explicitly when the package's test layout is non-standard; do not assume the default discovery pattern.
  • Use node for server/SSR tests, happy-dom or jsdom for simulated DOM tests, and Browser Mode for real-browser behavior; install the selected environment package explicitly.
  • For React or Vue component tests, register the matching build plugin, use the corresponding Testing Library, and centralize matcher extension and cleanup in a setup file.
  • Use multiple test projects only when environments or configurations genuinely differ; keep global options such as reporters, coverage, pool, isolation, and bail at the root.

Test writing

  • Prefer small tests that verify one public behavior; use .skip or .todo intentionally and never commit .only.
  • Keep test APIs and test files in the same module system as the project; do not mix ESM/CJS assumptions without verifying the runtime and bundler behavior.
  • Prefer await expect(promise).resolves... and .rejects... over try/catch patterns that can miss assertions.
  • Use includeSource only for small utilities, guard tests with import.meta.rstest, and define it as false in production builds.

Mocking

  • Use rs.fn() for functions, rs.spyOn() for object methods, and rs.mock() factories for modules; mock external boundaries rather than the subject under test.
  • Choose clearMocks, resetMocks, or restoreMocks according to whether calls, implementations, or original methods must be restored between tests.
  • Choose the module-mocking API that matches the module system; verify the exact request string and register hoisted/static mocks before the module under test is evaluated.
  • Module mocks replace runtime behavior but do not necessarily remove the real dependency from the Rspack build graph. Use aliases or narrowly scoped externals only when the build still traverses an unwanted or unavailable dependency, and verify the runtime externalization format.

Snapshots and coverage

  • Keep snapshots small and deterministic: use inline snapshots for short output, file snapshots for large structured output, and serializers for paths or unstable data. Review every update.
  • Enable coverage with --coverage or coverage.enabled.
  • Choose a coverage provider supported by the installed Rstest version and add its package explicitly; do not copy a V8 or Istanbul provider choice without checking project needs.
  • Set coverage.include deliberately before adding thresholds; choose reporters for humans and CI artifacts separately.

Running and CI

  • Use rstest for a single run; rstest run is an optional explicit equivalent. Use rstest --watch or rstest watch only for local development.
  • Use rstest list to verify discovery, positional filters or -t for focused runs, -u for intentional snapshot updates, and -c for a non-default config.
  • In CI, never use watch mode. Use sharding with blob reports and rstest merge-reports when distributing tests; use JUnit when the CI system requires machine-readable results.
  • If passing-test logs are too noisy, consider silent: 'passed-only'; disable it temporarily when diagnosing setup or runtime output.

First-line debugging

  • Start with a focused repro and --reporter=verbose; use --printConsoleTrace for noisy or unclear console output.
  • Use DEBUG=rstest and inspect dist/.rstest-temp/.rsbuild/ to verify final Rstest/Rsbuild/Rspack configuration and generated build output.
  • Use breakpoints through the Rstest VS Code extension or a JavaScript Debug Terminal for runtime failures.
  • Use rstest-debugging for systematic startup, build, runtime, logging, memory, or performance diagnosis.

Documentation

FAQ

What does the rstest-best-practices skill do?

Set up, write, or review Rstest tests and configuration, including environments, mocks, snapshots, coverage, and CI.

How do I install rstest-best-practices?

Run npx skills add https://github.com/rstackjs/agent-skills --skill rstest-best-practices in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/rstest-best-practices/ (personal) or .claude/skills/rstest-best-practices/ (project).

Which AI agents can use rstest-best-practices?

Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.

Is rstest-best-practices safe to install?

No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.

Who maintains rstest-best-practices?

It is published by rstackjs in rstackjs/agent-skills. It has 1,406 recorded installs.

More from rstackjs/agent-skills

View all →

rsbuild-best-practices

rstackjs/agent-skills

Configure, review, or troubleshoot Rsbuild applications, including build/dev commands, assets, type checking, and bundle optimization.

rslib-best-practices

rstackjs/agent-skills

Configure, review, or troubleshoot Rslib library builds, output formats, declarations, dependency handling, and integrations.

rspack-best-practices

rstackjs/agent-skills

Configure, review, or troubleshoot Rspack builds, including loaders, CSS, assets, type checking, bundle optimization, and profiling.

rspress-best-practices

rstackjs/agent-skills

Configure, review, or troubleshoot Rspress v2 sites, including content conventions, navigation, MDX, assets, search, and deployment.

rspack-v2-upgrade

rstackjs/agent-skills

Use when upgrading a Rspack 1.x project to v2, including dependency and configuration updates.

AI & Agents517 installs

rspress-description-generator

rstackjs/agent-skills

Generate missing description frontmatter for Rspress Markdown/MDX pages, including new docs pages and site-wide SEO metadata updates.

Docs & Writing500 installs

Popular code quality & workflow skills

View category →

grill-me

mattpocock/skills

A relentless interview to sharpen a plan or design.

Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.

handoff

mattpocock/skills

Compact the current conversation into a handoff document for another agent to pick up.

domain-modeling

mattpocock/skills

Build and sharpen a project's domain model. Use when discussing codebase terminology, writing or editing a GLOSSARY.md, or recording or editing an ADR.

codebase-design

mattpocock/skills

Shared vocabulary for designing deep modules. Use when the user wants to design or improve a module's interface, find deepening opportunities, decide where a seam goes, make code more testable or AI-navigable, or when another skill needs the deep-module vocabulary.

diagnosing-bugs

mattpocock/skills

Diagnosis loop for hard bugs and performance regressions. Use when the user says "diagnose"/"debug this", or reports something broken/throwing/failing/slow.