Skip to content

ericrisco/rsc-harness / skills/testing-web

testing-web

Verified

Use when writing or fixing frontend unit, component or custom-hook tests with Vitest or Jest plus Testing Library — rendering a component in jsdom, testing a hook in isolation, choosing between sync and async queries, silencing act warnings, mocking fetch, or migrating a Jest suite to Vitest. NOT real-browser multi-page journeys (that is `e2e-testing`), NOT pytest suites (that is `testing-py`), NOT accessibility auditing (that is `accessibility`).

FileKindSize
SKILL.mdskill md13.0 KB
evals/README.mdmarkdown907 B
evals/cases.yamlconfig3.6 KB
references/jest-setup.mdmarkdown3.0 KB
references/recipes.mdmarkdown3.7 KB
scripts/verify.shexecutablescript4.0 KB

scripts/verify.sh

View on GitHub
#!/usr/bin/env bash
set -euo pipefail

# verify.sh — testing-web skill gate. Lints frontend test files for the load-bearing rules.
#
# Usage:  scripts/verify.sh [PATH]      (PATH = a test file or a directory; default: current dir)
#
# Read-only. Never executes the tests, never edits anything. It checks artifact SHAPE, not whether the
# assertions are true.
#
# Discovers test files matching *.test.* / *.spec.* (.ts/.tsx/.js/.jsx), skipping node_modules/.git/dist.
# Per file:
#   HARD fail (exit 1):
#     - zero `expect(`                                  -> a test that asserts nothing
#     - a userEvent/`user.<verb>(` interaction not preceded by `await` on the same line
#   WARN (advisory, never changes exit code):
#     - getByTestId used while no getByRole/getByLabelText/getByText query is present
#     - raw fireEvent( where userEvent would do
#     - act( inside a component (non-hook) test file
#     - setTimeout(-based waiting instead of waitFor/findBy
#
# An empty or clean target exits 0 (no false failure). Stock macOS bash 3.2 compatible.

YELLOW=$'\033[33m'; GREEN=$'\033[32m'; RED=$'\033[31m'; NC=$'\033[0m'
EXIT=0
warn() { printf '%s[warn]%s %s\n' "$YELLOW" "$NC" "$*"; }
ok()   { printf '%s[ok]%s %s\n'   "$GREEN"  "$NC" "$*"; }
err()  { printf '%s[fail]%s %s\n' "$RED"    "$NC" "$*"; EXIT=1; }

TARGET="${1:-.}"
if [ ! -e "$TARGET" ]; then
  err "path not found: $TARGET"
  exit 1
fi

FILES=()
if [ -f "$TARGET" ]; then
  FILES+=("$TARGET")
else
  while IFS= read -r -d '' f; do
    FILES+=("$f")
  done < <(
    find "$TARGET" \
      \( -path '*/node_modules/*' -o -path '*/.git/*' -o -path '*/dist/*' -o -path '*/build/*' -o -path '*/coverage/*' \) -prune -o \
      -type f \( -name '*.test.ts' -o -name '*.test.tsx' -o -name '*.test.js' -o -name '*.test.jsx' \
                 -o -name '*.spec.ts' -o -name '*.spec.tsx' -o -name '*.spec.js' -o -name '*.spec.jsx' \) -print0 2>/dev/null
  )
fi

if [ "${#FILES[@]}" -eq 0 ]; then
  warn "no *.test.* / *.spec.* files found under $TARGET — nothing to lint"
  ok "verify.sh passed (empty target)"
  exit 0
fi

for f in "${FILES[@]}"; do
  problems=0

  # --- HARD: must contain at least one assertion ---
  if ! grep -Eq 'expect[[:space:]]*\(' "$f"; then
    err "$f: no expect(...) — a test must assert something observable"
    problems=$((problems + 1))
  fi

  # --- HARD: every userEvent/user.<verb>( interaction must be awaited on its line ---
  # Match interaction calls (user.click(, userEvent.type(, etc.) whose line lacks `await`.
  unawaited="$(grep -nE '(^|[^a-zA-Z0-9_.])(user|userEvent)\.[a-zA-Z]+[[:space:]]*\(' "$f" 2>/dev/null \
                | grep -vE '\bawait\b' \
                | grep -vE '\.setup[[:space:]]*\(' || true)"
  if [ -n "$unawaited" ]; then
    err "$f: user-event interaction not awaited (await user.click/type/...):"
    printf '%s\n' "$unawaited" | sed 's/^/      /'
    problems=$((problems + 1))
  fi

  # --- WARN: testid as the only query (no role/label/text query present) ---
  if grep -Eq 'getByTestId|findByTestId|queryByTestId' "$f"; then
    if ! grep -Eq 'ByRole|ByLabelText|ByText|ByPlaceholderText|ByDisplayValue' "$f"; then
      warn "$f: uses *ByTestId with no role/label/text query — climb the query ladder first"
    fi
  fi

  # --- WARN: raw fireEvent ---
  if grep -Eq '\bfireEvent\.' "$f"; then
    warn "$f: uses fireEvent — prefer userEvent.setup() + await user.* for realistic events"
  fi

  # --- WARN: act( in a component (non-hook) test file ---
  if grep -Eq '(^|[^a-zA-Z0-9_])act[[:space:]]*\(' "$f"; then
    if ! grep -Eq 'renderHook' "$f"; then
      warn "$f: bare act() in a component test — await findBy/waitFor instead"
    fi
  fi

  # --- WARN: setTimeout-based waiting ---
  if grep -Eq '\bsetTimeout[[:space:]]*\(' "$f" && ! grep -Eq 'waitFor|findBy' "$f"; then
    warn "$f: waits with setTimeout and no waitFor/findBy — use waitFor/findBy to retry until ready"
  fi

  if [ "$problems" -eq 0 ]; then
    ok "$f"
  fi
done

printf '\n'
if [ "$EXIT" -eq 0 ]; then
  ok "verify.sh passed"
else
  err "verify.sh found hard violations"
fi
exit "$EXIT"
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 469kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 469kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 469kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall