Token导航 LogoToken导航TokenDH.com
开发规范敏感数据github未标认证来源可访问许可证需确认审计通过

rstest-best-practicesrs 测试最佳实践

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

3,096

周安装

133

GitHub Stars

64

下载量

1,085
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:rstest-best-practices(rs 测试最佳实践)
来源仓库:https://github.com/rstackjs/agent-skills
仓库路径:skills/rstest-best-practices
安装命令:
npx skills add https://github.com/rstackjs/agent-skills --skill rstest-best-practices
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

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

简介

用于辅助测试设计、自动化测试、用例整理和回归验证,适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。

  • 适用于测试框架搭建、测试用例设计和回归验证等开发规范场景。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装并使用。
  • 使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑。
  • rstest-best-practices 属于开发规范类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Rstest Best Practices

Apply these rules when writing or reviewing Rstest test projects.

Configuration

  • Use rstest.config.ts and defineConfig from @rstest/core
  • Prefer explicit imports import {test, expect, describe} from '@rstest/core' over globals: true
  • For Rsbuild projects, use @rstest/adapter-rsbuild with extends: withRsbuildConfig() to reuse build config
  • For Rslib projects, use @rstest/adapter-rslib with extends: withRslibConfig() to reuse build config
  • Use setupFiles for shared test setup (e.g., custom matchers, cleanup hooks)
  • When using Rsbuild plugins (e.g., @rsbuild/plugin-react), add them via the plugins field
  • For deep-level or advanced build configuration needs, use tools.rspack or tools.bundlerChain

CLI

  • Use rstest or rstest run to run tests (run disables watch mode, suitable for CI)
  • Use rstest --watch or rstest watch for local development with file watching
  • Use rstest list to list all test files and test names
  • Use rstest -u to update snapshots
  • Use --reporter=verbose when debugging test failures for detailed output
  • Use --config (-c) to specify a custom config file path

Test writing

  • Import test APIs from @rstest/core: test, describe, expect, beforeEach, afterEach, etc.
  • Use test or it for test cases; use describe for grouping related tests
  • Use .only to focus on specific tests during development, but never commit .only to the codebase
  • Use .skip or .todo to mark incomplete or temporarily skipped tests
  • Prefer small, focused test cases that test a single behavior
  • For async error paths, prefer await 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 all
  • For async happy paths, use await expect(fn()).resolves.toEqual(...) for the same reason
  • Use includeSource for in-source testing of small utility functions (Rust-style import.meta.rstest)
  • For in-source tests, wrap test code in if (import.meta.rstest) {...} and define import.meta.rstest as false in production build config

Test environment

  • Use testEnvironment: 'node' (default) for Node.js / server-side code
  • Use testEnvironment: 'jsdom' or testEnvironment: 'happy-dom' for DOM / browser API testing
  • Install jsdom or happy-dom as a dev dependency when using DOM environments
  • Prefer happy-dom for faster DOM testing; use jsdom when better browser API compatibility is needed
  • For real browser testing, use @rstest/browser with Playwright
  • Use inline project configs to run different test environments within one project (e.g., node and jsdom projects)

React / Vue testing

  • For React: use @rsbuild/plugin-react plugin and @testing-library/react for component testing
  • For Vue: use @rsbuild/plugin-vue plugin and @testing-library/vue for component testing
  • Create a rstest.setup.ts with expect.extend(jestDomMatchers) and afterEach(() => cleanup()) for Testing Library
  • Add the setup file to setupFiles in config
  • For SSR testing, use testEnvironment: 'node' and test with react-dom/server or framework-specific SSR APIs

Mocking

  • Use rs.mock('./module') to mock modules
  • Use rs.fn() to create mock functions
  • Use rs.spyOn(object, 'method') to spy on methods
  • Prefer clearMocks, resetMocks, or restoreMocks config options to automatically clean up mocks between tests
  • Use factory functions in rs.mock('./module', () => ({...})) to provide mock implementations

Snapshot testing

  • Use toMatchSnapshot() for general snapshot testing
  • Use toMatchInlineSnapshot() for small, readable inline snapshots
  • Use toMatchFileSnapshot() for large or structured outputs (e.g., HTML, generated code)
  • Keep snapshots concise — only include relevant data, avoid timestamps and session IDs
  • Use expect.addSnapshotSerializer() to mask paths or sensitive data in snapshots
  • Use path-serializer to normalize file paths across platforms
  • Review snapshot changes carefully in code review

Coverage

  • Enable coverage with --coverage CLI flag or coverage.enabled: true in config
  • Install @rstest/coverage-istanbul for the Istanbul coverage provider
  • Use coverage.include to specify source files for coverage (e.g., ['src/**/*.{js,ts,tsx}'])
  • Use coverage.thresholds to enforce minimum coverage requirements
  • Use coverage.reporters to generate reports in different formats (e.g., text, lcov, html)

Multi-project testing

  • Use projects field in root config to define multiple test projects
  • For monorepos, use glob patterns like 'packages/*' to auto-discover sub-projects
  • Use defineProject helper in sub-project configs
  • Extract shared config and use mergeRstestConfig to compose project configs
  • Global options (reporters, pool, isolate, coverage, bail) must be set at the root level, not in projects

CI integration

  • Use rstest run (not rstest watch) in CI
  • Use --shard for parallel test execution across CI machines (e.g., --shard 1/3)
  • Use --reporter=blob with rstest merge-reports to combine sharded results
  • Use --reporter=junit with outputPath for CI report integration
  • The github-actions reporter is auto-enabled in GitHub Actions for inline error annotations
  • Use --bail to stop early on first failure when appropriate

Performance

  • Disable isolate (--no-isolate) when tests have no side effects for faster execution via module cache reuse
  • Use pool.maxWorkers to control parallelism based on available resources
  • Keep test build fast by avoiding unnecessary Rspack plugins in test config
  • Use test filtering (rstest <pattern> or -t <name>) to run only relevant tests during development
  • Leverage watch mode's incremental re-runs for fast local feedback

Debugging

  • Run with DEBUG=rstest to enable debug mode, which writes final configs and build outputs to disk
  • Read generated files in dist/.rstest-temp/.rsbuild/ to confirm final Rstest/Rsbuild/Rspack config
  • Use VS Code's JavaScript Debug Terminal to run rstest with breakpoints
  • Use --reporter=verbose for detailed per-test output
  • Use --printConsoleTrace to trace console calls to their source
  • Add VS Code launch config for debugging specific test files with @rstest/core/bin/rstest.js

Profiling

  • Use Rsdoctor with RSDOCTOR=true rstest run to analyze test build performance
  • Use samply for native profiling of both main and worker processes
  • Use Node.js --heap-prof for memory profiling

Toolchain integration

  • Use the official VS Code extension (rstack.rstest) for in-editor test running and debugging
  • For Rslib libraries, use @rstest/adapter-rslib for config reuse
  • For Rsbuild apps, use @rstest/adapter-rsbuild for config reuse
  • Use process.env.RSTEST to detect test environment and apply test-specific config

Documentation

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.16%
按下载量换算360

Claude

30.65%
按下载量换算333

Cursor

20.91%
按下载量换算227

Gemini CLI

10.01%
按下载量换算109

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills