# Test Results

> Show a test run with pass, fail, and skip counts, suites that open to their tests, and the error for each failure.

Source: https://www.honestui.com/docs/ai/test-results

```tsx
"use client"

import * as React from "react"

import { TestResults, type TestSuite } from "@/components/ai/test-results"

// Sample results.
const sampleSuites: TestSuite[] = [
  {
    id: "invoice",
    name: "Invoice totals",
    file: "src/billing/invoice.test.ts",
    tests: [
      { id: "invoice-sum", name: "sums line items", status: "passed", duration: 4 },
      {
        id: "invoice-round",
        name: "rounds the total once, after tax",
        status: "failed",
        duration: 11,
        error: {
          message: "expect(received).toBe(expected)",
          expected: "1284.37",
          received: "1284.38",
          stack: "at Object.<anonymous> (src/billing/invoice.test.ts:42:31)",
        },
      },
      { id: "invoice-discount", name: "applies a percentage discount", status: "passed", duration: 3 },
      { id: "invoice-credit", name: "carries a credit note forward", status: "skipped" },
    ],
  },
  {
    id: "currency",
    name: "Currency formatting",
    file: "src/billing/currency.test.ts",
    tests: [
      { id: "currency-usd", name: "formats USD with two decimals", status: "passed", duration: 2 },
      { id: "currency-jpy", name: "formats JPY without decimals", status: "passed", duration: 2 },
      { id: "currency-negative", name: "puts the sign before the symbol", status: "passed", duration: 1 },
    ],
  },
  {
    id: "export",
    name: "CSV export",
    file: "src/billing/export.test.ts",
    tests: [
      { id: "export-header", name: "writes the header row", status: "passed", duration: 6 },
      { id: "export-escape", name: "quotes fields with commas", status: "passed", duration: 5 },
      { id: "export-large", name: "streams 50,000 rows", status: "passed", duration: 812 },
    ],
  },
]

/**
 * No runner is attached. Rerun failed waits a moment, then reports the
 * rounding test as fixed, as your runner would after the change lands.
 */
export function TestResultsDemo() {
  const [suites, setSuites] = React.useState(sampleSuites)
  const [running, setRunning] = React.useState(false)
  const timer = React.useRef<number | undefined>(undefined)
  React.useEffect(() => () => window.clearTimeout(timer.current), [])

  return (
    <div className="w-full max-w-lg min-w-0">
      <TestResults
        title="vitest run src/billing"
        suites={suites}
        duration={1240}
        running={running}
        onRerunFailed={(ids) => {
          setRunning(true)
          setSuites((current) =>
            current.map((suite) => ({
              ...suite,
              tests: suite.tests.map((test) => (ids.includes(test.id) ? { ...test, status: "running" } : test)),
            }))
          )
          timer.current = window.setTimeout(() => {
            setRunning(false)
            setSuites((current) =>
              current.map((suite) => ({
                ...suite,
                tests: suite.tests.map((test) =>
                  ids.includes(test.id) ? { ...test, status: "passed", duration: 9, error: undefined } : test
                ),
              }))
            )
          }, 1400)
        }}
      />
    </div>
  )
}

```

## Overview [#overview]

Test Results shows what a test run found: how many tests passed, failed, and were skipped, how long it took, and each suite with its tests. A failed test shows its assertion message, the expected and received values, and a few lines of stack.

It shows the results you pass. Map your runner's report into suites and tests, and update them as the run progresses.

Use it when an agent runs your test suite and the person needs to see what broke. For a single command's raw output, use [Tool Chips](/docs/ai/tool-chips).

## Anatomy [#anatomy]

<Anatomy title="TestResults">
  <AnatomyItem name="Summary" description="The run's title, its counts in words, the duration, and a slim bar of the proportions" />

  <AnatomyItem name="Rerun failed" description="A button in the summary, when you handle it and a test has failed" />

  <AnatomyItem name="Suite" description="A row with the suite's name, file, and counts, which opens to its tests" />

  <AnatomyItem name="Test" description="A line with its status icon, name, and duration" />

  <AnatomyItem name="Error" description="Under a failed test: the message, expected and received values, and stack" />
