Skip to content

huh test launches a Playwright browser against your ErrorConfig JSON, captures screenshots of each error entry's UI, runs extended validation, and auto-generates an HTML report.

Prerequisites

Playwright must be installed.

bash

TIP

huh test uses headless Chromium internally. In CI environments, make sure the Playwright browser binaries are installed.


Basic Usage

bash
# Default run (standalone mode, desktop, src/huh.json)
npx huh test

# Capture with mobile viewport
npx huh test --device mobile

# Test specific trackIds only
npx huh test --filter ERR_AUTH,ERR_NOT_FOUND

# Open report in browser
npx huh test --open

# Compare with previous report (diff)
npx huh test --diff

# CI mode (exit code 1 on failures)
npx huh test --ci

CLI Options

OptionTypeDefaultDescription
--mode <mode>standalone | appstandalonePreview mode
--url <url>stringApp URL (required for app mode)
--config <path>stringsrc/huh.jsonPath to ErrorConfig JSON file
--output <dir>string.huh-reportReport output directory
--filter <ids>stringFilter by trackId (comma-separated)
--type <types>stringFilter by error type (comma-separated)
--device <preset>desktop | mobile | tabletdesktopDevice preset
--openbooleanfalseOpen report in browser after generation
--cibooleanfalseCI mode: exit with code 1 on failures
--diffbooleanfalseCompare with previous report

How It Works

Load ErrorConfig

Reads the JSON file from the --config path and parses it as ErrorConfig. If a simulate section exists in .huh.config.json, it is also loaded.

Filter trackIds

Filters target trackIds based on the --filter and --type options.

Start preview server

Starts an internal HTTP server that renders each error entry as an isolated HTML page. Built-in renderers for TOAST, MODAL, and PAGE types are applied automatically.

Capture screenshots with Playwright

Headless Chromium visits each error entry page and captures a screenshot. Type-specific delays are applied: - TOAST: 350ms - MODAL: 250ms - PAGE: 400ms

Extended Validation

Runs @sanghyuk-2i/huh-core base validation plus additional extended checks. See the Extended Validation section below.

Generate HTML report

Produces report.html with base64-encoded screenshots and report-data.json with structured validation results.


Device Presets

PresetResolutionScale FactorMobile
desktop1280 x 7201xNo
mobile375 x 8122xYes
tablet768 x 10242xYes
bash
# Test with mobile viewport
npx huh test --device mobile

# Test with tablet viewport
npx huh test --device tablet

Simulate Config

Add a simulate field to .huh.config.json to control template variables and timing during tests.

json
{
  "source": { "type": "csv", "filePath": "./errors.csv" },
  "output": "./src/huh.json",
  "simulate": {
    "defaultVariables": {
      "userName": "Jane",
      "count": "5"
    },
    "variables": {
      "ERR_AUTH": {
        "userName": "Admin"
      }
    },
    "waitTimeout": 10000,
    "screenshotDelay": 500
  }
}
FieldTypeDescription
defaultVariablesRecord<string, string>Default variables applied to all trackIds
variablesRecord<string, Record<string, string>>Per-trackId variables (overrides defaultVariables)
waitTimeoutnumberMax wait time for render completion (ms)
screenshotDelaynumberAdditional delay after render before capturing screenshot (ms)

TIP

When a trackId has entries in variables, those values override the same keys in defaultVariables. For example, with the config above, ERR_AUTH's userName will be "Admin", while all other trackIds will use "Jane".


Extended Validation

huh test runs @sanghyuk-2i/huh-core's base validation plus the following extended checks:

CheckSeverityDescription
render-failureerrorPlaywright failed to render the error UI
image-url-brokenwarningThe image field URL is invalid
message-too-longwarningMessage length exceeds the recommended limit for its type
slow-renderwarningRender time exceeded 3000ms
missing-template-variablewarningUnresolved \{\{variable\}\} patterns remain in the output

Recommended message length limits:

TypeMax Characters
TOAST120
MODAL500
PAGE300

Output Files

The following files are generated in the --output directory (default: .huh-report):

FileDescription
report.htmlVisual report with embedded base64 screenshots and validation results
report-data.jsonStructured report data for programmatic use (without screenshots)

report-data.json structure:

json
{
  "generatedAt": "2025-01-15T09:30:00.000Z",
  "device": { "name": "Desktop", "width": 1280, "height": 720 },
  "mode": "standalone",
  "totalEntries": 5,
  "passCount": 4,
  "failCount": 1,
  "warningCount": 2,
  "entries": [
    {
      "trackId": "ERR_AUTH",
      "type": "MODAL",
      "renderTimeMs": 180,
      "success": true,
      "validationIssues": [],
      "coreValidationErrors": [],
      "coreValidationWarnings": []
    }
  ]
}

Diff Mode

Use the --diff option to compare the current results against a previously generated report-data.json.

bash

Detected changes:

StatusDescription
addedNewly added trackId
removedDeleted trackId
changedType, success/fail status, or issue count changed
unchangedNo changes

Example output:

Diff: 1 added, 0 removed, 1 changed, 3 unchanged
  + ERR_TIMEOUT: new entry (type: TOAST)
  ~ ERR_AUTH: status changed (fail → pass)

CI/CD Integration

yaml
on:
  pull_request:
    paths:
      - 'src/huh.json'

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: pnpm/action-setup@v2
        with:
          version: 9

      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: pnpm

      - run: pnpm install
      - run: npx playwright install chromium

      - name: Run huh test
        run: npx huh test --ci --diff

      - name: Upload report
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: huh-report
          path: .huh-report/

WARNING

In --ci mode, the process exits with code 1 if there is at least one error (e.g., render-failure). Warnings alone do not cause a failure.


Filtering

trackId Filter

Test only specific trackIds:

bash

Type Filter

Test only specific error types:

bash
# Test only TOAST type
npx huh test --type TOAST

# Test MODAL and PAGE types
npx huh test --type MODAL,PAGE

Combined Filters

When using both --filter and --type, only entries matching both criteria are tested:

bash
# Only TOAST entries among specific trackIds
npx huh test --filter ERR_NETWORK,ERR_SAVE --type TOAST

Released under the MIT License.