Setup Visual Testing 标志

Setup Visual Testing

组织
uiverify
setup-visual-testing

Set up UI Verify visual regression testing in a repo end to end — detect or scaffold the capture path (Storybook stories, a Playwright suite, Vitest browser-mode component tests, or Bun visual tests), install the uiverify CLI and wire it into CI, and author the first stories the economical, deterministic way from the start. Use when adding visual/screenshot regression testing to a project for the first time, wiring UI Verify into CI, or onboarding a repo that has no visual tests yet.

概览

发布者uiverify
代码仓库uiverify
技能名称setup-visual-testing
星标数
27
复刻数
1
附带文件
2
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载的 SKILL.md 文件,因此只有在请求确实匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 2 个随附文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 uiverify 发布于 GitHub。请在安装前查看源内容。

安装

在 TypingMind 中安装 Setup Visual Testing AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/uiverify/uiverify/tree/main/packages/skills/skills/setup-visual-testing
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/uiverify/uiverify.git /tmp/uiverify
mkdir -p .claude/skills
cp -r /tmp/uiverify/packages/skills/skills/setup-visual-testing .claude/skills/setup-visual-testing
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Setup Visual Testing,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Setup Visual Testing。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Setup Visual Testing 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会获取指令,因此未使用的技能不会产生额外费用。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Set up UI Verify, end to end

Goal: take a repo from no visual testing to a green UI Verify check on every PR, with the first stories authored the cheap + deterministic way so the setup doesn't start flaky or expensive. This skill is the conductor — it decides the capture path, wires CI, then hands the authoring and determinism work to the focused skills.

