|
2 | 2 |
|
3 | 3 | This file provides guidance to agents working in `webview-ui/`. |
4 | 4 |
|
| 5 | +## Testing Strategy Overview |
| 6 | + |
| 7 | +We use a complementary two-layer strategy for testing webview UI code: |
| 8 | + |
| 9 | +1. **Vitest + JSDOM (`*.test.tsx`)**: Unit, hook, state-machine, and interaction tests. |
| 10 | +2. **Playwright Component Testing (`*.visual.tsx`)**: Visual snapshot, VS Code theme variable, layout, and shadow DOM tests. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +### When to write a JSDOM Test (`*.test.tsx`) vs. a Playwright Visual Test (`*.visual.tsx`) |
| 15 | + |
| 16 | +| Testing Goal | Recommended Harness | |
| 17 | +| :-------------------------------------------------------------------- | :-------------------------------------------------------------------- | |
| 18 | +| Component state transitions, reducer actions, custom hook behavior | **Vitest + JSDOM** (`*.test.tsx`) | |
| 19 | +| User interactions (button clicks, form validation, text typing) | **Vitest + JSDOM** (`*.test.tsx`) using `@testing-library/user-event` | |
| 20 | +| Conditional DOM rendering or prop wiring | **Vitest + JSDOM** (`*.test.tsx`) | |
| 21 | +| Visual layout, flexbox/grid alignment, or padding/margin verification | **Playwright CT** (`*.visual.tsx`) | |
| 22 | +| VS Code dark/light theme CSS tokens (`--vscode-*`) | **Playwright CT** (`*.visual.tsx`) | |
| 23 | +| Web component shadow DOM style encapsulation & upgrades | **Playwright CT** (`*.visual.tsx`) | |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Unit & State Tests (Vitest + JSDOM) |
| 28 | + |
5 | 29 | - Prefer local `webview-ui` tests for React/webview behavior. If a change is about component rendering, local state, hooks, form dirty-state, validation, or prop wiring inside the webview, add or update Vitest coverage under `webview-ui/src/**/__tests__` instead of reaching for `apps/vscode-e2e`. |
6 | 30 | - Use `apps/vscode-e2e` only when the behavior depends on the real VS Code extension environment: extension-host to webview messaging, VS Code workspace APIs, task execution flows, or other end-to-end behavior that needs `@vscode/test-electron`. |
7 | 31 | - When a regression can be proven with a component or webview integration test, keep it in `webview-ui`. Do not promote it to e2e just because the UI is hosted inside VS Code. |
8 | 32 | - For `SettingsView`, preserve the cached-state pattern from the repo root guidance: inputs should operate on local `cachedState` until the user saves, and tests should distinguish automatic initialization from real user edits. |
9 | 33 |
|
10 | | -## Visual Tests |
| 34 | +### Coverage & Codecov Quality Gates |
| 35 | + |
| 36 | +Codecov tracks `webview-ui` coverage under the `webview-ui` flag. |
| 37 | + |
| 38 | +- **Ratcheting (`target: auto`)**: Overall webview coverage will never drop below the current baseline as new tests are added. |
| 39 | +- **Patch Gate (`target: 70%`)**: New or modified lines in PRs touching `webview-ui/src/` must meet minimum test coverage, ensuring state changes and new UI logic stay tested over time. |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +## Visual Tests (Playwright CT) |
11 | 44 |
|
12 | 45 | - Add Playwright screenshot tests selectively for components where layout, styling, VS Code theme variables, or real web-component rendering are part of the behavior under test. |
13 | 46 | - Keep behavioral assertions in Vitest. A `*.visual.tsx` test should establish a deterministic state and make a focused screenshot assertion. |
|
0 commit comments