Test Results
SaveA test run with pass, fail, and skip counts over a proportional bar, collapsible suites, and failing tests that expand to their message and expected and received values.
- Category
- AI elements
- Version
- 0.1.0
- Frameworks
- Next.js, Vite + React
- Styling
- Tailwind CSS v4
Preview
Test Results preview
Test results
pnpm vitest run src/billing src/components
1.8 sFailed
- Passed
- 8
- Failed
- 1
- Skipped
- 1
- charges the remaining days of the month on upgrade, passed18 ms
- credits unused days on downgrade, passed11 ms
expected 1233 to be 1234
- Expected
- 1234
- Received
- 1233
src/billing/proration.test.ts:48:31
- handles leap years in annual plans, skipped
Installation
npx @shakenui/cli add test-resultsReview the plan first. A dry run lists every file and package without changing anything:
npx @shakenui/cli add test-results --dry-runUsage
test-results-example.tsx
import { TestResults, type TestSuite } from "@/components/shaken/agent/test-results";
const suites: TestSuite[] = [
{
name: "src/billing/proration.test.ts",
durationMs: 412,
tests: [
{ name: "charges the remaining days of the month on upgrade", status: "passed", durationMs: 18 },
{ name: "credits unused days on downgrade", status: "passed", durationMs: 11 },
{
name: "rounds partial cents toward the customer",
status: "failed",
durationMs: 9,
failure: {
message: "expected 1233 to be 1234",
expected: "1234",
actual: "1233",
location: "src/billing/proration.test.ts:48:31",
},
},
{ name: "handles leap years in annual plans", status: "skipped" },
],
},
{
name: "src/billing/invoice.test.ts",
durationMs: 266,
tests: [
{ name: "numbers invoices per workspace", status: "passed", durationMs: 7 },
{ name: "adds tax lines for EU customers", status: "passed", durationMs: 14 },
{ name: "voids a draft without sending email", status: "passed", durationMs: 22 },
],
},
{
name: "src/components/PlanPicker.test.tsx",
durationMs: 893,
tests: [
{ name: "shows the current plan as selected", status: "passed", durationMs: 61 },
{ name: "disables plans below current usage", status: "passed", durationMs: 48 },
{ name: "confirms before downgrading", status: "passed", durationMs: 104 },
],
},
];
export default function TestResultsExample() {
return <TestResults suites={suites} command="pnpm vitest run src/billing src/components" durationMs={1820} className="w-full max-w-xl" />;
}States
Every state, rendered from local fixture data.
Test Results states
Running
pnpm vitest run src/billing
Running tests
- Passed
- 3
- Failed
- 0
- Skipped
- 0
- Remaining
- 2
- charges the remaining days on upgrade, passed18 ms
- rounds partial cents toward the customer, running
- handles leap years in annual plans, queued
Passed
pnpm vitest run src/billing
1.1 sPassed
- Passed
- 4
- Failed
- 0
- Skipped
- 0
API
| Prop | Type | Default | Description |
|---|---|---|---|
| suites | { name, durationMs?, tests: { name, status, durationMs?, failure? }[] }[] | — | Suites and their tests. status is queued, running, passed, failed, or skipped; failure holds message, expected, actual, and location. |
| title | ReactNode | "Test results" | Heading. |
| command | string | — | The command that ran, shown under the title. |
| durationMs | number | — | Total time, shown once the run ends. |
| running | boolean | — | Marks the run in progress; derived from the tests when unset. |
Accessibility
- The summary bar is role img with a label such as 9 passed, 1 failed, 1 skipped, of 11 tests; the counts also appear as a labelled list below it.
- Each test pairs its status glyph with an sr-only status after its name; skipped tests are struck through.
- Suites and failing tests are Base UI Collapsible buttons operable with Enter and Space; suites with failures start open.
- The overall status is a live region (Running tests, Passed, or Failed). Disclosures animate in 220ms; instant with reduced motion.
Files
Installed into src/components/shaken, or components/shaken when the project has no src directory.
src/components/shaken/agent/test-results.tsxtest-results- Also installs agent-state@0.1.0registry dependency
- Also installs step-list@0.3.0registry dependency
- npm packages: @base-ui/react@^1.9.0React and Tailwind CSS v4 required
Source
The exact source the CLI installs, from /r/items/react/test-results/0.1.0.json.
agent/test-results.tsxShowHide
agent/test-results.tsx
"use client";
import { Collapsible } from "@base-ui/react/collapsible";
import type { ComponentProps, ReactNode } from "react";
import { AgentState } from "./agent-state";
import { StatusGlyph, type StatusGlyphKind } from "./step-list";
function cx(...classes: (string | false | null | undefined)[]) {
return classes.filter(Boolean).join(" ");
}
const ease = "ease-[cubic-bezier(0.23,1,0.32,1)]";
export type TestStatus = "queued" | "running" | "passed" | "failed" | "skipped";
export interface TestFailure {
/** The assertion message. */
message: string;
/** Expected value, shown on its own line. */
expected?: string;
/** Received value, shown on its own line. */
actual?: string;
/** Where the assertion failed, for example `src/cart.test.ts:42:18`. */
location?: string;
}
export interface TestCase {
name: string;
status: TestStatus;
durationMs?: number;
failure?: TestFailure;
}
export interface TestSuite {
/** Usually the test file path. */
name: string;
tests: TestCase[];
durationMs?: number;
}
export interface TestResultsProps extends Omit<ComponentProps<"section">, "children" | "title"> {
suites: TestSuite[];
/** Heading. Defaults to "Test results". */
title?: ReactNode;
/** The command that ran, shown under the title, e.g. `pnpm vitest run`. */
command?: string;
/** Total time, shown once the run ends. */
durationMs?: number;
/** Marks the run as in progress; derived from the tests when unset. */
running?: boolean;
}
const glyphFor: Record<TestStatus, StatusGlyphKind> = {
queued: "queued",
running: "running",
passed: "success",
failed: "failed",
skipped: "skipped",
};
function count(tests: TestCase[]) {
const totals = { passed: 0, failed: 0, skipped: 0, pending: 0 };
for (const test of tests) {
if (test.status === "passed") totals.passed++;
else if (test.status === "failed") totals.failed++;
else if (test.status === "skipped") totals.skipped++;
else totals.pending++;
}
return totals;
}
function suiteStatus(tests: TestCase[]): TestStatus {
const totals = count(tests);
if (tests.some((test) => test.status === "running")) return "running";
if (totals.failed) return "failed";
if (totals.pending) return "queued";
if (totals.passed) return "passed";
return "skipped";
}
/**
* A test run: pass, fail, and skip counts over a proportional bar, then one row per suite.
* Suites with failures start open, and each failing test expands to its message and the
* expected and received values.
*/
export function TestResults({ suites, title = "Test results", command, durationMs, running: runningProp, className, ...props }: TestResultsProps) {
const all = suites.flatMap((suite) => suite.tests);
const totals = count(all);
const running = runningProp ?? all.some((test) => test.status === "running" || test.status === "queued");
const total = all.length;
const summary = [
`${totals.passed} passed`,
totals.failed ? `${totals.failed} failed` : null,
totals.skipped ? `${totals.skipped} skipped` : null,
totals.pending ? `${totals.pending} remaining` : null,
]
.filter(Boolean)
.join(", ");
return (
<section
aria-label={typeof title === "string" ? title : "Test results"}
aria-busy={running || undefined}
className={cx(
"@container overflow-hidden rounded-xl border bg-white text-left text-zinc-950 shadow-[0_1px_2px_rgb(0_0_0/0.04)]",
"transition-[border-color] duration-200 motion-reduce:transition-none",
"dark:bg-black dark:text-white dark:shadow-[inset_0_1px_0_rgb(255_255_255/0.06)]",
!running && totals.failed ? "border-red-500/35" : "border-zinc-950/10 dark:border-white/10",
className,
)}
{...props}
>
<header className="p-4">
<div className="flex items-start justify-between gap-3">
<div className="min-w-0">
<h3 className="text-sm leading-6 font-semibold">{title}</h3>
{command ? <p className="truncate font-mono text-xs text-zinc-500">{command}</p> : null}
</div>
<div className="flex shrink-0 items-center gap-2.5">
{!running && durationMs != null ? (
<span className={`font-mono text-xs text-zinc-500 tabular-nums transition-opacity duration-300 ${ease} starting:opacity-0 motion-reduce:transition-none`}>
{formatDuration(durationMs)}
</span>
) : null}
{running ? (
<AgentState status size="sm" activity="working" label="Running tests" />
) : (
<span role="status" className="inline-flex h-6 items-center gap-1.5 text-xs">
<StatusGlyph key={totals.failed ? "failed" : "success"} kind={totals.failed ? "failed" : "success"} />
<span className={totals.failed ? "text-red-600 dark:text-red-400" : "text-zinc-600 dark:text-zinc-400"}>{totals.failed ? "Failed" : "Passed"}</span>
</span>
)}
</div>
</div>
<div
role="img"
aria-label={`${summary}, of ${total} tests`}
className="mt-3.5 flex h-1.5 gap-0.5 overflow-hidden rounded-full"
>
{total === 0 ? <span className="flex-1 bg-zinc-950/[0.06] dark:bg-white/[0.08]" /> : null}
<Segment value={totals.passed} className="bg-emerald-500" />
<Segment value={totals.failed} className="bg-red-500" />
<Segment value={totals.skipped} className="bg-zinc-950/20 dark:bg-white/25" />
<Segment value={totals.pending} className="bg-zinc-950/[0.06] dark:bg-white/[0.08]" />
</div>
<dl className="mt-2.5 flex flex-wrap gap-x-4 gap-y-1 text-xs">
<Total label="Passed" value={totals.passed} kind="success" />
<Total label="Failed" value={totals.failed} kind="failed" />
<Total label="Skipped" value={totals.skipped} kind="skipped" />
{totals.pending ? <Total label="Remaining" value={totals.pending} kind="queued" /> : null}
</dl>
</header>
<ul className="border-t border-zinc-950/[0.07] dark:border-white/[0.08]">
{suites.map((suite) => (
<SuiteRow key={suite.name} suite={suite} />
))}
</ul>
</section>
);
}
function Segment({ value, className }: { value: number; className: string }) {
if (!value) return null;
return <span className={cx("h-full min-w-1.5 first:rounded-l-full last:rounded-r-full", className)} style={{ flexGrow: value, flexBasis: 0 }} />;
}
function Total({ label, value, kind }: { label: string; value: number; kind: StatusGlyphKind }) {
return (
<div className="flex items-center gap-1.5">
<StatusGlyph kind={kind} className={value ? "" : "opacity-40"} />
<dt className="text-zinc-600 dark:text-zinc-400">{label}</dt>
<dd className={cx("font-mono tabular-nums", value ? "text-zinc-950 dark:text-white" : "text-zinc-500")}>{value}</dd>
</div>
);
}
const panel = cx(
"h-(--collapsible-panel-height) overflow-hidden",
`transition-[height,opacity] duration-220 ${ease} motion-reduce:transition-none`,
"data-starting-style:h-0 data-starting-style:opacity-0",
"data-ending-style:h-0 data-ending-style:opacity-0 data-ending-style:duration-180",
);
const chevron = `size-4 shrink-0 text-zinc-500 transition-transform duration-200 ${ease} group-data-panel-open:rotate-90 motion-reduce:transition-none`;
function SuiteRow({ suite }: { suite: TestSuite }) {
const totals = count(suite.tests);
const status = suiteStatus(suite.tests);
return (
<li className="border-b border-zinc-950/[0.07] last:border-b-0 dark:border-white/[0.08]">
<Collapsible.Root defaultOpen={totals.failed > 0 || status === "running"}>
<Collapsible.Trigger
className={cx(
"group flex w-full cursor-pointer items-center gap-2.5 py-2.5 pr-4 pl-3 text-left select-none",
"transition-colors duration-150 hover:bg-zinc-950/[0.03] motion-reduce:transition-none dark:hover:bg-white/[0.04]",
"focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-sky-500",
)}
>
<svg aria-hidden="true" viewBox="0 0 16 16" className={chevron}>
<path d="m6.25 4.5 3.5 3.5-3.5 3.5" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
</svg>
<StatusGlyph key={status} kind={glyphFor[status]} />
<span className="min-w-0 flex-1 truncate font-mono text-[13px] text-zinc-950 dark:text-white">{suite.name}</span>
<span className="shrink-0 font-mono text-xs text-zinc-500 tabular-nums">
{/* In a narrow container the glyph carries the failure and the duration drops, so the file name keeps its room. */}
{totals.failed ? <span className="text-red-600 @max-md:hidden dark:text-red-400">{totals.failed} failed, </span> : null}
{totals.passed}/{suite.tests.length}
{suite.durationMs != null ? <span className="ml-2.5 @max-md:hidden">{formatDuration(suite.durationMs)}</span> : null}
</span>
</Collapsible.Trigger>
<Collapsible.Panel className={panel}>
<ul className="pb-2">
{suite.tests.map((test) => (
<TestRow key={test.name} test={test} />
))}
</ul>
</Collapsible.Panel>
</Collapsible.Root>
</li>
);
}
const statusText: Record<TestStatus, string> = {
queued: "queued",
running: "running",
passed: "passed",
failed: "failed",
skipped: "skipped",
};
function TestRow({ test }: { test: TestCase }) {
const label = (
<>
<StatusGlyph key={test.status} kind={glyphFor[test.status]} />
<span
className={cx(
"min-w-0 flex-1 text-[13px] leading-5",
test.status === "skipped" ? "text-zinc-500 line-through decoration-zinc-500/60" : test.status === "queued" ? "text-zinc-500" : "text-zinc-800 dark:text-zinc-200",
)}
>
{test.name}
<span className="sr-only">, {statusText[test.status]}</span>
</span>
{test.durationMs != null && test.status !== "queued" && test.status !== "running" ? (
<span className="shrink-0 font-mono text-[11px] text-zinc-500 tabular-nums">{formatDuration(test.durationMs)}</span>
) : null}
</>
);
if (test.status !== "failed" || !test.failure) {
return <li className="flex items-start gap-2.5 py-1 pr-4 pl-16 [&>svg]:mt-0.5">{label}</li>;
}
const failure = test.failure;
return (
<li>
<Collapsible.Root defaultOpen>
<Collapsible.Trigger
className={cx(
"group flex w-full cursor-pointer items-start gap-2.5 py-1 pr-4 pl-[38px] text-left [&>svg]:mt-0.5",
"transition-colors duration-150 hover:bg-zinc-950/[0.03] motion-reduce:transition-none dark:hover:bg-white/[0.04]",
"focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-sky-500",
)}
>
<svg aria-hidden="true" viewBox="0 0 16 16" className={chevron}>
<path d="m6.25 4.5 3.5 3.5-3.5 3.5" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
</svg>
{label}
</Collapsible.Trigger>
<Collapsible.Panel className={panel}>
<div className="pt-1 pr-4 pb-2 pl-16">
<div className="rounded-lg border border-red-500/35 bg-red-500/[0.08] px-3 py-2.5 font-mono text-xs leading-relaxed break-words">
<p className="text-red-700 dark:text-red-300">{failure.message}</p>
{failure.expected != null || failure.actual != null ? (
<dl className="mt-2 grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-0.5">
{failure.expected != null ? (
<>
<dt className="text-zinc-500">Expected</dt>
<dd className="text-emerald-700 dark:text-emerald-400">{failure.expected}</dd>
</>
) : null}
{failure.actual != null ? (
<>
<dt className="text-zinc-500">Received</dt>
<dd className="text-red-700 dark:text-red-300">{failure.actual}</dd>
</>
) : null}
</dl>
) : null}
{failure.location ? <p className="mt-2 text-zinc-500">{failure.location}</p> : null}
</div>
</div>
</Collapsible.Panel>
</Collapsible.Root>
</li>
);
}
function formatDuration(ms: number): string {
return ms < 1000 ? `${Math.round(ms)} ms` : `${(ms / 1000).toFixed(1)} s`;
}