Step 1 — pick the capture path (don't ask the user; detect it)

UI Verify captures UI five ways. Choose by what the repo already has:

  • Storybook path — the repo has .storybook/ or @storybook/* in package.json, or is a component/design-system library. Each story is a snapshot. This is the default; prefer it when components exist in isolation.
  • Playwright path — the repo has a @playwright/test suite and you want to test assembled real pages (the app, staging, or prod), not isolated components. Each test archives its final UI state for UI Verify to replay + diff.
  • Vitest path — the repo already runs component tests in Vitest browser mode (@vitest/browser with a Playwright provider), and you want those component renders diffed without adopting Storybook. Each browser-mode test archives its final DOM. Prefer this over scaffolding Storybook only when a browser-mode suite already exists.
  • Bun path — the repo runs on Bun (a bun.lock / bun.lockb or bunfig.toml, bun test in its scripts, a Bun.serve app) and has no Storybook, Playwright or Vitest browser-mode suite to reuse. Visual tests run on bun test with @uiverify/bun, drive the installed Chrome, and archive each test's final page: real pages of the app (run({ webServer })) or components on a page serveBundle() builds. No Node test runner or browser download needed.
  • Screenshot-upload path — the repo is native / mobile / React Native (or otherwise can't render in a browser) but already produces finished screenshots from its own harness (Detox, Maestro, native snapshot tests). Upload those PNGs directly with --screenshots; UI Verify diffs, judges, and baselines them with no rendering. There are no stories to author and determinism is owned by your capture harness, so Steps 2-3 (client SDK + story authoring) don't apply — install the CLI (npm i -D uiverify), then jump to Step 4 and wire the CI upload with --screenshots ./screenshots in place of --static-dir. Upload only the screens a PR changed and the rest carry forward. iOS / Swift app with no screenshot harness yet: use swift-snapshot-testing; the helper, test, run command and macOS CI job are in references/ios-swift-screenshots.md.

If none exists and the repo is a browser app, scaffold Storybook (npx storybook@latest init) — it's the lower-friction path and gives you deterministic isolation for free (see storybook-visual-testing).

Step 2 — install the client

Storybook:

bash
npm i -D uiverify

Playwright — swap the import so every test also archives its UI state:

diff
- import { test, expect } from '@playwright/test';
+ import { test, expect } from '@uiverify/playwright';
bash
npm i -D @uiverify/playwright uiverify

Vitest — add the plugin to vitest.config.ts so every browser-mode test archives its final DOM:

ts
import { playwright } from '@vitest/browser-playwright';
import { uiverifyPlugin } from '@uiverify/vitest/plugin';
export default defineConfig({
  plugins: [uiverifyPlugin()],
  test: { browser: { enabled: true, provider: playwright(), instances: [{ browser: 'chromium' }] } },
});
bash
npm i -D @uiverify/vitest @vitest/browser-playwright uiverify

Bun — define a suite, write *.visual.ts tests, and a runner that starts the app (full setup and the component-page variant: bun-visual-testing):

ts
// tests/visual/fixtures.ts
import { DEFAULT_VIEWPORT, defineSuite } from '@uiverify/bun';
export const visualSuite = defineSuite({ viewports: { '': DEFAULT_VIEWPORT } });

// tests/visual/home.visual.ts
import { expect } from '@uiverify/bun';
import { visualSuite } from './fixtures';
const { test } = visualSuite(import.meta.path);
test('home', async (page) => {
  await page.goto('/');
  await expect(page.getByRole('heading', { name: 'Welcome' })).toBeVisible();
});

// tests/visual/run.ts — run with `bun tests/visual/run.ts`
import { run } from '@uiverify/bun/run';
// The server gets PORT and must listen on it; `ready` (optional) is how its "serving" log line begins.
process.exitCode = await run({ webServer: { command: ['bun', 'server.ts'], port: 3000, ready: 'Listening' } });
bash
bun add -d @uiverify/bun uiverify

It needs Bun 1.3.12+ and Google Chrome or Chromium.

Step 3 — author the first stories the right way

Don't snapshot whatever exists as-is. Author (or refactor) the first few stories using the two authoring skills, in this order:

  1. economical-visual-tests — collapse variant matrices into gallery/data-driven stories so you snapshot the fewest billable shots for full coverage. Do this before determinism work — fewer stories is less to make deterministic.
  2. storybook-visual-testing (Storybook), playwright-visual-testing (Playwright), vitest-visual-testing (Vitest), or bun-visual-testing (Bun) — remove the run-to-run variation the tool can't neutralize from outside your app (mostly: the clock, live data, infinite animations).

Step 4 — wire CI

Add a CI workflow that runs on every PR and on every push to the default branch. Both triggers are required; never write a PR-only workflow. Default-branch builds are the baseline every PR compares against, and they are what lets a PR render only the stories it touches. Without them every PR sees every story as new, compares nothing, and renders (and bills) the whole suite. Keep --auto-accept-changes on the upload: the expression below adds it only on the push run, so each merge becomes the baseline without a second review while PRs still wait for one. Store the project's UIVERIFY_API_KEY (a uv_proj_… key from the dashboard) as a repo secret, then run the uiverify CLI (installed in Step 2). Change [main] to whatever your default branch is (master, develop) — a repo whose default isn't main gets a push trigger that never fires.

Public repo? Write the fork-safe setup instead of the one job below. GitHub withholds secrets from a fork's pull request, so the one-job workflow has no key on a fork PR and the check never posts there. Check before writing any YAML: gh repo view --json visibility --jq .visibility. If it prints PUBLIC, write the two workflows in references/fork-safe-ci.md (capture with no key, then upload from a separate workflow_run workflow that never runs the PR's code), and tell the user the follow-ups listed at its end. If you can't tell (no gh, not on GitHub), ask the user whether the repo takes pull requests from forks. Background: https://uiverify.ai/docs/open-source-and-forks

yaml
# .github/workflows/visual.yml
name: Visual
on:
  push:
    branches: [main]                           # required: your default branch's builds are the baseline
  pull_request:
jobs:
  uiverify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with: { fetch-depth: 0 }             # full history so baseline ancestry works
      - uses: actions/setup-node@v4
        with: { node-version: 24, cache: npm }
      - run: npm ci
      - run: npm run build-storybook -- --stats-json    # ./storybook-static + the dependency graph
      - run: npx uiverify upload --static-dir storybook-static ${{ github.event_name == 'push' && '--auto-accept-changes' || '' }}
        env:
          UIVERIFY_API_KEY: ${{ secrets.UIVERIFY_API_KEY }}
        # Whatever you capture, keep the --auto-accept-changes expression at the end of the upload line.
        # Playwright / Vitest instead (browsers aren't preinstalled on the runner): run
        #   "npx playwright install --with-deps && npx playwright test"  (or "npx vitest run"), then
        #   "npx uiverify upload --static-dir uiverify-archive". Playwright must support the runner's OS (below).
        # Bun instead: add oven-sh/setup-bun@v2, drop setup-node's "cache: npm" and replace "npm ci"
        #   with "bun install --frozen-lockfile" (a Bun repo has no package-lock.json), then run
        #   "bun tests/visual/run.ts" (it drives the runner's preinstalled Chrome) and
        #   "npx uiverify upload --static-dir uiverify-archive". Keep setup-node: the CLI runs on Node 22.12 or later.
        # Screenshot upload (native / mobile / React Native): produce your PNGs (Detox, Maestro, etc.),
        #   then "npx uiverify upload --screenshots ./screenshots" in place of the build+upload steps.
        #   iOS / Swift: "runs-on: macos-15" and the xcodebuild step from references/ios-swift-screenshots.md.

Keep --stats-json on the build - it is the default, not a tuning step (see "Render only what the PR could have changed" below). Locally the same thing is:

bash
npm run build-storybook -- --stats-json && UIVERIFY_API_KEY=uv_proj_… npx uiverify upload --static-dir storybook-static
# Playwright:  npx playwright test && npx uiverify upload --static-dir uiverify-archive
# Vitest:      npx playwright install --with-deps && npx vitest run && npx uiverify upload --static-dir uiverify-archive
# Bun:         bun tests/visual/run.ts && npx uiverify upload --static-dir uiverify-archive

Playwright / Vitest: Playwright must be new enough for the CI machine's OS. Each Playwright release installs browsers only on the OS versions it knows about. When a CI image moves to a newer OS (a floating label like GitHub's ubuntu-latest, a :latest Docker base image, a hosted-runner upgrade on GitLab or CircleCI), an older Playwright fails at playwright install with Playwright does not support chromium on <os>, before any capture runs, so no build reaches UI Verify. When wiring CI, read the resolved playwright / @playwright/test version from the lockfile and bump it if it predates the runner's OS (Ubuntu 26.04, for example, needs 1.61+), keeping any mcr.microsoft.com/playwright image tag in step. If the user can't upgrade, pin the CI image to an OS version their Playwright supports. The bump doesn't move baselines: UI Verify renders every screenshot in its own browser, not the one the tests ran in.

Optional — run only on PRs that can change the UI. The workflow above fires on every PR, and a Playwright archive has no dependency graph of its own, so it renders in full unless you add one (a Vitest or Storybook upload already renders only what the PR could have changed — see below). On a busy repo, scope the job to UI-affecting changes. Two ways, and they differ on required checks:

  • Plain paths: filter — add paths: to the trigger. Simplest, but it skips the whole job, so it reports no status. If the UI Verify check is a required status check, a PR touching none of those paths is stuck "Expected" and can't merge. Use only when the check isn't required.
  • dorny/paths-filter (required-check-safe) — a first job computes whether UI files changed; the upload job always runs but guards each step on that result, so a backend-only PR no-ops yet still reports green and never wedges the required check. Prefer this.
yaml
# .github/workflows/visual.yml
on:
  push:
    branches: [main]          # advance the baseline as PRs merge
  pull_request:
jobs:
  changes:
    runs-on: ubuntu-latest
    outputs: { ui: '${{ steps.f.outputs.ui }}' }
    steps:
      - uses: actions/checkout@v4
        with: { fetch-depth: 0 }
      - uses: dorny/paths-filter@v4
        id: f
        with:
          filters: |
            ui:
              - 'src/components/**'
              - 'src/app/**'
              - 'packages/ui/**'                 # shared UI packages
              - '**/*.css'
              - '.github/workflows/visual.yml'    # the workflow itself
  uiverify:
    needs: changes
    runs-on: ubuntu-latest
    steps:                     # every step below is also guarded:  if: ${{ needs.changes.outputs.ui == 'true' }}
      - if: ${{ needs.changes.outputs.ui == 'true' }}
        uses: actions/checkout@v4
        with: { fetch-depth: 0 }
      # ...the setup-node / install / build / upload steps from Step 4, each guarded the same way.
      # Keep the upload's ${{ github.event_name == 'push' && '--auto-accept-changes' || '' }} from Step 4,
      # so the post-merge render becomes the baseline.

A missed render is silent — bias to include. An unnecessary run costs a few CI minutes; a missed one renders nothing, the check passes green, and the unseen change becomes the next baseline every branch inherits. So list every dir the UI is built from (components, pages, shared UI packages, global CSS) and the workflow file itself — and don't exclude a mixed folder just because it's mostly backend: a lib/ holding both a cn() helper the UI imports and unrelated db/AI code stays in the filter. If that over-runs, split the UI-facing code onto its own path, then filter on that — separate for granularity; never trade coverage for speed.

Render only what the PR could have changed — on by default for Storybook and Vitest. Whenever the upload carries a dependency graph, UI Verify renders just the stories your commit's changed files could affect and carries the rest of the baselines forward, so a PR's build time and bill track the size of the diff, not the size of the suite. It is safe from the first run - when it can't prove a story is unaffected it renders it, and a first build has nothing to carry, so it renders everything anyway. Local uploads are safe on the default too: files you haven't committed count as changed, so what they affect renders.

For Storybook the graph comes from the build, and an agent must not drop it: --stats-json writes preview-stats.json, the dependency graph the server reads. Without it every story renders, and the upload log says so on every run. If the repo already has a visual workflow, edit its build and upload steps in place rather than appending new ones, or the job builds Storybook twice and registers two builds per PR.

Vitest needs no build flag: @uiverify/vitest 1.6+ writes the Vite module graph into the archive on its own, so the plain upload is enough:

yaml
      - run: npx uiverify upload --static-dir uiverify-archive
        env:
          UIVERIFY_API_KEY: ${{ secrets.UIVERIFY_API_KEY }}

For Vitest the skip is only as granular as your test files: the server traces a changed source file to the tests that import it and carries the rest forward, so keep one page/component per *.visual.test.tsx file (each importing only what it renders). A file that colocates next to its component (SecurityPage.visual.test.tsx beside SecurityPage.tsx) lets a one-component change skip every other page; a single mega-test that imports half the app re-renders on every commit. A test whose imports git can't follow (bundler output, as under Angular's unit-test builder, a workspace package's built dist/, gitignored generated code) always renders; the test run prints [uiverify] The tests in N file(s) always render: ... with the reason. It does nothing for the Playwright path out of the box - a Playwright archive has no dependency graph, so every test renders unless you add a preview-stats.json to the archive directory yourself (module graph format). A Bun archive carries no dependency graph either, so every Bun test renders on every build: the path filter above is how a Bun suite stays off PRs that can't change the UI. Add the visual tests themselves (tests/visual/**) to that filter, or a PR that only edits a test skips its own capture.

Check the Storybook major before you write the build step - the flag is --stats-json on Storybook 8+, but --webpack-stats-json on 7.x, and passing the wrong one fails the build step before the upload ever runs.

Step 5 — the check gates every PR

Once wired, every PR gets a UI Verify check. The first run on your default branch captures the baseline; after that each PR is diffed against it, and a real visual regression (or an operational failure like a broken build or network error) turns the job red. Strict-by-default is intentional: a silently dropped upload must not leave CI green. If the first few diffs are noisy, don't disable the check — loop back to the determinism skill (Step 3) to remove the flake at its source.

Step 6 — connect your agent so it can see the diffs (MCP)

The check gates the PR; the MCP is how your coding agent reviews it without leaving the terminal — list builds, look at the actual before/after pixels, post them to the PR, accept baselines. Add it as a real MCP server (Claude Code, Cursor, Codex, …) — don't hand-roll curl, or the image tools come back as blocks a shell can't render. One command for Claude Code, run in the project root:

sh
claude mcp add --scope project --transport http uiverify https://uiverify.ai/mcp

Then restart Claude Code, run /mcp, pick uiverify, and log in to UI Verify in the browser. That one login reaches every project in every team the user belongs to, so it is done once, not per project, and there is no API key in the config: the committed .mcp.json holds only the URL and each teammate logs in with their own account.

Then hand the review loop to triage-visual-changes (it has the per-client setup and the recipes: bucket real regressions vs noise, put the before/after in the PR, bulk-accept). On a passed build the agent can still pull any story's current image by id to confirm it looks right.

Make it stick — install making-ui-changes and point your AGENTS.md / CLAUDE.md at it. The setup only pays off if new UI keeps getting captured, and it will only get captured if the agent reads the discipline on every UI change instead of when a human remembers to. So don't leave the customer to hand-edit CLAUDE.md — do it as part of setup: install the making-ui-changes skill (the playbook for changing UI safely — reuse before you create, add the story/capture in the same change, check the blast radius, prove it with a visual test), then add a one-line rule to both AGENTS.md and CLAUDE.md so every tool (Claude, Codex, Cursor, …) sees it:

md
## UI changes
- Before changing any component, page, or styles, read the `making-ui-changes` skill and follow it:
  reuse before you create, add/update the story or capture in the same change, check the blast radius on
  shared components, and prove the change with a visual test before calling it done.

That turns a one-time wiring into a habit the agent follows on every change.

Done when

  • A PR shows a UI Verify check with a baseline captured.
  • The first build's changed-stories list is empty or all-real (no clock/data/animation flake) — if not, loop back to the determinism skill for that path.
  • Stories cover the variants without one-story-per-combo explosion (economical-visual-tests applied).

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Setup Visual Testing AI 技能有什么作用?

Set up UI Verify visual regression testing in a repo end to end — detect or scaffold the capture path (Storybook stories, a Playwright suite, Vitest browser-mode component tests, or Bun visual tests), install the uiverify CLI and wire it into CI, and author the first stories the economical, deterministic way from the start. Use when adding visual/screenshot regression testing to a project for the first time, wiring UI Verify into CI, or onboarding a repo that has no visual tests yet.

为什么在 TypingMind 中使用 Setup Visual Testing?

因为您只需安装一次,就能搭配任何模型使用。Setup Visual Testing 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型,甚至可以在聊天中途切换模型,而不会影响技能正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Setup Visual Testing?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/uiverify/uiverify/tree/main/packages/skills/skills/setup-visual-testing。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Setup Visual Testing?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Setup Visual Testing 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以搭配 Setup Visual Testing 使用,包括 GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等,都可在 TypingMind 中使用您自己的 API 密钥接入。

Setup Visual Testing AI 技能免费吗?

是的。该技能源自 uiverify 在 GitHub 上以 MIT 许可证发布的项目。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