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/rslib/index.md.
close
  • 简体中文
  • Rslib

    Rslib 是基于 Rsbuild 的库开发工具,用于构建 JavaScript 库和 UI 组件库。

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

    快速开始

    新项目

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

    npx create-rslib --template react-ts --tools rstest --dir my-project

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

    已有项目

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

    复用 Rslib 配置

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

    安装适配器

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

    扩展配置

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

    适配器会读取 rslib.config.ts,转换测试编译需要的选项,将结果与 Rstest 配置合并,并将已加载的配置文件加入 forceRerunTriggers,因此当该配置发生变化时,--changed 会运行完整测试套件。

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

    完整的 options、配置映射、cache 行为和调试方法请查看配置参考

    相关文档