/biloba-vitest:setupfrom biloba-vitest
Wires Biloba's TypeScript client into Vitest — installs biloba, chrome-headless-shell, starts a shared Chrome in global setup, creates daemon and root Session per test file, and handles lifecycle.
Ships in biloba-vitest. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Install biloba; it pulls in the bilobad daemon binary via a per-platform npm package — no Go toolchain needed:
npm install -D vitest biloba
That resolves to biloba plus exactly one of biloba-darwin-arm64, biloba-darwin-x64, biloba-linux-x64, biloba-linux-arm64. Windows isn't supported yet — the daemon-resolution error there names building bilobad from source (go install github.com/onsi/biloba/cmd/[email protected]) plus BILOBA_DAEMON_EXECUTABLE as the workaround.
Then fetch the Chrome build the daemon drives, once per Chrome version:
npx biloba install-chrome
This runs bilobad install-chrome: downloads Chrome for Testing's current Stable chrome-headless-shell into a per-user cache (~/Library/Caches/biloba on macOS, ~/.cache/biloba on Linux) and prints the path. A no-op once that version is cached. Biloba never downloads Chrome silently — autoInstall: true is the opt-in. Chrome lookup order: an explicit chromePath, BILOBA_CHROME_HEADLESS_SHELL, chrome-headless-shell on PATH, then the newest build across the puppeteer and Biloba caches. On Linux arm64, Chrome for Testing ships no chrome-headless-shell build at all; install a distro Chromium and launch it explicitly: startSharedBrowser({mode: "headless", chromePath: "/usr/bin/chromium"}) (path varies by distro; on Debian-based images such as the official node images, apt-get install -y chromium; Ubuntu's chromium is a snap that doesn't run in containers).
Start one Chrome for the entire run:
// global-setup.ts
import {startSharedBrowser, type SharedBrowserConnection, type SharedBrowserProcess} from "biloba";
import type {TestProject} from "vitest/node";
declare module "vitest" {
export interface ProvidedContext {
chromeConnection: SharedBrowserConnection;
}
}
let browser: SharedBrowserProcess | undefined;
export async function setup(project: TestProject): Promise<void> {
browser = await startSharedBrowser({mode: "headless-shell"});
project.provide("chromeConnection", browser.connection);
}
export async function teardown(): Promise<void> {
await browser?.stop();
}
The declare module "vitest" augmentation is required — project.provide/inject don't type-check without it. Declare it once, in the global setup file.
Create one daemon and root session in each test file:
import {inject} from "vitest";
import {connect, type Browser, type Session} from "biloba";
let browser: Browser;
let session: Session;
beforeAll(async () => {
browser = await connect({chromeConnection: inject("chromeConnection")});
session = await browser.openSession();
});
beforeEach(async () => { await session.prepare(); });
afterAll(async () => { await browser.close(); });
Register globalSetup in the Vitest config. Keep test files parallel: the architecture assumes one worker process and daemon per file.
connect/startSharedBrowser resolve the daemon executable in order: an explicit daemonExecutable/executable option, BILOBA_DAEMON_EXECUTABLE, then the platform package alongside biloba. Both overrides exist for a source build or an unsupported platform — you don't normally need either.--omit=optional, or node_modules installed on a different OS than it's running on), the error names both causes.bilobad version reports the daemon's own version. If an overridden daemon's version differs from the biloba package's, connect emits a BILOBA_VERSION_MISMATCH process warning (skipped for dev builds).chromeConnection from global setup for a suite. Omitting it launches one Chrome per daemon and is suitable only for a single file or isolated debugging.chromeConnection over the legacy chromeWsUrl; the structured connection retains validated launch metadata.startSharedBrowser and a self-launching connect accept mode, chromePath, autoInstall, chromeSandbox, ordered chromeArgs, and windowSize."headless-shell", "headless", and "headful"; the default viewport is 1024×768.bilobad auto-adds --no-sandbox when running as root or when the kernel reports AppArmor is restricting unprivileged user namespaces (the default on Ubuntu 23.10+/ubuntu-latest, where a cached chrome-headless-shell otherwise fails with "No usable sandbox"). Headful and every other OS are untouched. chromeSandbox: true/false overrides the automatic decision; unset it to leave it automatic. Doesn't apply when attaching via chromeConnection/chromeWsUrl — attaching launches nothing.diagnostics to configure failure, progress, and on-demand capture. artifactDir is a compatibility alias.biloba supports Vitest 3, 4, and 5 (peer range >=3 <6); Vitest 5 needs Node ≥22.12, biloba itself needs Node ≥20. poolOptions/minWorkers are gone as of Vitest 4 — use top-level maxWorkers/isolate.prepare() before every test.newTab() for sibling tabs in the same browser context. Root sessions have isolated cookies and storage.Browser in afterAll; global teardown stops the shared Chrome.Authoring → biloba-vitest:write-tests. Diagnostics → biloba-vitest:debug-failures. Docs: https://onsi.github.io/biloba/vitest.html.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub onsi/biloba --plugin biloba-vitest7 skills in this plugin
/debug-failuresDiagnose Biloba failures in TypeScript/Vitest — BilobaError codes and fields, polling trajectories, DOM outlines, screenshots and visual artifacts, context-wide session.captureDiagnostics(), console/warning streams, debug logs, Vitest hooks, and renderer/browser/daemon crash distinctions. Use when a Biloba Vitest test fails, hangs, flakes, or needs CI/agent artifact configuration./flake-huntRun a flake hunt on a Biloba Vitest suite — run the whole browser suite many times (60 by default), every run to completion with its own JSON report, then read each test's failure rate, the seeds, and the failure evidence out of those reports instead of re-running. Covers the hunt script (vitest run with shuffle and a recorded seed, maxWorkers at the measured knee, no retry or bail, a per-run BILOBA_SCREENSHOTS_DIR, and the seed, wall clock, and exit status the JSON reporter doesn't record), the runs the JSON reports as clean when they aren't (unhandled errors, failed beforeAll hooks, killed runs), logging BilobaError's code and trajectory, what keeps a hunt a valid measurement (one hunt at a time on an idle machine, nothing editing the tree, focused hunts for iterating only, stale visual baselines), how many clean runs it takes to call a flake dead, reading the results (one systemic race behind many names, stalled tabs, a long tail that clusters by run), and the performance record a hunt produces (test timing, the longest file, per-test cost, drift between hunts). Use before declaring a flake fixed, after changing shared test helpers or fixtures, at the end of a batch of work, or to measure a suite's performance.Other plugins' skills for the same job