Agent Skills › home-assistant/frontend › ha-frontend-testing

ha-frontend-testing

GitHub

用于 Home Assistant 前端代码的测试、验证及构建工作流。涵盖 Vitest、Playwright E2E、Lint、TypeScript 检查及生产构建命令,指导如何复用测试辅助函数及规范测试编写策略。

.agents/skills/ha-frontend-testing/SKILL.md home-assistant/frontend

Trigger Scenarios

运行前端单元测试或 E2E 测试 执行前端代码检查和格式化 构建前端生产包 启动前端开发服务器

Install

npx skills add home-assistant/frontend --skill ha-frontend-testing -g -y
More Options

Non-standard path

npx skills add https://github.com/home-assistant/frontend/tree/dev/.agents/skills/ha-frontend-testing -g -y

Use without installing

npx skills use home-assistant/frontend@ha-frontend-testing

指定 Agent (Claude Code)

npx skills add home-assistant/frontend --skill ha-frontend-testing -a claude-code -g -y

安装 repo 全部 skill

npx skills add home-assistant/frontend --all -g -y

预览 repo 内 skill

npx skills add home-assistant/frontend --list

SKILL.md

Frontmatter
{
    "name": "ha-frontend-testing",
    "description": "Home Assistant frontend testing and validation workflow. Use when adding or updating tests, running lint, TypeScript checks, Vitest, Playwright e2e suites, dev servers, or chart-data benchmarks."
}

HA Frontend Testing

Use this skill when choosing or running validation for frontend changes.

Test Helpers

  • Before adding or changing tests, inspect the relevant suite's existing helpers and fixtures. Reuse them instead of duplicating setup, test data, navigation, interactions, waits, or assertions.
  • When the same test flow appears more than once, move it into the closest suite-local helper with a focused interface.
  • Keep one-off test behaviour in the test unless a helper makes the intent materially clearer. Do not hide the behaviour under test behind broad, configurable abstractions.

Core Commands

pnpm lint          # ESLint + Prettier + TypeScript + Lit
pnpm format        # Auto-fix ESLint + Prettier
pnpm lint:types    # TypeScript compiler, run without file arguments
pnpm test          # Vitest
pnpm build         # Full production build
pnpm dev           # App dev server
pnpm dev:serve     # Local serving dev server

Never run tsc or pnpm lint:types with file arguments. File arguments make tsc ignore tsconfig.json and can emit .js files into src/.

For focused type feedback on one file, use editor diagnostics instead of a file-scoped tsc command.

Production Builds

Production builds support foreground and managed background execution:

pnpm build                         # Full foreground build
pnpm build --background            # Full managed background build
pnpm build --modern                # Modern frontend_latest bundle only
pnpm build --modern --background   # Modern managed background build
pnpm build --status
pnpm build --logs [--follow]
pnpm build --stop

Use pnpm build --modern --background for production bundle-size or browser performance comparisons that only need modern browser output. It runs the normal metadata and static preparation, minifies and compresses the modern frontend_latest bundle and shared static assets, and generates modern-only entry pages and service workers. It deliberately skips the legacy bundle and its service worker.

Do not pass --help, --background, or --modern to script/build_frontend; that raw script does not parse arguments and always starts the full foreground build. Use pnpm build for managed builds. App builds and development servers keep exclusive ownership of hass_frontend/ for their lifetime.

Managed app, demo, gallery, and E2E app workflows share one lifetime lock, so only one build or development server can run at a time.

When To Add Tests

  • Write tests for code that computes something: data processing, utilities, config validation, and strategies.
  • Do not write rendering tests. This includes views, panels, and components whose text, styles, slots, or option defaults are checked, or that only put context and helper data into a template.
  • Do not try to cover every scenario, especially for behaviour that changes often.
  • If you are not sure a test is useful, describe it and what it would catch, and let the user decide.
  • Tests never talk to a real Home Assistant. Replace callWS, callApi, and the connection with fakes.

Dev Servers

pnpm dev builds and watches the app, served by a running Home Assistant core configured through development_repo.

