Testing Guidelines
The Elements library uses a comprehensive testing strategy with many test types to ensure quality, accessibility, and performance. All tests follow consistent patterns and use shared utilities from @internals/testing and @internals/vite.
Running Tests
Run test scripts from the root directory of the project where the package.json lives.
Test Types
Unit Tests (.test.ts)
- Unit Tests (
.test.ts): Standard behavior tests. - Accessibility Tests (
.test.axe.ts): best practices tests using axe-core. - Lighthouse Performance Tests (
.test.lighthouse.ts): performance audits and best practices via Lighthouse - Visual Regression Tests (
.test.visual.ts): Visual regression tests using Playwright screenshots. - SSR Tests (
.test.ssr.ts): Server-side rendering compatibility tests. - WebGPU rendering tests (
.test.webgpu.ts): External rendering, resource, timing, diagnostic, and lifecycle tests orchestrated by Vitest against a clean Playwright page.
Render regression tests (.test.render.ts)
Core measures Chromium layout and style recalculation counts during interactions on an isolated Playwright page. These counts include legitimate rendering and do not count forced reflows. Use vitest.render.ts with libraryRenderTestConfig. Keep explicit count budgets, readiness, and completion boundaries in each scenario. The shared runner documentation includes the API, a complete grid example, calibration results, commands, and trace investigation guidance.
Test Configuration
Vitest Configs
Each test type has its own Vitest configuration:
- Unit tests:
vitest.config.tsusinglibraryTestConfig - Axe tests:
vitest.axe.tsusinglibraryAxeTestConfig - Lighthouse tests:
vitest.lighthouse.tsusinglibraryLighthouseConfig - Render tests:
vitest.render.tsusinglibraryRenderTestConfig - WebGPU tests:
vitest.webgpu.tsusinglibraryWebGPUTestConfig - Visual tests:
vitest.visual.tsusinglibraryVisualTestConfig - SSR tests:
vitest.ssr.tsusinglibraryLitSSRTestConfig
HTML Templates
Lighthouse, Render, and Visual tests require HTML templates:
vitest.lighthouse.html- Base template for Lighthouse testsvitest.render.html- Base template for Render testsvitest.visual.html- Base template for Visual tests
Testing Utilities
@internals/testing
Core testing utilities for DOM manipulation and element stability:
createFixture: Creates test fixture DOM elementremoveFixture: Removes test fixture DOMelementIsStable: Waits for Lit element to be stableemulateClick: Triggers native click eventsuntilEvent: Creates promise for event results