</Anatomy>

Installing `test-results` brings [Button](/docs/components/button) and [Collapsible](/docs/components/collapsible) along as registry dependencies.

## Behavior [#behavior]

### Counts and bar [#counts-and-bar]

The counts are written out, such as "1 failed · 9 passed · 1 skipped · 1.24 s", and the bar beneath them shows the same proportions. Passing tests are drawn in a quiet neutral, so only failures carry color.

Pass `duration` for the run's wall time. Without it, the component adds up the durations of the tests.

### Suites [#suites]

A suite with a failure opens on its own, including when a test fails after the first render. Other suites stay closed until the person opens them. Set `defaultExpanded` to `"all"` to start with every suite open, or `"none"` to keep them all closed.

### Rerun failed [#rerun-failed]

Pass `onRerunFailed` to show Rerun failed whenever a test has failed. It is called with the ids of the failed tests. Set `running` while your runner works: the button shows Rerunning and is disabled. Updating the tests' statuses is your application's work.

### Statuses [#statuses]

A test is `passed`, `failed`, `skipped`, `running`, or `queued`, so the same component shows a run in progress.

## Accessibility [#accessibility]

The results are a labelled region. Each suite is a button that reports whether it is open. Every test's status is in words for screen readers as well as an icon, and the counts line is a polite live region, so a finished rerun is announced. The proportion bar is decorative, since the counts carry the numbers. With reduced motion, running icons do not rotate.

| Key                                  | Action                                    |
| ------------------------------------ | ----------------------------------------- |
| <kbd>Tab</kbd>                       | Move to Rerun failed and across suites    |
| <kbd>Enter</kbd> or <kbd>Space</kbd> | Open or close the focused suite, or rerun |

## Installation [#installation]


  

  
    <CliBlock commands="[&#x22;@honestai/test-results&#x22;]" />
  

  
    
      
        Add the components it is built from.
      

      <CliBlock commands="[&#x22;button&#x22;, &#x22;collapsible&#x22;]" />

      
        Copy and paste this file into your project.
      

      ### components/ai/test-results.tsx

