返回博客

Storybook 9 现已进入 beta 版

立即体验 UI 测试的未来

loading
Michael Shilman
@mshilman
最后更新

Storybook 9是我们迄今为止最具雄心的发布。Beta版本意味着9已具备所有功能并可供您的项目使用,但我们仍需要您的帮助才能最终完成。

我们的目标是让Storybook成为一个精简、高效的测试机器。以下是主要内容:

🚥 组件测试小部件
▶️ 交互测试
♿️ 可访问性测试
👁️ 视觉测试
🛡️ 测试覆盖率
🪶 打包体积减小48%
🏷️ 基于标签的组织
⚛️ React Native 支持设备和Web

Storybook's test widget. It's titled "Run components tests". Under that is "Testing... 1/97" with an eye and stop icons beside them. Then three rows of checkboxes labeled, Interactions, Coverage, and Accessibility, each with a gray status dot. Under that is another section, titled "Run visual tests in cloud". The final section has a "Run tests" button.

组件测试

组件测试是UI测试中的“金发姑娘”测试,结合了单元测试的速度和可靠性以及端到端(E2E)测试的浏览器内保真度。与更适合少数“正常路径”用户流程的E2E测试不同,组件测试可以编写和维护成千上万个,为您提供对所有关键UI状态的全面覆盖。

我们与Vitest合作,这是该生态系统中速度最快的测试运行器,旨在为您在开发组件时提供卓越的测试工具。

交互测试

交互测试帮助您模拟用户行为并断言组件是否正常工作。现在可以单独、批量或跨整个Storybook运行它们。启用监视模式,以便在保存更改时运行它们。

Storybook with the Filled Form story for the LoginForm component open. The Interactions panel is open, showing a passing test with the interactive debugger and each step of the interaction, all of which are successful.

可访问性测试

我们对可访问性工作流程进行了彻底的改进。与上面描述的功能测试一样,您现在可以跨所有故事运行可访问性测试,并通过新的高效UI检查违规情况。

Storybook, with the Empty Form story of the LoginForm component open. In the preview, a gray button is highlighted and a popover informs about a color contrast ratio violation. The Accessibility panel is open and more details about that violation are shown.

视觉测试

只需单击一下按钮,您就可以同时视觉测试所有故事,从而精确到像素的更改。

Storybook with the Primary story of the Button component open. The Visual tests panel is open, showing a visual diff between the baseline and the latest snapshot.

测试覆盖率

单击按钮,您可以计算测试覆盖率,以确切了解哪些行、函数和分支被您的组件测试执行。

Two browser windows. The foreground window shows an interactive coverage report. Many of the files have 100% coverage and are highlighted green, but card.tsx has 74% and is highlighted yellow. The background window shows Storybook's sidebar, where the coverage summary of 95% is visible.

体积减小48%

Storybook 9的体积不到Storybook 8的一半。其依赖结构也更加扁平;它安装速度更快,并且不会与您项目中的任何依赖项冲突。

Dependency graph, Before, A full-height, very complex dependency graph. After, a much simpler graph approximately 10% the size of the other one.
Storybook 8(左)与9(右)的依赖关系图

基于标签的组织

Storybook标签是侧边栏中组织和过滤故事的新方法。

Storybook's sidebar with the filter menu on the search bar open. There are two options, experimental and play-fn. The sidebar has been filtered to only show the Experimental Feature story under the Button component.

React Native无处不在

我们为React Native带来了官方的Web支持,为React Native带来了与Storybook的文档和测试功能的完全兼容性!

Marcelo Prado 的 React Native Flash Calendar 在 RNW 和 RN 中并排运行。RNW Storybook 包括 Docs 和 Test 插件。一次测试运行表明日历通过了所有 WCAG 可访问性检查!

使用自动化迁移轻松升级

您可以通过一个命令即可将项目升级到今天的Beta版

npx storybook@next upgrade

我们的自动化迁移系统将检测任何相关的破坏性更改,并逐步指导您完成整个过程,在可能的情况下提供代码转换器以尽可能地自动化。我们还提供了一个迁移指南来帮助填补空白。

我们需要您对9 Beta版的反馈

我们已经进行了多轮彻底的测试,因此您应该能够顺利升级。但测试的项目越多越好。如果您的项目中出现任何问题,请通过提交GitHub问题告知我们。整个团队都在待命,随时准备修复错误并回答您的问题。

Storybook 9现已发布Beta版!现在就可以尝试了。让我们来看看里面有什么……

Storybook (@storybook.js.org) 2025-04-24T20:03:42.562Z

加入 Storybook 邮件列表

获取最新消息、更新和发布信息

7,468开发者及更多

我们正在招聘!

加入 Storybook 和 Chromatic 团队。构建被数十万开发人员在生产中使用的工具。远程优先。

查看职位

热门帖子

Storybook 9

精益、高效的组件测试利器
loading
Michael Shilman

使用 Storybook 9 进行前端测试覆盖

Stories 为您提供免费的测试覆盖
loading
Dominic Nguyen

抢先看:可访问性插件 (Accessibility Addon) 更新

我们如何对 Storybook 9.0 中的可访问性插件进行大修
loading
Dominic Nguyen
加入社区
7,468开发者及更多
原因为什么选择 Storybook组件驱动的 UI
文档指南教程更新日志遥测
社区插件参与进来博客
展示探索项目组件词汇表
开源软件
Storybook - Storybook 中文

特别感谢 Netlify CircleCI