skills/rstest-best-practices/SKILL.md
Rstest best practices for config, CLI workflow, test writing, mocking, snapshot testing, DOM testing, coverage, multi-project setup, CI integration, performance and debugging. Use when writing, reviewing, or troubleshooting Rstest test projects.
npx skillsauth add rstackjs/agent-skills rstest-best-practicesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Apply these rules when writing or reviewing Rstest test projects.
rstest.config.ts and defineConfig from @rstest/coreimport { test, expect, describe } from '@rstest/core' over globals: true@rstest/adapter-rsbuild with extends: withRsbuildConfig() to reuse build config@rstest/adapter-rslib with extends: withRslibConfig() to reuse build configsetupFiles for shared test setup (e.g., custom matchers, cleanup hooks)@rsbuild/plugin-react), add them via the plugins fieldtools.rspack or tools.bundlerChainrstest or rstest run to run tests (run disables watch mode, suitable for CI)rstest --watch or rstest watch for local development with file watchingrstest list to list all test files and test namesrstest -u to update snapshots--reporter=verbose when debugging test failures for detailed output--config (-c) to specify a custom config file path@rstest/core: test, describe, expect, beforeEach, afterEach, etc.test or it for test cases; use describe for grouping related tests.only to focus on specific tests during development, but never commit .only to the codebase.skip or .todo to mark incomplete or temporarily skipped testsawait expect(fn()).rejects.toThrow(ErrorClass) (or .rejects.toMatchObject({ ... })) over try/catch with expect.fail or .catch(e => e) patterns — the matcher form fails clearly if the promise unexpectedly resolves, keeps the assertion in one chain, and avoids forgetting to assert the throw at allawait expect(fn()).resolves.toEqual(...) for the same reasonincludeSource for in-source testing of small utility functions (Rust-style import.meta.rstest)if (import.meta.rstest) { ... } and define import.meta.rstest as false in production build configtestEnvironment: 'node' (default) for Node.js / server-side codetestEnvironment: 'jsdom' or testEnvironment: 'happy-dom' for DOM / browser API testingjsdom or happy-dom as a dev dependency when using DOM environmentshappy-dom for faster DOM testing; use jsdom when better browser API compatibility is needed@rstest/browser with Playwrightnode and jsdom projects)@rsbuild/plugin-react plugin and @testing-library/react for component testing@rsbuild/plugin-vue plugin and @testing-library/vue for component testingrstest.setup.ts with expect.extend(jestDomMatchers) and afterEach(() => cleanup()) for Testing LibrarysetupFiles in configtestEnvironment: 'node' and test with react-dom/server or framework-specific SSR APIsrs.mock('./module') to mock modulesrs.fn() to create mock functionsrs.spyOn(object, 'method') to spy on methodsclearMocks, resetMocks, or restoreMocks config options to automatically clean up mocks between testsrs.mock('./module', () => ({ ... })) to provide mock implementationstoMatchSnapshot() for general snapshot testingtoMatchInlineSnapshot() for small, readable inline snapshotstoMatchFileSnapshot() for large or structured outputs (e.g., HTML, generated code)expect.addSnapshotSerializer() to mask paths or sensitive data in snapshotspath-serializer to normalize file paths across platforms--coverage CLI flag or coverage.enabled: true in config@rstest/coverage-istanbul for the Istanbul coverage providercoverage.include to specify source files for coverage (e.g., ['src/**/*.{js,ts,tsx}'])coverage.thresholds to enforce minimum coverage requirementscoverage.reporters to generate reports in different formats (e.g., text, lcov, html)projects field in root config to define multiple test projects'packages/*' to auto-discover sub-projectsdefineProject helper in sub-project configsmergeRstestConfig to compose project configsreporters, pool, isolate, coverage, bail) must be set at the root level, not in projectsrstest run (not rstest watch) in CI--shard for parallel test execution across CI machines (e.g., --shard 1/3)--reporter=blob with rstest merge-reports to combine sharded results--reporter=junit with outputPath for CI report integrationgithub-actions reporter is auto-enabled in GitHub Actions for inline error annotations--bail to stop early on first failure when appropriateisolate (--no-isolate) when tests have no side effects for faster execution via module cache reusepool.maxWorkers to control parallelism based on available resourcesrstest <pattern> or -t <name>) to run only relevant tests during developmentDEBUG=rstest to enable debug mode, which writes final configs and build outputs to diskdist/.rstest-temp/.rsbuild/ to confirm final Rstest/Rsbuild/Rspack configrstest with breakpoints--reporter=verbose for detailed per-test output--printConsoleTrace to trace console calls to their source@rstest/core/bin/rstest.jsRSDOCTOR=true rstest run to analyze test build performancesamply for native profiling of both main and worker processes--heap-prof for memory profilingrstack.rstest) for in-editor test running and debugging@rstest/adapter-rslib for config reuse@rstest/adapter-rsbuild for config reuseprocess.env.RSTEST to detect test environment and apply test-specific configdevelopment
Debug Rstest issues systematically, including performance regressions. First determine whether the slowdown is in build startup or test execution, then run controlled config or code experiments and compare before/after timings.
development
Opinionated Rslib recommendations for modern JS/TS npm package design covering pure ESM, strict TypeScript, explicit exports, small stable APIs, pragmatic dependencies, accurate sideEffects, correct declarations, package validation, provenance, README.md, and AGENTS.md. Use when the user wants to make a JS/TS package more modern, check whether the current package setup is healthy, review package.json/exports/types/dependencies/docs/release readiness, or apply a modern library baseline.
development
Create or update draft GitHub releases for the current project's main GitHub repository, then organize GitHub-generated release notes into user-friendly sections without rewriting release note items. Use for preparing, formatting, categorizing, creating, or updating GitHub release notes or draft releases, including optional highlights when the user asks for them.
tools
Migrate ESLint or other linters to Rslint. Use when asked to replace ESLint flat config, lint scripts, VS Code ESLint settings, inline directives, rules, presets, plugins, or lint dependencies with Rslint equivalents.