```tsx
"use client"

import * as React from "react"
import {
  ChevronDown as ChevronDownIcon,
  CircleAlert as CircleAlertIcon,
  CircleCheck as CircleCheckIcon,
  CircleDashed as CircleDashedIcon,
  CircleMinus as CircleMinusIcon,
  LoaderCircle as LoaderCircleIcon,
  RotateCcw as RotateCcwIcon,
} from "honestui/icons"

import { cn } from "@/lib/utils"
import { Button } from "@/components/honest-ui/ui/button"
import {
  Collapsible,
  CollapsiblePanel,
  CollapsibleTrigger,
} from "@/components/honest-ui/ui/collapsible"

export type TestStatus = "passed" | "failed" | "skipped" | "running" | "queued"

export type TestError = {
  /** The assertion message, such as "expected 3 to equal 4". */
  message: string
  /** Optional expected and received values, shown as a two-line diff. */
  expected?: string
  received?: string
  /** A few lines of stack or source, shown as they are. */
  stack?: string
}

export type TestCase = {
  id: string
  name: string
  status: TestStatus
  /** Milliseconds. */
  duration?: number
  error?: TestError
}

export type TestSuite = {
  id: string
  name: string
  /** The file the suite lives in, shown after the name. */
  file?: string
  tests: TestCase[]
}

export type TestResultsLabels = {
  title: string
  passed: string
  failed: string
  skipped: string
  running: string
  queued: string
  rerunFailed: string
  rerunning: string
  expected: string
  received: string
  noTests: string
  /** How a duration in milliseconds reads. */
  formatDuration: (ms: number) => string
}

export const defaultTestResultsLabels: TestResultsLabels = {
  title: "Test results",
  passed: "passed",
  failed: "failed",
  skipped: "skipped",
  running: "running",
  queued: "queued",
  rerunFailed: "Rerun failed",
  rerunning: "Rerunning",
  expected: "Expected",
  received: "Received",
  noTests: "No tests were collected.",
  formatDuration: (ms) =>
    ms < 1000 ? `${Math.round(ms)} ms` : `${(ms / 1000).toFixed(ms < 10_000 ? 2 : 1)} s`,
}

const rowText =
  "[font-size:var(--hui-font-size-regular)] [letter-spacing:var(--hui-letter-spacing-regular)] [line-height:var(--hui-line-height-regular)]"
const metaText =
  "[font-size:var(--hui-font-size-small)] [letter-spacing:var(--hui-letter-spacing-small)] [line-height:var(--hui-line-height-small)]"
const monoText =
  "font-mono [font-variant-ligatures:none] [font-size:var(--hui-font-size-mono-small)] [letter-spacing:var(--hui-letter-spacing-mono-small)] [line-height:var(--hui-line-height-mono-regular)]"

const statusIcon: Record<TestStatus, { Icon: typeof CircleCheckIcon; className: string }> = {
  // Passing is quiet; color is kept for the tests that need attention.
  passed: { Icon: CircleCheckIcon, className: "text-[var(--hui-color-foreground-base-secondary)]" },
  failed: { Icon: CircleAlertIcon, className: "text-[var(--hui-color-foreground-danger-primary)]" },
  skipped: { Icon: CircleMinusIcon, className: "text-[var(--hui-color-foreground-base-tertiary)]" },
  running: {
    Icon: LoaderCircleIcon,
    className: "text-[var(--hui-color-foreground-base-secondary)] motion-safe:animate-spin",
  },
  queued: { Icon: CircleDashedIcon, className: "text-[var(--hui-color-foreground-base-tertiary)]" },
}

type Counts = Record<TestStatus, number>

function countTests(tests: TestCase[]): Counts {
  const counts: Counts = { passed: 0, failed: 0, skipped: 0, running: 0, queued: 0 }
  for (const test of tests) counts[test.status] += 1
  return counts
}

function sumDuration(tests: TestCase[]) {
  return tests.reduce((total, test) => total + (test.duration ?? 0), 0)
}

function countsText(counts: Counts, labels: TestResultsLabels) {
  const order: TestStatus[] = ["failed", "passed", "skipped", "running", "queued"]
  return order
    .filter((status) => counts[status] > 0)
    .map((status) => `${counts[status]} ${labels[status]}`)
}

export type TestResultsProps = Omit<React.ComponentProps<"section">, "children" | "title"> & {
  suites: TestSuite[]
  /** A heading for the run, such as the command or the package name. */
  title?: React.ReactNode
  /** Total wall time in milliseconds. Defaults to the sum of the tests. */
  duration?: number
  /** True while a rerun is in progress. Disables Rerun failed. */
  running?: boolean
  /** Passing it shows Rerun failed whenever a test has failed. */
  onRerunFailed?: (failedTestIds: string[]) => void
  /** Which suites start open. "failed" opens a suite when one of its tests fails. */
  defaultExpanded?: "failed" | "all" | "none"
  labels?: Partial<TestResultsLabels>
}

/**
 * A test run: a summary of passed, failed, and skipped tests, then each suite
 * with its tests. It shows the results you pass; update them as your runner
 * reports.
 */
function TestResults({
  suites,
  title,
  duration,
  running = false,
  onRerunFailed,
  defaultExpanded = "failed",
  labels: labelsProp,
  className,
  ...props
}: TestResultsProps) {
  const labels = React.useMemo(
    () => ({ ...defaultTestResultsLabels, ...labelsProp }),
    [labelsProp]
  )
  const titleId = React.useId()
  const allTests = React.useMemo(() => suites.flatMap((suite) => suite.tests), [suites])
  const counts = countTests(allTests)
  const total = allTests.length
  const failedIds = allTests.filter((test) => test.status === "failed").map((test) => test.id)
  const totalDuration = duration ?? sumDuration(allTests)
  const showRerun = onRerunFailed !== undefined && (failedIds.length > 0 || running)

  const segments: { status: TestStatus; className: string }[] = [
    { status: "passed", className: "bg-[var(--hui-color-foreground-base-secondary)]" },
    { status: "failed", className: "bg-[var(--hui-color-foreground-danger-primary)]" },
    { status: "skipped", className: "bg-[var(--hui-color-border-base-primary)]" },
    { status: "running", className: "bg-[var(--hui-color-border-base-secondary)]" },
    { status: "queued", className: "bg-[var(--hui-color-border-base-secondary)]" },
  ]

  return (
    <section
      aria-labelledby={titleId}
      data-slot="test-results"
      data-running={running || undefined}
      className={cn(
        "flex w-full min-w-0 flex-col overflow-hidden rounded-[var(--hui-radius-4)] border-[0.5px] border-[var(--hui-color-border-base-primary)] bg-[var(--hui-color-background-base-primary)] text-[var(--hui-color-foreground-base-primary)] shadow-[var(--hui-shadow-feather)]",
        rowText,
        className
      )}
      {...props}
    >
      <header
        data-slot="test-results-summary"
        className="flex min-w-0 flex-col gap-[var(--hui-space-4)] border-b-[0.5px] border-[var(--hui-color-border-base-primary)] px-[var(--hui-space-5)] py-[var(--hui-space-5)]"
      >
        <div className="flex min-w-0 items-center gap-[var(--hui-space-4)]">
          <div className="min-w-0 flex-1">
            <p
              id={titleId}
              className={cn("m-0 truncate [font-weight:var(--hui-font-weight-medium)]", rowText)}
            >
              {title ?? labels.title}
            </p>
            {/* Polite, so a finished rerun is heard without moving focus. */}
            <p
              aria-live="polite"
              data-slot="test-results-counts"
              className={cn("m-0 truncate text-[var(--hui-color-foreground-base-secondary)] tabular-nums", metaText)}
            >
              {total === 0
                ? labels.noTests
                : [...countsText(counts, labels), labels.formatDuration(totalDuration)].join(" · ")}
            </p>
          </div>
          {showRerun && (
            <Button
              variant="secondary"
              size="xs"
              disabled={running}
              data-slot="test-results-rerun"
              onClick={() => onRerunFailed?.(failedIds)}
              className="shrink-0"
            >
              {running ? (
                <LoaderCircleIcon aria-hidden="true" className="motion-safe:animate-spin" />
              ) : (
                <RotateCcwIcon aria-hidden="true" />
              )}
              {running ? labels.rerunning : labels.rerunFailed}
            </Button>
          )}
        </div>
        {total > 0 && (
          // The words above carry the numbers; the bar is their shape.
          <div
            aria-hidden="true"
            data-slot="test-results-bar"
            className="flex h-1 w-full gap-px overflow-hidden rounded-full bg-[var(--hui-color-border-base-secondary)]"
          >
            {segments
              .filter((segment) => counts[segment.status] > 0)
              .map((segment) => (
                <span
                  key={segment.status}
                  data-status={segment.status}
                  className={cn("h-full motion-safe:[transition:flex-grow_var(--hui-duration-normal)_var(--hui-ease-out)]", segment.className)}
                  style={{ flexGrow: counts[segment.status], flexBasis: 0 }}
                />
              ))}
          </div>
        )}
      </header>

      <ul role="list" className="m-0 flex list-none flex-col p-0">
        {suites.map((suite) => (
          <SuiteRow key={suite.id} suite={suite} labels={labels} expand={defaultExpanded} />
        ))}
      </ul>
    </section>
  )
}

function SuiteRow({
  suite,
  labels,
  expand,
}: {
  suite: TestSuite
  labels: TestResultsLabels
  expand: "failed" | "all" | "none"
}) {
  const counts = countTests(suite.tests)
  const suiteStatus: TestStatus =
    counts.failed > 0
      ? "failed"
      : counts.running > 0
        ? "running"
        : counts.queued > 0
          ? "queued"
          : counts.passed > 0
            ? "passed"
            : "skipped"
  const { Icon, className: iconClassName } = statusIcon[suiteStatus]
  // Failures open on their own; a passing suite waits to be asked.
  const opensOnFailure = expand === "failed"
  const [open, setOpen] = React.useState(expand === "all" || (opensOnFailure && counts.failed > 0))
  const hadFailure = React.useRef(counts.failed > 0)
  React.useEffect(() => {
    if (opensOnFailure && counts.failed > 0 && !hadFailure.current) setOpen(true)
    hadFailure.current = counts.failed > 0
  }, [counts.failed, opensOnFailure])

  return (
    <li
      data-slot="test-suite"
      data-status={suiteStatus}
      className="min-w-0 border-b-[0.5px] border-[var(--hui-color-border-base-primary)] last:border-b-0"
    >
      <Collapsible open={open} onOpenChange={setOpen}>
        <CollapsibleTrigger
          className={cn(
            "group/suite flex min-h-[var(--hui-space-11)] w-full min-w-0 items-center gap-[var(--hui-space-4)] rounded-none border-0 bg-transparent px-[var(--hui-space-5)] py-[var(--hui-space-3)] text-left text-[var(--hui-color-foreground-base-primary)] outline-none motion-safe:[transition:var(--hui-transition-interactive)] hover:bg-[var(--hui-color-background-base-primary-hover)] focus-visible:outline-offset-[var(--hui-focus-ring-offset-inset)]",
            rowText
          )}
        >
          <Icon strokeWidth={1.5} aria-hidden="true" className={cn("size-4 shrink-0", iconClassName)} />
          <span className="flex min-w-0 flex-1 items-baseline gap-[var(--hui-space-3)]">
            {/* The name keeps its width; the file path gives way first. */}
            <span className="max-w-full shrink-0 truncate [font-weight:var(--hui-font-weight-medium)]" title={suite.name}>
              {suite.name}
            </span>
            {suite.file && (
              <span
                className={cn(
                  "hidden min-w-0 truncate text-[var(--hui-color-foreground-base-secondary)] sm:inline",
                  monoText
                )}
              >
                {suite.file}
              </span>
            )}
          </span>
          <span className={cn("shrink-0 text-[var(--hui-color-foreground-base-secondary)] tabular-nums", metaText)}>
            {countsText(counts, labels).join(" · ")}
          </span>
          <ChevronDownIcon
            aria-hidden="true"
            className="size-3.5 shrink-0 text-[var(--hui-color-foreground-base-tertiary)] motion-safe:transition-transform motion-safe:duration-200 group-data-panel-open/suite:rotate-180"
          />
        </CollapsibleTrigger>
        <CollapsiblePanel>
          <ul
            role="list"
            className="m-0 flex list-none flex-col p-0 pb-[var(--hui-space-3)]"
          >
            {suite.tests.map((test) => (
              <TestRow key={test.id} test={test} labels={labels} />
            ))}
          </ul>
        </CollapsiblePanel>
      </Collapsible>
    </li>
  )
}

function TestRow({ test, labels }: { test: TestCase; labels: TestResultsLabels }) {
  const { Icon, className: iconClassName } = statusIcon[test.status]

  return (
    <li data-slot="test-case" data-status={test.status} className="min-w-0">
      <div className="flex min-w-0 items-center gap-[var(--hui-space-4)] py-[var(--hui-space-2)] ps-[calc(var(--hui-space-5)+var(--hui-space-6))] pe-[calc(var(--hui-space-5)+14px+var(--hui-space-4))]">
        <Icon strokeWidth={1.5} aria-hidden="true" className={cn("size-3.5 shrink-0", iconClassName)} />
        <span
          title={test.name}
          className={cn(
            "min-w-0 flex-1 truncate",
            test.status === "skipped"
              ? "text-[var(--hui-color-foreground-base-secondary)]"
              : "text-[var(--hui-color-foreground-base-primary)]"
          )}
        >
          {test.name}
        </span>
        {/* Status in words for readers that skip the icon. */}
        <span className="sr-only">{labels[test.status]}</span>
        {test.duration !== undefined && (
          <span className={cn("shrink-0 text-[var(--hui-color-foreground-base-secondary)] tabular-nums", metaText)}>
            {labels.formatDuration(test.duration)}
          </span>
        )}
      </div>
      {test.status === "failed" && test.error && <ErrorBlock error={test.error} labels={labels} />}
    </li>
  )
}

function ErrorBlock({ error, labels }: { error: TestError; labels: TestResultsLabels }) {
  const hasDiff = error.expected !== undefined || error.received !== undefined

  return (
    <div
      data-slot="test-error"
      className={cn(
        "ms-[calc(var(--hui-space-5)+var(--hui-space-6)+14px+var(--hui-space-4))] me-[var(--hui-space-5)] mt-[var(--hui-space-1)] mb-[var(--hui-space-3)] overflow-hidden rounded-[var(--hui-radius-2)] border-[0.5px] border-[var(--hui-color-border-base-primary)] bg-[var(--hui-color-background-base-secondary)]",
        monoText
      )}
    >
      <p className="m-0 px-[var(--hui-space-4)] py-[var(--hui-space-3)] break-words whitespace-pre-wrap text-[var(--hui-color-foreground-danger-primary)]">
        {error.message}
      </p>
      {hasDiff && (
        <dl className="m-0 border-t-[0.5px] border-[var(--hui-color-border-base-primary)] py-[var(--hui-space-2)]">
          {error.expected !== undefined && (
            <DiffLine sign="-" term={labels.expected} value={error.expected} kind="expected" />
          )}
          {error.received !== undefined && (
            <DiffLine sign="+" term={labels.received} value={error.received} kind="received" />
          )}
        </dl>
      )}
      {error.stack && (
        <pre className="m-0 overflow-x-auto border-t-[0.5px] border-[var(--hui-color-border-base-primary)] px-[var(--hui-space-4)] py-[var(--hui-space-3)] text-[var(--hui-color-foreground-base-secondary)]">
          {error.stack}
        </pre>
      )}
    </div>
  )
}

function DiffLine({
  sign,
  term,
  value,
  kind,
}: {
  sign: string
  term: string
  value: string
  kind: "expected" | "received"
}) {
  return (
    <div
      className={cn(
        "flex min-w-0 gap-[var(--hui-space-3)] px-[var(--hui-space-4)] text-[var(--hui-color-foreground-base-primary)]",
        kind === "expected"
          ? "bg-[color-mix(in_oklch,var(--hui-color-background-success-primary)_50%,transparent)]"
          : "bg-[color-mix(in_oklch,var(--hui-color-background-danger-primary)_50%,transparent)]"
      )}
    >
      <span aria-hidden="true" className="w-2 shrink-0 select-none text-[var(--hui-color-foreground-base-secondary)]">
        {sign}
      </span>
      <dt className="shrink-0 text-[var(--hui-color-foreground-base-secondary)]">{term}</dt>
      <dd className="m-0 min-w-0 break-all whitespace-pre-wrap">{value}</dd>
    </div>
  )
}

export { TestResults }

```

      
        Update the import paths to match your project setup.
      
    
  


