Set up visual regression testing in Bun
Write visual tests on bun test with @uiverify/bun, upload the archive, and wire CI so every pull request gets a screenshot diff. Captures with your installed Chrome.
Paste this into Claude Code, Cursor or any coding agent, in your repo. It reads our install guide, signs you in and sets everything up from there.
Set up UI Verify for Bun in this repo: fetch https://uiverify.ai/install.md with curl and follow it.
@uiverify/bun is UI Verify's capture SDK for Bun. Your visual tests run on bun test and drive the Chrome you have installed through Bun.WebView, and each test archives its final page: the serialized DOM plus the bytes of its images, fonts and stylesheets. UI Verify replays that archive in one pinned browser, screenshots it, and diffs it against the baseline. It is the same archive-replay engine the Playwright and Vitest integrations use, and there is no Playwright or Node test runner to install.
toHaveScreenshot(), see Bun visual regression testing.@uiverify/bun into a small project with this exact setup and its own CI workflow.BUN_CHROME_PATH to use another Chrome). The uiverify CLI that uploads the archive runs on Node 22.12 or later.1. Sign in
Sign in once on your machine. The command prints a link and a short code, opens the link in your browser when it can, and waits while you sign in (or sign up) and approve. No project key goes in your commands or your repository.
npx -y uiverify@1.10.0 loginYour first upload creates your project, named after your repository, and your first team, named after the repository's owner. If you made a project on the website first, pass --project <team>/<slug> to that upload so it goes there. If the sign-in can't finish, set UIVERIFY_API_KEY to the project key from your project's settings instead (under API keys). No project yet? Create one first at uiverify.ai/onboarding, under "Create a project", and its settings show the key. In CI, store that key as a repository secret named UIVERIFY_API_KEY. A repo with several apps? See Several apps in one repo.
2. Install the capture SDK
bun add -d @uiverify/bun@1.0.13. Define a suite
A suite sets what every test starts from: the viewports each test runs at, where the page clock starts (now, default 2026-01-01T00:00:00Z), and the color scheme. An optional second argument runs at the start of every test, which is where you stub the requests your pages make with page.route().
// tests/visual/fixtures.ts
import { DEFAULT_VIEWPORT, defineSuite } from "@uiverify/bun";
export const visualSuite = defineSuite({ viewports: { "": DEFAULT_VIEWPORT } });4. Write a visual test
Each *.visual.ts file is a visual test file. A test drives the page, and a test that never calls takeSnapshot() is snapshotted once when it ends. A snapshot's id is <file> > <describe> > <test>, plus ::<name> for a named snapshot and ::<viewport key> for a non-default viewport. A repeated test name gets (2) and a repeated snapshot name in one test gets #2. When that suffix matches a name you wrote yourself (a test literally named X (2) next to a repeated X), the second one fails with an error naming both, so rename one.
// tests/visual/home.visual.ts
import { expect, takeSnapshot } from "@uiverify/bun";
import { visualSuite } from "./fixtures";
const { test } = visualSuite(import.meta.path);
test("menu", async (page) => {
await page.goto("/");
await page.getByRole("button", { name: "Menu" }).click();
await expect(page.getByRole("menu")).toBeVisible();
await takeSnapshot("open"); // optional; a test with no takeSnapshot() is archived at its end
});expect is bun:test's, with retrying assertions for a locator (toBeVisible, toBeAttached, toHaveCount, toBeDisabled, toHaveValue, toHaveAttribute, and .not). Await them.
5. Add the runner script
run() starts your app's web servers (with PORT and UI_VERIFY=1 set), runs every *.visual.ts in its own bun test process, and writes the archive's index to ./uiverify-archive. Its test processes ignore your app's bunfig.toml, so a test preload such as happy-dom never replaces the test process's fetch. Keep your fixtures free of modules that need a loader or define registered there.
// tests/visual/run.ts
import { run } from "@uiverify/bun/run";
process.exitCode = await run({
webServer: { command: ["bun", "server.ts"], port: 3000 }, // your app's start command; it gets PORT
});Test components without running your app
To capture components rather than pages of a running app, build a preview page with serveBundle() and point the suite at it. The preview is an ordinary HTML page whose script mounts the components you capture. Pass the Bun.build plugins and constants your components need (Bun.build inlines no env, so a process.env.PUBLIC_* a component reads goes in define). With only component tests, drop webServer from the runner script: run() then starts no app.
import { afterAll } from "bun:test";
import { expect, serveBundle } from "@uiverify/bun";
import { visualSuite } from "./fixtures";
const preview = await serveBundle({
entrypoint: `${import.meta.dir}/preview/index.html`,
define: { "process.env.PUBLIC_API_URL": '"https://api.example.com"' },
});
afterAll(() => preview.stop());
const { test } = visualSuite(import.meta.path, { baseUrl: preview.url });
test("primary button", async (page) => {
await page.goto("/");
await expect(page.getByRole("button", { name: "Save" })).toBeVisible();
});6. Run your tests and upload the archive
bun tests/visual/run.ts # writes ./uiverify-archive
npx -y uiverify@1.10.0 upload --static-dir ./uiverify-archive7. Catch a change locally
You do not need CI or a pull request to see a diff. Change something visible in a page or component, such as a color or a label, then run the tests and upload again on the same commit. UI Verify diffs the new build against your first one and flags what moved. Open the build page it prints, where you accept or reject the change. Accepting promotes the new screenshot to the baseline for that branch.
8. Wire it into CI
Paste this one line into your coding agent and it adds the workflow below and the repository secret for you (it asks for your project key: copy it from your project's settings, under API keys). Or add the workflow yourself:
Wire UI Verify into CI for Bun in this repo: fetch https://uiverify.ai/ci.md with curl and follow it.GitHub's Ubuntu runners ship with Google Chrome, so the job sets up Bun, installs your dependencies, runs the visual tests and uploads. It also sets up Node for the uiverify CLI.
name: UI Verify
on:
push:
branches: [main] # your default branch: its builds are the baseline every PR compares against
pull_request:
jobs:
visual:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0 # full history so the baseline can be found
- uses: oven-sh/setup-bun@v2
- uses: actions/setup-node@v7
with:
node-version: 24
- run: bun install --frozen-lockfile
- run: bun tests/visual/run.ts
- run: |
npx -y uiverify@1.10.0 upload \
--static-dir uiverify-archive \
${{ github.event_name == 'push' && '--auto-accept-changes' || '' }}
env:
UIVERIFY_API_KEY: ${{ secrets.UIVERIFY_API_KEY }}push trigger on your default branch is required, not optional. Builds there keep the baseline every PR compares against up to date, and they are what lets a PR render only the stories it touches. A workflow that runs only on pull requests sees every story as new on every PR and renders all of them. --auto-accept-changes applies only to that push run: it accepts what you merged, so the baseline moves forward without a second review, while pull requests still wait for yours. Change [main] to whatever your default branch is (master, develop), or the trigger never fires.@uiverify/bun writes no dependency graph, which UI Verify needs to skip unchanged tests.UI Verify: <slug> a required status check, or add the auto-rerun workflow that clears the job the moment you accept. Both are in Require the check and auto-clear the CI job.9. Install the visual-testing skills
Give your coding agent the visual-testing playbooks so it can do the work in your repo: triage a build's changes, write economical visual tests, check an edit's visual impact before pushing, and keep captures deterministic. This installs just these skills, not the whole bundle. Restart the agent session afterward so they load.
npx skills add uiverify/uiverify \
--skill making-ui-changes \
--skill economical-visual-tests \
--skill triage-visual-changes \
--skill check-visual-changes \
--skill bun-visual-testing10. Review changes from your coding agent
Connect the UI Verify MCP and your agent can pull a build's changes into the conversation, look at each diff, read the AI judge's verdict, and accept the intended ones. See Triage visual changes from your coding agent.
claude mcp add --scope project --transport http uiverify \
https://uiverify.ai/mcpThen log in once: restart Claude Code, run /mcp, pick uiverify, and log in to UI Verify in your browser. After that the agent can reach every project in every team you are a member of. Project scope writes the server to your committed .mcp.json, so the whole team gets it, and the file holds no secret: each teammate logs in with their own account. Using Cursor, Codex, or another client? See UI Verify MCP server for coding agents for its setup.
11. Install the GitHub App
Install the UI Verify GitHub App from your project's setup page and point it at your repo, so it can post a check and a comment on each pull request. This is the one step your coding agent cannot do for you. It does not block getting started: your first upload and baselines work without it, so add it when you want the results to show up on GitHub.
What a Bun capture pins for you
Each capture starts from the same state, so a screenshot changes only when your UI does:
- Time and randomness. The page clock starts at the suite's
nowand runs untilpage.pauseClock(), andMath.randomis seeded. - Motion. Animations and transitions finish instantly, and
prefers-reduced-motionis set. - Locale. The timezone is UTC, the locale en-US, and the color scheme the suite's
colorScheme. - Loading. Before a snapshot it waits for the fonts in use, then for every image and CSS background, then for the page to stop moving.
- Isolation. Each test starts on a blank page with no routes or init scripts, no cookies, no history, and the storage of every origin the previous test touched cleared.
What it cannot pin is yours to fix at the source. A page whose elements keep moving on their own (a requestAnimationFrame loop, a Lottie) fails after 10 seconds, and a canvas that keeps redrawing is captured mid-frame: stop either while UI Verify captures with isUIVerify(). Live data belongs in fixtures, served with page.route(). A cross-site iframe runs in its own process, so its requests are not routed and it gets no clock or init scripts.
Deterministic Bun captures
Stop Bun visual-test diffs that flake without a real change.
Visual testing for agents
UI Verify is visual regression testing for Playwright, Storybook, Vitest and Bun. Your coding agent sees what its UI change did and fixes it before it ships. See how it works.
Get started