Code Examples

Custom reporting

Each finding is a plain object you can filter, count, upload as a build artifact, or pipe into your own formatter.

2 min read

runAccessibilityAudit returns AccessKitAuditFinding[]. Use it directly for assertions, or pass the array through formatAuditFindingsForConsole for a consistent console or log file layout.

AccessKitAuditFinding

AccessKitAuditFinding properties
FieldDescription
idStable string for this row (violation + node).
ruleIdWCAG-style id when available, else axe rule id.
wcagLevel"A", "AA", "AAA", or omitted for non-WCAG rules.
categoryTopic (e.g. color, forms) when present.
severity"error" or "warning".
messageShort rule description.
suggestionHow to fix, combined from failure summary + description.
helpUrlOptional link to Deque / rule docs.
selectorCSS selector or snippet of the element that failed
standardsAdditional standards the rule belongs to (e.g. ["TTv5", "RGAAv4"]). Undefined when the rule only maps to WCAG

Filtering

Build your own pass/fail rules on top of the array; for example only Level A and AA errors:

ts
import type { AccessKitAuditFinding } from "@access-kit/react"

function blockingForAa(findings: AccessKitAuditFinding[]) {
  return findings.filter(
    (f) =>
      f.severity === "error" &&
      (f.wcagLevel === "A" || f.wcagLevel === "AA"),
  )
}

Built-in console format

The CI audit script and DevTools use the same formatter for readable logs:

ts
import { formatAuditFindingsForConsole } from "@access-kit/react"

// Logs the same human-readable layout as DevTools / CI script
const text = formatAuditFindingsForConsole(findings)
console.log(text)

CI artifacts

Write JSON for later triage or dashboards. The Auditing in CI doc explains appending markdown to GITHUB_STEP_SUMMARY when AUDIT_SUMMARY_PATH is set.

ts
import { writeFileSync } from "fs"
import type { AccessKitAuditFinding } from "@access-kit/react"

export function writeFindingsJson(path: string, findings: AccessKitAuditFinding[]) {
  writeFileSync(path, JSON.stringify(findings, null, 2), "utf-8")
}

Tag-based blocking in CI

The reference audit script treats AUDIT_TAGS as the set of tags that produce a blocking error. WCAG levels A, AA, AAA match wcagLevel; cat.* tags match category; other tags (e.g. best-practice) are passed to axe as extra rules and non-WCAG findings from those rules block when those tags are listed. Adjust tags to match your team’s policy.

See also