## Usage [#usage]

```tsx
import { TestResults } from "@/components/ai/test-results"

<TestResults
  title="vitest run"
  duration={report.duration}
  running={rerun.isPending}
  suites={report.files.map((file) => ({
    id: file.path,
    name: file.name,
    file: file.path,
    tests: file.tests.map((test) => ({
      id: test.id,
      name: test.name,
      status: test.state,
      duration: test.duration,
      error: test.error && { message: test.error.message, expected: test.error.expected, received: test.error.actual },
    })),
  }))}
  onRerunFailed={(ids) => rerun.mutate(ids)}
/>
```

## Examples [#examples]

### Run in progress [#run-in-progress]

Tests move from queued to running to their result. The counts and bar follow.

```tsx
"use client"

import * as React from "react"
import { RotateCcw as RotateCcwIcon } from "honestui/icons"

import { Button } from "@/components/honest-ui/ui/button"
import { TestResults, type TestStatus, type TestSuite } from "@/components/ai/test-results"

// Sample plan: each test's final status and duration.
const plan: { suite: string; name: string; file: string; tests: [string, TestStatus, number][] }[] = [
  {
    suite: "auth",
    name: "Session tokens",
    file: "src/auth/session.test.ts",
    tests: [
      ["issues a token on sign-in", "passed", 14],
      ["refreshes before expiry", "passed", 22],
      ["rejects a revoked token", "passed", 9],
    ],
  },
  {
    suite: "rate",
    name: "Rate limiter",
    file: "src/auth/rate-limit.test.ts",
    tests: [
      ["allows 10 requests a minute", "passed", 31],
      ["resets the window", "passed", 18],
      ["shares limits across regions", "skipped", 0],
    ],
  },
]

function buildSuites(step: number): TestSuite[] {
  let index = 0
  return plan.map((suite) => ({
    id: suite.suite,
    name: suite.name,
    file: suite.file,
    tests: suite.tests.map(([name, status, duration]) => {
      const position = index++
      const done = position < step
      return {
        id: `${suite.suite}-${position}`,
        name,
        status: done ? status : position === step ? "running" : "queued",
        duration: done && status !== "skipped" ? duration : undefined,
      }
    }),
  }))
}

const total = plan.reduce((sum, suite) => sum + suite.tests.length, 0)

/** A run in progress. Nothing executes; a timer moves through the sample plan. */
export function TestResultsLive() {
  const [step, setStep] = React.useState(0)
  const [run, setRun] = React.useState(0)

  React.useEffect(() => {
    if (step >= total) return
    const timer = window.setTimeout(() => setStep((current) => current + 1), 650)
    return () => window.clearTimeout(timer)
  }, [step, run])

  return (
    <div className="flex w-full max-w-lg min-w-0 flex-col gap-[var(--hui-space-4)]">
      <TestResults title="vitest run src/auth" suites={buildSuites(step)} defaultExpanded="all" />
      <div>
        <Button
          variant="ghost"
          size="sm"
          disabled={step < total}
          onClick={() => {
            setStep(0)
            setRun((current) => current + 1)
          }}
        >
          <RotateCcwIcon aria-hidden="true" />
          Replay
        </Button>
      </div>
    </div>
  )
}

```