pnpm dev:serve also serves locally and supports -c for the core URL and -p for the port. The default is 8124, or 8123 in a devcontainer.

Dev server commands support --background, --status, --stop, and --logs [--follow]. pnpm dev, pnpm dev:serve, pnpm dev:demo, and pnpm dev:gallery also support --fetch-translations; this runs translation fetching, including first-time GitHub device authentication, under the workflow lock before starting the watcher. It works in foreground and background modes. Prefer managed background mode while iterating so the watcher stays available across test runs without occupying the terminal. pnpm dev and pnpm dev:serve share one managed process slot because both write the app output.

Playwright E2E

Each suite has its own dev server port. Playwright reuses an existing server locally when its configured URL responds; otherwise it performs a slow full build. When a development watcher is being reused, rspack recompiles on save and reruns should not need a restart.

Start the relevant suite server, then run that suite:

Suite Background server Test command
App pnpm test:e2e:app:dev --background on 8095 pnpm test:e2e:app
Demo pnpm dev:demo --background on 8090 pnpm test:e2e:demo
Gallery pnpm dev:gallery --background on 8100 pnpm test:e2e:gallery

The custom development wrappers use /__ha_dev_status to identify and manage their own suites. Playwright server reuse checks the configured URL instead. Wrapper start and stop operations are idempotent for a matching suite and reject an unrelated process occupying the port.

Local runs against a watched development server do not always match CI's clean build artifacts, environment, sharding, or worker configuration. Use background servers for the fast iteration loop, but confirm the relevant CI jobs complete successfully before considering E2E changes verified.

Use -g "<title>" --project=chromium to narrow a run. pnpm test:e2e runs suites sequentially when managed servers are unavailable to prevent cold builds racing over shared generated assets. Run suites directly; piping through output truncation hides progress and failures.

The app suite uses a stripped-down harness for e2e. Demo and gallery use their normal dev servers.

Benchmarks

For chart data transforms such as history, statistics, energy, and downsampling, read and follow the complete workflow in test/benchmarks/README.md before making benchmark or optimization changes.

That workflow owns the baseline, noise analysis, guardrails, acceptance thresholds, and reporting requirements. In particular, optimizations must keep output bit-identical; never update snapshots or modify fixtures to make an optimization pass.

Verification Selection

  • Documentation-only change: no code test required unless examples or commands changed.
  • Type-only or utility change: run focused Vitest if available, then pnpm lint:types if practical.
  • Lit component change: run relevant tests plus lint or typecheck depending on scope.
  • E2E-sensitive flow: start the relevant e2e dev server and run the narrow Playwright suite.
  • Broad refactor: run pnpm lint and relevant test suites when practical.

Version History

  • 38ac2a0 Current 2026-10-19 18:07

    将包管理器从 Yarn 迁移至 pnpm,更新所有相关命令和配置。

  • fd19a0e 2026-09-28 09:23

    新增规则:停止建议对视觉组件(如视图、面板、组件)进行渲染测试。

  • 156840b 2026-08-28 19:58

    澄清了Agent在何种情况下应添加测试的指导原则。

  • 3c7560a 2026-08-20 08:57

Same Skill Collection

.agents/skills/ha-frontend-components/SKILL.md
.agents/skills/ha-frontend-contexts/SKILL.md
.agents/skills/ha-frontend-demo/SKILL.md
.agents/skills/ha-frontend-events/SKILL.md
.agents/skills/ha-frontend-gallery/SKILL.md
.agents/skills/ha-frontend-lit/SKILL.md
.agents/skills/ha-frontend-review/SKILL.md
.agents/skills/ha-frontend-styling/SKILL.md
.agents/skills/ha-frontend-types/SKILL.md
.agents/skills/ha-frontend-user-facing-text/SKILL.md
.agents/skills/ha-frontend-ux-readiness/SKILL.md

Metadata

Files
0
Version
38ac2a0
Hash
6aa9a5c1
Indexed
2026-08-20 08:57

Accueil - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-10-31 14:15
浙ICP备14020137号-1