happo

中文文档
7.3.0发布于 2026/11/04MITTypeScriptES Module

Catch unexpected visual and accessibility changes and UI bugs

原始使用文档
文档目录15 节
  1. 📚 Documentation
  2. 🚀 Features
  3. 📦 Installation
  4. 🛠️ Usage
  5. Basic Configuration
  6. CLI Usage
  7. 🔧 Configuration Options
  8. Supported Configuration Files
  9. Key Configuration Properties
  10. Blocking Approval
  11. Browser Targets
  12. 🤝 Contributing
  13. 📄 License
  14. 🔗 Links
  15. 💡 Support

Happo

License: MIT

An open source library for integrating with happo.io - a visual and accessibility regression testing platform that helps you catch unintended changes in your applications.

📚 Documentation

For comprehensive documentation, visit docs.happo.io.

🚀 Features

  • CLI Tool: Includes a command-line interface for easy integration
  • Flexible Configuration: Support for multiple configuration file formats
  • TypeScript Support: Built with TypeScript and provides full type definitions
  • ES Modules: Uses modern ES modules for better tree-shaking and performance

📦 Installation

npm install happo --save-dev
# or
pnpm add happo --save-dev
# or
yarn add happo --dev

🛠️ Usage

Basic Configuration

Create a happo.config.ts file in your project root:

import { defineConfig } from 'happo';

export default defineConfig({
  apiKey: process.env.HAPPO_API_KEY!,
  apiSecret: process.env.HAPPO_API_SECRET!,
  targets: {
    'chrome-desktop': {
      type: 'chrome',
      viewport: '1280x720',
    },
    'firefox-desktop': {
      type: 'firefox',
      viewport: '1280x720',
    },
    'ios-safari': {
      type: 'ios-safari',
    },
  },
});

CLI Usage

Run Happo using the CLI:

npx happo

The CLI will automatically find your configuration file and run the visual regression test suite.

🔧 Configuration Options

Supported Configuration Files

The library automatically detects configuration files in the following order:

  • happo.config.js
  • happo.config.mjs
  • happo.config.cjs
  • happo.config.ts
  • happo.config.mts
  • happo.config.cts

Key Configuration Properties

  • apiKey & apiSecret: Authentication credentials for happo.io
  • integration: Set up the integration type
  • targets: Target configurations, including regular browsers and accessibility targets
  • project: Optional project name
  • deepCompare: Optional settings for how diffs are computed
  • blockApproval: Optional conditions that block a comparison from being approved

Blocking Approval

Use blockApproval to prevent a comparison from being approved until certain problems are resolved:

export default defineConfig({
  // ...
  blockApproval: {
    // Block when the report has examples that failed to render
    renderErrors: true,
    // Block when the comparison introduces new accessibility violations
    accessibilityViolations: true,
    // Block when a page starts to scroll sideways (needs a target with
    // `detectHorizontalOverflow`)
    horizontalOverflow: true,
  },
});

Since this lives in the config, you can enable a condition in a single pull request (and fix the problems there) without affecting other work in the repository.

Browser Targets

Supported browser types:

  • Desktop: chrome, firefox, edge, safari, accessibility
  • Mobile: ios-safari, ipad-safari

Each target supports advanced options like:

  • Viewport sizing
  • Maximum dimensions
  • Color scheme preferences
  • Settings for silencing animations
  • Animated (APNG) snapshot capture via animate (experimental, not supported on ios-safari/ipad-safari)

🤝 Contributing

Issues are welcome at happo/happo. The package is developed in Happo's own repository now, so the code in happo/happo is no longer updated, and pull requests there can't be merged as they are.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

💡 Support

For support and questions:

版本与发布记录

happo 共发布 114 个版本,首次发布于 2016/11/23;过去 12 个月发布了 83 个版本。

版本发布日期距今
7.3.0latest2026/11/04今天
7.2.42026/11/021 天前
7.2.32026/10/286 天前
7.2.22026/10/287 天前
7.2.12026/10/287 天前
7.2.02026/10/268 天前

其他发布通道:beta → 6.0.0-beta.8。

关于 happo 的常见问题

happo 是什么?

捕捉意外的视觉和可访问性变化以及UI错误

如何安装 happo?

在项目目录运行 npm install happo,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 happo,可以用 npx happo 直接运行。

happo 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

happo 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

happo 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^22.18.0 || >=24.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

happo 可以商用吗?

happo 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

happo 还在维护吗?

最新版本 7.3.0 发布于 2026/11/04(今天);至今共发布 114 个版本,其中过去 12 个月发布了 83 个;首次发布于 2016/11/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。