## API reference [#api-reference]

### TestResults [#testresults]

Accepts native section props beyond those listed.

| Prop              | Type                                | Default          | Description                                                  |
| ----------------- | ----------------------------------- | ---------------- | ------------------------------------------------------------ |
| `suites`          | `TestSuite[]`                       | Required         | The suites, in order.                                        |
| `title`           | `ReactNode`                         | `"Test results"` | A heading for the run, such as the command.                  |
| `duration`        | `number`                            | Sum of the tests | The run's wall time in milliseconds.                         |
| `running`         | `boolean`                           | `false`          | True while a rerun is in progress.                           |
| `onRerunFailed`   | `(failedTestIds: string[]) => void` | None             | Passing it shows Rerun failed when a test has failed.        |
| `defaultExpanded` | `"failed" \| "all" \| "none"`       | `"failed"`       | Which suites start open.                                     |
| `labels`          | `Partial<TestResultsLabels>`        | English          | Status words, button text, diff terms, and `formatDuration`. |

### Types [#types]

| Export       | Shape                                                            |
| ------------ | ---------------------------------------------------------------- |
| `TestSuite`  | `id`, `name`, `tests`, and an optional `file`                    |
| `TestCase`   | `id`, `name`, `status`, and optional `duration` (ms) and `error` |
| `TestError`  | `message`, and optional `expected`, `received`, `stack`          |
| `TestStatus` | `"passed"`, `"failed"`, `"skipped"`, `"running"`, or `"queued"`  |
