rstest-best-practices
Skill97 starsChanged 3 months agoMITView on GitHub
Set up, write, or review Rstest tests and configuration, including environments, mocks, snapshots, coverage, and CI.
We split this skill into the rules it gives an agent
20 rules. About 0 are common, 4 are distinctive, and 16 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
16
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 13
Add @rstest/core, a package-local test script, and a config file whose extension matches the package's module mode.
- Very specific: line 16
Verify test discovery with rstest list, then run focused tests, the full suite, and the project's existing build or type-check command.
- Very specific: line 20
Use defineConfig from @rstest/core and a config file extension compatible with the package's module mode.
- Very specific: line 21
Prefer explicit imports from @rstest/core over globals: true.
- Very specific: line 22
Use setupFiles for shared matchers and cleanup.
- Very specific: line 24
Use node for server/SSR tests, happy-dom or jsdom for simulated DOM tests, and Browser Mode for real-browser behavior.
- Distinctive: line 26
Use multiple test projects only when environments or configurations genuinely differ.
- Very specific: line 30
Prefer small tests that verify one public behavior.
- Distinctive: line 31
Keep test APIs and test files in the same module system as the project.
- Very specific: line 32
Prefer await expect(promise).resolves...
- Very specific: line 33
Use includeSource only for small utilities, guard tests with import.meta.rstest, and define it as false in production builds.
- Very specific: line 37
Use rs.fn() for functions, rs.spyOn() for object methods, and rs.mock() factories for modules.
- Distinctive: line 44
Keep snapshots small and deterministic: use inline snapshots for short output, file snapshots for large structured output, and serializers …
- Very specific: line 51
Use rstest for a single run.
- Very specific: line 52
Use rstest list to verify discovery, positional filters or -t for focused runs, -u for intentional snapshot updates, and -c for a …
- Very specific: line 54
If passing-test logs are too noisy, consider silent: 'passed-only'.
- Very specific: line 58
Start with a focused repro and --reporter=verbose.
- Very specific: line 59
Use DEBUG=rstest and inspect dist/.rstest-temp/.rsbuild/ to verify final Rstest/Rsbuild/Rspack configuration and generated build output.
- Distinctive: line 60
Use breakpoints through the Rstest VS Code extension or a JavaScript Debug Terminal for runtime failures.
- Very specific: line 61
Use rstest-debugging for systematic startup, build, runtime, logging, memory, or performance diagnosis.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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
passWithNoTestsunless 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
defineConfigfrom@rstest/coreand a config file extension compatible with the package's module mode. - Prefer explicit imports from
@rstest/coreoverglobals: true. - Use
setupFilesfor shared matchers and cleanup; useplugins,resolve, orsourcefor ordinary build integration and low-leveltoolsonly when necessary. - Set
includeexplicitly when the package's test layout is non-standard; do not assume the default discovery pattern. - Use
nodefor server/SSR tests,happy-domorjsdomfor 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
.skipor.todointentionally 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...overtry/catchpatterns that can miss assertions. - Use
includeSourceonly for small utilities, guard tests withimport.meta.rstest, and define it asfalsein production builds.
Mocking
- Use
rs.fn()for functions,rs.spyOn()for object methods, andrs.mock()factories for modules; mock external boundaries rather than the subject under test. - Choose
clearMocks,resetMocks, orrestoreMocksaccording 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
--coverageorcoverage.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.includedeliberately before adding thresholds; choose reporters for humans and CI artifacts separately.
Running and CI
- Use
rstestfor a single run;rstest runis an optional explicit equivalent. Userstest --watchorrstest watchonly for local development. - Use
rstest listto verify discovery, positional filters or-tfor focused runs,-ufor intentional snapshot updates, and-cfor a non-default config. - In CI, never use watch mode. Use sharding with blob reports and
rstest merge-reportswhen 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--printConsoleTracefor noisy or unclear console output. - Use
DEBUG=rstestand inspectdist/.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-debuggingfor systematic startup, build, runtime, logging, memory, or performance diagnosis.
Documentation
- For the latest Rstest docs, read https://rstest.rs/llms.txt
In this repository31 other files it gives its agents.
- AGENTS.mdAGENTS.md
- create-draft-release-notesSkill
- mdx-to-markdownSkill
- pr-creatorSkill
- release-blog-writerSkill
- rstack-docs-writerSkill
- rstack-eco-ci-debugSkill
- rstack-repo-maintainSkill
- rstack-skill-evaluatorSkill
- migrate-to-rsbuildSkill
- migrate-to-rslibSkill
- migrate-to-rslintSkill
- migrate-to-rstestSkill
- rsbuild-best-practicesSkill
- rsbuild-v2-upgradeSkill
- rsdoctor-analysisSkill
- rsdoctor-v2-upgradeSkill
- rslib-best-practicesSkill
- rslib-modern-packageSkill
- rspack-best-practicesSkill
- rspack-debuggingSkill
- rspack-split-chunksSkill
- rspack-tracingSkill
- rspack-v2-upgradeSkill
- rspress-best-practicesSkill
- rspress-custom-themeSkill
- rspress-description-generatorSkill
- rspress-docs-generatorSkill
- rspress-v2-upgradeSkill
- rstest-debuggingSkill
- storybook-rsbuildSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

