For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/integration/rsbuild/index.md.
close
  • 简体中文
  • Rsbuild

    Rsbuild 是由 Rspack 驱动的 Web 应用构建工具,提供开箱即用的常见构建能力,并通过插件支持 React、Vue 等框架。

    如果你的应用使用 Rsbuild 构建,可以使用 Rstest 编写和运行测试,并通过适配器复用 Rsbuild 配置中与测试相关的部分,减少重复配置,让测试编译与应用构建保持一致。

    快速开始

    新项目

    创建 Rsbuild + Rstest 项目时,加上 --tools rstest

    npm create rsbuild@latest -- --tools rstest

    脚手架会包含 Rstest 和示例测试。使用 npm run test 运行测试。

    已有项目

    已有项目可以参考快速开始,完成 Rstest 的安装和测试脚本配置。

    复用 Rsbuild 配置

    @rstest/adapter-rsbuild 会读取 Rsbuild 配置,并将测试编译需要的配置转换为 Rstest 配置。

    安装适配器

    npm
    yarn
    pnpm
    bun
    deno
    npm add @rstest/adapter-rsbuild -D

    扩展配置

    rstest.config.ts
    import { defineConfig } from '@rstest/core';
    import { withRsbuildConfig } from '@rstest/adapter-rsbuild';
    
    export default defineConfig({
      extends: withRsbuildConfig(),
    });

    适配器会读取 rsbuild.config.ts,转换测试编译需要的选项,将结果与 Rstest 配置合并,并将已加载的配置文件加入 forceRerunTriggers,因此当该配置发生变化时,--changed 会运行完整测试套件。同时,它会移除 rsbuild:type-check plugin,因为测试流程不会执行类型检查。

    它不会复制 devserverhtml 等只用于构建的配置。如果默认配置位置或 environment 不适合当前项目,可以使用 cwdconfigenvironmentName

    如果其他工具已经在内存中生成了 Rsbuild 配置对象,可以使用 toRstestConfig 直接转换,而不必重新读取配置文件。两种入口、options、配置映射和调试方法请查看配置参考

    相关文档