Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test(components): restore web and html-reporter component tests (#41889)

Pavel Feldman58cf15c7c0ed
diff --git a/.github/workflows/tests_primary.yml b/.github/workflows/tests_primary.yml
index 5e4be9bea7..a4da6a0e7f 100644
--- a/.github/workflows/tests_primary.yml
+++ b/.github/workflows/tests_primary.yml
@@ -140,6 +140,29 @@ jobs:
env:
PWTEST_SHARD_WEIGHTS: ${{ matrix.shardWeights }}
+ test_web_components:
+ name: Web Components - ${{ matrix.package }}
+ environment: ${{ github.event_name == 'push' && 'allow-uploading-flakiness-results' || null }}
+ permissions:
+ id-token: write # This is required for OIDC login (azure/login) to succeed
+ contents: read # This is required for actions/checkout to succeed
+ strategy:
+ fail-fast: false
+ matrix:
+ package: [html-reporter, web]
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v6
+ - uses: ./.github/actions/run-test
+ with:
+ node-version: 20
+ browsers-to-install: chromium
+ command: npm run test-${{ matrix.package }}
+ bot-name: "web-components-${{ matrix.package }}"
+ flakiness-client-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_CLIENT_ID }}
+ flakiness-tenant-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_TENANT_ID }}
+ flakiness-subscription-id: ${{ secrets.AZURE_FLAKINESS_DASHBOARD_SUBSCRIPTION_ID }}
+
test_vscode_extension:
name: VSCode Extension
runs-on: ubuntu-latest
diff --git a/examples/ct-react-vite/.gitignore b/examples/ct-react-vite/.gitignore
deleted file mode 100644
index 5bb1c7684c..0000000000
--- a/examples/ct-react-vite/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-node_modules
-dist
-test-results
-playwright-report
diff --git a/examples/ct-react-vite/index.html b/examples/ct-react-vite/index.html
deleted file mode 100644
index cf3a13303c..0000000000
--- a/examples/ct-react-vite/index.html
+++ /dev/null
@@ -1,13 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
- <head>
- <meta charset="UTF-8" />
- <link rel="icon" type="image/svg+xml" href="/src/assets/favicon.svg" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>Vite App</title>
- </head>
- <body>
- <div id="root"></div>
- <script type="module" src="/src/main.tsx"></script>
- </body>
-</html>
diff --git a/examples/ct-react-vite/package.json b/examples/ct-react-vite/package.json
deleted file mode 100644
index 0479b93f1b..0000000000
--- a/examples/ct-react-vite/package.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
- "name": "ct-react-vite-example",
- "private": true,
- "version": "0.0.0",
- "type": "module",
- "scripts": {
- "dev": "vite",
- "build": "tsc && vite build",
- "test": "playwright test",
- "typecheck": "tsc --noEmit"
- },
- "dependencies": {
- "react": "^18.2.0",
- "react-dom": "^18.2.0",
- "react-router-dom": "^6.6.1"
- },
- "devDependencies": {
- "@playwright/test": "^1.56.0",
- "@types/react": "^18.0.26",
- "@types/react-dom": "^18.0.10",
- "@vitejs/plugin-react": "^6.0.3",
- "typescript": "^5.2.2",
- "vite": "^8.1.0"
- }
-}
diff --git a/examples/ct-react-vite/playwright.config.ts b/examples/ct-react-vite/playwright.config.ts
deleted file mode 100644
index 8be33427cb..0000000000
--- a/examples/ct-react-vite/playwright.config.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-import { defineConfig, devices } from '@playwright/test';
-
-// Component testing with Playwright, following the playwright-component-testing skill.
-// The gallery (playwright/gallery/index.html) is served by the app's own Vite dev server;
-// `baseURL` points the built-in `mount` fixture at it.
-export default defineConfig({
- // Specs live next to their components as trios: Button.tsx / Button.story.tsx / Button.spec.tsx.
- testDir: './src',
- forbidOnly: !!process.env.CI,
- retries: process.env.CI ? 2 : 0,
- reporter: process.env.CI ? 'html' : 'line',
- webServer: {
- command: 'npm run dev',
- url: 'http://localhost:5173/playwright/gallery/index.html',
- reuseExistingServer: !process.env.CI,
- },
- use: {
- baseURL: 'http://localhost:5173/playwright/gallery/index.html',
- serviceWorkers: 'block',
- reuseContext: true,
- trace: 'on-first-retry',
- },
- projects: [
- { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
- { name: 'firefox', use: { ...devices['Desktop Firefox'] } },
- { name: 'webkit', use: { ...devices['Desktop Safari'] } },
- ],
-});
diff --git a/examples/ct-react-vite/playwright/gallery/index.html b/examples/ct-react-vite/playwright/gallery/index.html
deleted file mode 100644
index 2dfb0a5b57..0000000000
--- a/examples/ct-react-vite/playwright/gallery/index.html
+++ /dev/null
@@ -1,12 +0,0 @@
-<!DOCTYPE html>
-<html lang="en">
- <head>
- <meta charset="UTF-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
- <title>Component gallery</title>
- </head>
- <body>
- <div id="root"></div>
- <script type="module" src="./main.tsx"></script>
- </body>
-</html>
diff --git a/examples/ct-react-vite/playwright/gallery/main.tsx b/examples/ct-react-vite/playwright/gallery/main.tsx
deleted file mode 100644
index 5822ceca54..0000000000
--- a/examples/ct-react-vite/playwright/gallery/main.tsx
+++ /dev/null
@@ -1,38 +0,0 @@
-// Playwright component gallery — implements the contract in the playwright-component-testing
-// skill (references/gallery-spec.md): a single page exposing window.mount()/window.unmount().
-// The built-in `mount` fixture navigates here (baseURL) and calls window.mount via
-// page.evaluate(..., { exposeFunctions: true }), so props may carry real callbacks.
-import { flushSync } from 'react-dom';
-import { createRoot, type Root } from 'react-dom/client';
-import '../../src/assets/index.css';
-
-// import.meta.glob must stay inline: Vite analyzes it statically, relative to this file.
-const stories = import.meta.glob('../../src/**/*.story.tsx');
-const id = (f: string) => f.replace(/^(\.\.\/)+src\//, '').replace(/\.story\.\w+$/, '');
-
-// Story id is '<path under src, without .story.tsx>/<ExportName>', e.g. 'components/Button/Default'.
-async function resolve(storyId: string) {
- const sep = storyId.lastIndexOf('/');
- const [path, name] = [storyId.slice(0, sep), storyId.slice(sep + 1)];
- const file = Object.keys(stories).find(f => id(f) === path || id(f).endsWith('/' + path));
- const mod = (file && await stories[file]()) as Record<string, any> | undefined;
- return mod?.[name] ?? mod?.default;
-}
-
-const rootEl = document.getElementById('root')!;
-let root: Root | undefined;
-
-(window as any).mount = async ({ story, props }: { story: string, props?: Record<string, any> }) => {
- const Story = await resolve(story);
- if (!Story)
- throw new Error(`Unknown story: ${story}`);
- // Reuse the root so component.update() reconciles in place and preserves state.
- root ??= createRoot(rootEl);
- // flushSync so a render error rejects the promise instead of being swallowed.
- flushSync(() => root!.render(<Story {...props} />));
-};
-
-(window as any).unmount = async () => {
- root?.unmount();
- root = undefined;
-};
diff --git a/examples/ct-react-vite/src/App.spec.tsx b/examples/ct-react-vite/src/App.spec.tsx
deleted file mode 100644
index 3e01da7173..0000000000
--- a/examples/ct-react-vite/src/App.spec.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-import { test, expect } from '@playwright/test';
-
-test('navigate to a page by clicking a link', async ({ mount }) => {
- const component = await mount('App/Routing');
- await expect(component.getByRole('main')).toHaveText('Login');
- await component.getByRole('link', { name: 'Dashboard' }).click();
- await expect(component.getByRole('main')).toHaveText('Dashboard');
-});
-
-test('update does not reset the router', async ({ mount }) => {
- const component = await mount('App/Routing', { title: 'before' });
- await expect(component.getByRole('heading')).toHaveText('before');
- await expect(component.getByRole('main')).toHaveText('Login');
-
- await component.update({ title: 'after' });
- await expect(component.getByRole('heading')).toHaveText('after');
- await expect(component.getByRole('main')).toHaveText('Login');
-});
diff --git a/examples/ct-react-vite/src/App.story.tsx b/examples/ct-react-vite/src/App.story.tsx
deleted file mode 100644
index 66a9b8d229..0000000000
--- a/examples/ct-react-vite/src/App.story.tsx
+++ /dev/null
@@ -1,6 +0,0 @@
-import { MemoryRouter } from 'react-router-dom';
-import App from './App';
-
-// Providers (here a router) are wired inside the story — the skill's decorator pattern.
-// MemoryRouter is used so routing starts at '/' regardless of the gallery's own URL.
-export const Routing = (props: any) => <MemoryRouter><App {...props} /></MemoryRouter>;
diff --git a/examples/ct-react-vite/src/App.tsx b/examples/ct-react-vite/src/App.tsx
deleted file mode 100644
index fd004390f3..0000000000
--- a/examples/ct-react-vite/src/App.tsx
+++ /dev/null
@@ -1,21 +0,0 @@
-import { Routes, Route, Link } from 'react-router-dom';
-import logo from './assets/logo.svg';
-import LoginPage from './pages/LoginPage';
-import DashboardPage from './pages/DashboardPage';
-
-export default function App({ title }: { title?: string }) {
- return <>
- <header>
- <img src={logo} alt="logo" width={125} height={125} />
- {title && <h1>{title}</h1>}
- <Link to="/">Login</Link>
- <Link to="/dashboard">Dashboard</Link>
- </header>
- <Routes>
- <Route path="/">
- <Route index element={<LoginPage />} />
- <Route path="dashboard" element={<DashboardPage />} />
- </Route>
- </Routes>
- </>
-}
diff --git a/examples/ct-react-vite/src/assets/favicon.svg b/examples/ct-react-vite/src/assets/favicon.svg
deleted file mode 100644
index de4aeddc12..0000000000
--- a/examples/ct-react-vite/src/assets/favicon.svg
+++ /dev/null
@@ -1,15 +0,0 @@
-<svg width="410" height="404" viewBox="0 0 410 404" fill="none" xmlns="http://www.w3.org/2000/svg">
-<path d="M399.641 59.5246L215.643 388.545C211.844 395.338 202.084 395.378 198.228 388.618L10.5817 59.5563C6.38087 52.1896 12.6802 43.2665 21.0281 44.7586L205.223 77.6824C206.398 77.8924 207.601 77.8904 208.776 77.6763L389.119 44.8058C397.439 43.2894 403.768 52.1434 399.641 59.5246Z" fill="url(#paint0_linear)"/>
-<path d="M292.965 1.5744L156.801 28.2552C154.563 28.6937 152.906 30.5903 152.771 32.8664L144.395 174.33C144.198 177.662 147.258 180.248 150.51 179.498L188.42 170.749C191.967 169.931 195.172 173.055 194.443 176.622L183.18 231.775C182.422 235.487 185.907 238.661 189.532 237.56L212.947 230.446C216.577 229.344 220.065 232.527 219.297 236.242L201.398 322.875C200.278 328.294 207.486 331.249 210.492 326.603L212.5 323.5L323.454 102.072C325.312 98.3645 322.108 94.137 318.036 94.9228L279.014 102.454C275.347 103.161 272.227 99.746 273.262 96.1583L298.731 7.86689C299.767 4.27314 296.636 0.855181 292.965 1.5744Z" fill="url(#paint1_linear)"/>
-<defs>
-<linearGradient id="paint0_linear" x1="6.00017" y1="32.9999" x2="235" y2="344" gradientUnits="userSpaceOnUse">
-<stop stop-color="#41D1FF"/>
-<stop offset="1" stop-color="#BD34FE"/>
-</linearGradient>
-<linearGradient id="paint1_linear" x1="194.651" y1="8.81818" x2="236.076" y2="292.989" gradientUnits="userSpaceOnUse">
-<stop stop-color="#FFEA83"/>
-<stop offset="0.0833333" stop-color="#FFDD35"/>
-<stop offset="1" stop-color="#FFA800"/>
-</linearGradient>
-</defs>
-</svg>
diff --git a/examples/ct-react-vite/src/assets/iconfont.woff2 b/examples/ct-react-vite/src/assets/iconfont.woff2
deleted file mode 100644
index ed1f4f34a4..0000000000
Binary files a/examples/ct-react-vite/src/assets/iconfont.woff2 and /dev/null differ
diff --git a/examples/ct-react-vite/src/assets/index.css b/examples/ct-react-vite/src/assets/index.css
deleted file mode 100644
index dd2a6fa726..0000000000
--- a/examples/ct-react-vite/src/assets/index.css
+++ /dev/null
@@ -1,29 +0,0 @@
-body {
- margin: 0;
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
- 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
- sans-serif;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
-}
-
-code {
- font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
- monospace;
-}
-
-@media (prefers-color-scheme: light) {
- :root {
- color: #e3e3e3;
- background-color: #1b1b1d;
- }
-}
-
-@font-face {
- font-family: 'pwtest-iconfont';
- /* See tests/assets/webfont/README.md */
- src: url('./iconfont.woff2') format('woff2');
- font-weight: normal;
- font-style: normal;
- font-display: swap;
-}
diff --git a/examples/ct-react-vite/src/assets/logo.svg b/examples/ct-react-vite/src/assets/logo.svg
deleted file mode 100644
index 6b60c1042f..0000000000
--- a/examples/ct-react-vite/src/assets/logo.svg
+++ /dev/null
@@ -1,7 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3">
- <g fill="#61DAFB">
- <path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/>
- <circle cx="420.9" cy="296.5" r="45.7"/>
- <path d="M520.5 78.1z"/>
- </g>
-</svg>
diff --git a/examples/ct-react-vite/src/components/Button.spec.tsx b/examples/ct-react-vite/src/components/Button.spec.tsx
deleted file mode 100644
index fd2d401151..0000000000
--- a/examples/ct-react-vite/src/components/Button.spec.tsx
+++ /dev/null
@@ -1,34 +0,0 @@
-import { test, expect } from '@playwright/test';
-
-test('render props', async ({ mount }) => {
- const component = await mount('components/Button/Default');
- await expect(component).toContainText('Submit');
-});
-
-test('render attributes', async ({ mount }) => {
- const component = await mount('components/Button/Default', { className: 'primary' });
- await expect(component).toHaveClass('primary');
-});
-
-test('execute callback when the button is clicked', async ({ mount }) => {
- const messages: string[] = [];
- const component = await mount('components/Button/Default', {
- onClick: (data: string) => messages.push(data),
- });
- await component.click();
- expect(messages).toEqual(['hello']);
-});
-
-test('unmount', async ({ mount, page }) => {
- const component = await mount('components/Button/Default');
- await expect(page.locator('#root')).toContainText('Submit');
- await component.unmount();
- await expect(page.locator('#root')).not.toContainText('Submit');
-});
-
-test('mount, unmount, then mount again', async ({ mount }) => {
- let component = await mount('components/Button/Default');
- await component.unmount();
- component = await mount('components/Button/Default', { title: 'Save' });
- await expect(component).toContainText('Save');
-});
diff --git a/examples/ct-react-vite/src/components/Button.story.tsx b/examples/ct-react-vite/src/components/Button.story.tsx
deleted file mode 100644
index 34d0dd117c..0000000000
--- a/examples/ct-react-vite/src/components/Button.story.tsx
+++ /dev/null
@@ -1,4 +0,0 @@
-import Button from './Button';
-
-// Spreads props so a test can pass `title`, `className`, or a real `onClick` callback.
-export const Default = (props: any) => <Button title="Submit" {...props} />;
diff --git a/examples/ct-react-vite/src/components/Button.tsx b/examples/ct-react-vite/src/components/Button.tsx
deleted file mode 100644
index 8785b878d0..0000000000
--- a/examples/ct-react-vite/src/components/Button.tsx
+++ /dev/null
@@ -1,13 +0,0 @@
-import { ButtonHTMLAttributes } from "react";
-
-type ButtonProps = {
- title: string;
- onClick?(props: string): void;
- className?: string;
-} & Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'onClick'>;
-
-export default function Button({ onClick, title, ...attributes }: ButtonProps) {
- return <button {...attributes} onClick={() => onClick?.('hello')}>
- {title}
- </button>
-}
diff --git a/examples/ct-react-vite/src/components/CheckChildrenProp.spec.tsx b/examples/ct-react-vite/src/components/CheckChildrenProp.spec.tsx
deleted file mode 100644
index 755e1b5d06..0000000000
--- a/examples/ct-react-vite/src/components/CheckChildrenProp.spec.tsx
+++ /dev/null
@@ -1,6 +0,0 @@
-import { test, expect } from '@playwright/test';
-
-test('absence of children', async ({ mount }) => {
- const component = await mount('components/CheckChildrenProp/NoChildren');
- await expect(component).toContainText('No Children');
-});
diff --git a/examples/ct-react-vite/src/components/CheckChildrenProp.story.tsx b/examples/ct-react-vite/src/components/CheckChildrenProp.story.tsx
deleted file mode 100644
index 7c3f8410ae..0000000000
--- a/examples/ct-react-vite/src/components/CheckChildrenProp.story.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-import CheckChildrenProp from './CheckChildrenProp';
-
-export const NoChildren = () => <CheckChildrenProp />;
diff --git a/examples/ct-react-vite/src/components/CheckChildrenProp.tsx b/examples/ct-react-vite/src/components/CheckChildrenProp.tsx
deleted file mode 100644
index 3e8f405a5b..0000000000
--- a/examples/ct-react-vite/src/components/CheckChildrenProp.tsx
+++ /dev/null
@@ -1,7 +0,0 @@
-import type { PropsWithChildren } from 'react';
-
-type DefaultChildrenProps = PropsWithChildren<{}>;
-
-export default function CheckChildrenProp(props: DefaultChildrenProps) {
- return <>{'children' in props ? props.children : 'No Children'}</>
-}
diff --git a/examples/ct-react-vite/src/components/ComponentAsProp.spec.tsx b/examples/ct-react-vite/src/components/ComponentAsProp.spec.tsx
deleted file mode 100644
index 1e8c2156f6..0000000000
--- a/examples/ct-react-vite/src/components/ComponentAsProp.spec.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import { test, expect } from '@playwright/test';
-
-test('render component as a prop', async ({ mount }) => {
- const component = await mount('components/ComponentAsProp/WithButton');
- await expect(component.getByRole('button', { name: 'Submit' })).toBeVisible();
-});
-
-test('render a jsx array as a prop', async ({ mount }) => {
- const component = await mount('components/ComponentAsProp/WithArray');
- await expect(component.getByRole('heading', { level: 4 })).toHaveText('4');
- await expect(component.getByRole('paragraph')).toHaveText('[2,3]');
-});
diff --git a/examples/ct-react-vite/src/components/ComponentAsProp.story.tsx b/examples/ct-react-vite/src/components/ComponentAsProp.story.tsx
deleted file mode 100644
index 9c3db66e3c..0000000000
--- a/examples/ct-react-vite/src/components/ComponentAsProp.story.tsx
+++ /dev/null
@@ -1,7 +0,0 @@
-import { ComponentAsProp } from './ComponentAsProp';
-import Button from './Button';
-
-// The rendered node passed as a prop is baked into the story (JSX can't travel from the test).
-export const WithButton = () => <ComponentAsProp component={<Button title="Submit" />} />;
-
-export const WithArray = () => <ComponentAsProp component={[<h4>{[4]}</h4>, [[<p>[2,3]</p>]]]} />;
diff --git a/examples/ct-react-vite/src/components/ComponentAsProp.tsx b/examples/ct-react-vite/src/components/ComponentAsProp.tsx
deleted file mode 100644
index 67b8813207..0000000000
--- a/examples/ct-react-vite/src/components/ComponentAsProp.tsx
+++ /dev/null
@@ -1,9 +0,0 @@
-import { ReactNode } from "react";
-
-type ComponentAsProp = {
- component: ReactNode[] | ReactNode;
-};
-
-export function ComponentAsProp({ component }: ComponentAsProp) {
- return <div>{component}</div>
-}
diff --git a/examples/ct-react-vite/src/components/Counter.spec.tsx b/examples/ct-react-vite/src/components/Counter.spec.tsx
deleted file mode 100644
index 5e7640bb77..0000000000
--- a/examples/ct-react-vite/src/components/Counter.spec.tsx
+++ /dev/null
@@ -1,36 +0,0 @@
-import { test, expect } from '@playwright/test';
-
-// component.update(props) re-renders the same story on the reused root, so state survives —
-// remount-count stays 1 throughout.
-test('update props without remounting', async ({ mount }) => {
- const component = await mount('components/Counter/Default', { count: 9001 });
- await expect(component.getByTestId('props')).toContainText('9001');
-
- await component.update({ count: 1337 });
- await expect(component).not.toContainText('9001');
- await expect(component.getByTestId('props')).toContainText('1337');
-
- await expect(component.getByTestId('remount-count')).toContainText('1');
-});
-
-test('update callbacks without remounting', async ({ mount }) => {
- const component = await mount('components/Counter/Default');
-
- const messages: string[] = [];
- await component.update({ onClick: (message: string) => messages.push(message) });
- await component.click();
- expect(messages).toEqual(['hello']);
-
- await expect(component.getByTestId('remount-count')).toContainText('1');
-});
-
-test('update children without remounting', async ({ mount }) => {
- const component = await mount('components/Counter/Default', { children: 'Default Slot' });
- await expect(component).toContainText('Default Slot');
-
- await component.update({ children: 'Test Slot' });
- await expect(component).not.toContainText('Default Slot');
- await expect(component).toContainText('Test Slot');
-
- await expect(component.getByTestId('remount-count')).toContainText('1');
-});
diff --git a/examples/ct-react-vite/src/components/Counter.story.tsx b/examples/ct-react-vite/src/components/Counter.story.tsx
deleted file mode 100644
index fc5e31281e..0000000000
--- a/examples/ct-react-vite/src/components/Counter.story.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import Counter from './Counter';
-
-// Spreads props (count, onClick, children) so tests can drive it and, crucially, call
-// component.update(newProps) to re-render in place — remount-count stays 1.
-export const Default = (props: any) => <Counter {...props} />;
diff --git a/examples/ct-react-vite/src/components/Counter.tsx b/examples/ct-react-vite/src/components/Counter.tsx
deleted file mode 100644
index 18e999de73..0000000000
--- a/examples/ct-react-vite/src/components/Counter.tsx
+++ /dev/null
@@ -1,25 +0,0 @@
-import { useLayoutEffect, useRef, useState } from "react"
-
- type CounterProps = {
- count?: number;
- onClick?(props: string): void;
- children?: any;
- }
-
- let _remountCount = 1;
-
- export default function Counter(props: CounterProps) {
- const [remountCount] = useState(_remountCount);
- const didMountRef = useRef(false)
- useLayoutEffect(() => {
- if (!didMountRef.current) {
- didMountRef.current = true;
- _remountCount++;
- }
- }, [])
- return <button onClick={() => props.onClick?.('hello')}>
- <span data-testid="props">{ props.count }</span>
- <span data-testid="remount-count">{ remountCount }</span>
- { props.children }
- </button>
- }
diff --git a/examples/ct-react-vite/src/components/DefaultChildren.spec.tsx b/examples/ct-react-vite/src/components/DefaultChildren.spec.tsx
deleted file mode 100644
index bd41ae3221..0000000000
--- a/examples/ct-react-vite/src/components/DefaultChildren.spec.tsx
+++ /dev/null
@@ -1,31 +0,0 @@
-import { test, expect } from '@playwright/test';
-
-test('render a default child', async ({ mount }) => {
- const component = await mount('components/DefaultChildren/Text');
- await expect(component).toContainText('Main Content');
-});
-
-test('render a component as a child', async ({ mount }) => {
- const component = await mount('components/DefaultChildren/WithButton');
- await expect(component).toContainText('Submit');
-});
-
-test('render multiple children', async ({ mount }) => {
- const component = await mount('components/DefaultChildren/Multiple');
- await expect(component.getByTestId('one')).toContainText('One');
- await expect(component.getByTestId('two')).toContainText('Two');
-});
-
-test('render a number as a child', async ({ mount }) => {
- const component = await mount('components/DefaultChildren/Number');
- await expect(component).toContainText('1337');
-});
-
-test('execute callback when a child node is clicked', async ({ mount }) => {
- let clickFired = false;
- const component = await mount('components/DefaultChildren/ClickableChild', {
- onChildClick: () => (clickFired = true),
- });
- await component.getByText('Main Content').click();
- expect(clickFired).toBeTruthy();
-});
diff --git a/examples/ct-react-vite/src/components/DefaultChildren.story.tsx b/examples/ct-react-vite/src/components/DefaultChildren.story.tsx
deleted file mode 100644
index 59254c743e..0000000000
--- a/examples/ct-react-vite/src/components/DefaultChildren.story.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-import DefaultChildren from './DefaultChildren';
-import Button from './Button';
-
-// Children cannot cross the test/browser boundary as JSX, so each composition is its own story.
-export const Text = () => <DefaultChildren>Main Content</DefaultChildren>;
-
-export const WithButton = () => <DefaultChildren><Button title="Submit" /></DefaultChildren>;
-
-export const Multiple = () => <DefaultChildren>
- <div data-testid="one">One</div>
- <div data-testid="two">Two</div>
-</DefaultChildren>;
-
-export const Number = () => <DefaultChildren>{1337}</DefaultChildren>;
-
-// A clickable child whose handler is supplied by the test as a callback prop.
-export const ClickableChild = (props: { onChildClick?: () => void }) =>
- <DefaultChildren><span onClick={props.onChildClick}>Main Content</span></DefaultChildren>;
diff --git a/examples/ct-react-vite/src/components/DefaultChildren.tsx b/examples/ct-react-vite/src/components/DefaultChildren.tsx
deleted file mode 100644
index 691b6a0806..0000000000
--- a/examples/ct-react-vite/src/components/DefaultChildren.tsx
+++ /dev/null
@@ -1,15 +0,0 @@
-type DefaultChildrenProps = {
- children?: any;
-}
-
-export default function DefaultChildren(props: DefaultChildrenProps) {
- return <div>
- <h1>Welcome!</h1>
- <main>
- {props.children}
- </main>
- <footer>
- Thanks for visiting.
- </footer>
- </div>
-}
diff --git a/examples/ct-react-vite/src/components/EmptyFragment.spec.tsx b/examples/ct-react-vite/src/components/EmptyFragment.spec.tsx
deleted file mode 100644
index cf656897c2..0000000000
--- a/examples/ct-react-vite/src/components/EmptyFragment.spec.tsx
+++ /dev/null
@@ -1,7 +0,0 @@
-import { test, expect } from '@playwright/test';
-
-test('render an empty component', async ({ mount, page }) => {
- const component = await mount('components/EmptyFragment/Default');
- expect(await page.evaluate(() => 'props' in window && (window as any).props)).toEqual({});
- await expect(component).toHaveText('');
-});
diff --git a/examples/ct-react-vite/src/components/EmptyFragment.story.tsx b/examples/ct-react-vite/src/components/EmptyFragment.story.tsx
deleted file mode 100644
index 95ba94b540..0000000000
--- a/examples/ct-react-vite/src/components/EmptyFragment.story.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-import EmptyFragment from './EmptyFragment';
-
-export const Default = () => <EmptyFragment />;
diff --git a/examples/ct-react-vite/src/components/EmptyFragment.tsx b/examples/ct-react-vite/src/components/EmptyFragment.tsx
deleted file mode 100644
index b424841462..0000000000
--- a/examples/ct-react-vite/src/components/EmptyFragment.tsx
+++ /dev/null
@@ -1,4 +0,0 @@
-export default function EmptyFragment(props: unknown) {
- Object.assign(window, { props });
- return <>{[]}</>;
-}
diff --git a/examples/ct-react-vite/src/components/Fetcher.spec.tsx b/examples/ct-react-vite/src/components/Fetcher.spec.tsx
deleted file mode 100644
index e6a9fb3302..0000000000
--- a/examples/ct-react-vite/src/components/Fetcher.spec.tsx
+++ /dev/null
@@ -1,8 +0,0 @@
-import { test, expect } from '@playwright/test';
-
-// Network mocking is standard Playwright routing — set the route before mounting.
-test('mock a fetch with page.route', async ({ mount, page }) => {
- await page.route('**/data.json', route => route.fulfill({ json: { name: 'John Doe' } }));
- const component = await mount('components/Fetcher/Default');
- await expect(component.getByTestId('name')).toHaveText('John Doe');
-});
diff --git a/examples/ct-react-vite/src/components/Fetcher.story.tsx b/examples/ct-react-vite/src/components/Fetcher.story.tsx
deleted file mode 100644
index 8613c48ed3..0000000000
--- a/examples/ct-react-vite/src/components/Fetcher.story.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-import Fetcher from './Fetcher';
-
-export const Default = () => <Fetcher />;
diff --git a/examples/ct-react-vite/src/components/Fetcher.tsx b/examples/ct-react-vite/src/components/Fetcher.tsx
deleted file mode 100644
index 2f1322d148..0000000000
--- a/examples/ct-react-vite/src/components/Fetcher.tsx
+++ /dev/null
@@ -1,32 +0,0 @@
-import { useEffect, useState } from "react"
-
-export default function Fetcher() {
- const [data, setData] = useState<{ name: string }>({ name: '<none>' });
- const [fetched, setFetched] = useState(false);
-
- useEffect(() => {
- const doFetch = async () => {
- try {
- const response = await fetch('/data.json');
- setData(await response.json());
- } catch {
- setData({ name: '<error>' });
- }
- setFetched(true);
- }
-
- if (!fetched)
- doFetch();
- }, [fetched, setFetched, setData]);
-
- return <div>
- <div data-testid='name'>{data.name}</div>
- <button onClick={() => {
- setFetched(false);
- setData({ name: '<none>' });
- }}>Reset</button>
- <button onClick={() => {
- fetch('/post', { method: 'POST', body: 'hello from the page' });
- }}>Post it</button>
- </div>;
-}
diff --git a/examples/ct-react-vite/src/components/MultiRoot.spec.tsx b/examples/ct-react-vite/src/components/MultiRoot.spec.tsx
deleted file mode 100644
index 61705e0fa2..0000000000
--- a/examples/ct-react-vite/src/components/MultiRoot.spec.tsx
+++ /dev/null
@@ -1,15 +0,0 @@
-import { test, expect } from '@playwright/test';
-
-test('render a multi-root component', async ({ mount, page }) => {
- await mount('components/MultiRoot/Default');
- await expect(page.locator('#root')).toContainText('root 1');
- await expect(page.locator('#root')).toContainText('root 2');
-});
-
-test('unmount a multi-root component', async ({ mount, page }) => {
- const component = await mount('components/MultiRoot/Default');
- await expect(page.locator('#root')).toContainText('root 1');
- await expect(page.locator('#root')).toContainText('root 2');
- await component.unmount();
- await expect(page.locator('#root')).not.toContainText('root 1');
-});
diff --git a/examples/ct-react-vite/src/components/MultiRoot.story.tsx b/examples/ct-react-vite/src/components/MultiRoot.story.tsx
deleted file mode 100644
index 8defa20579..0000000000
--- a/examples/ct-react-vite/src/components/MultiRoot.story.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-import MultiRoot from './MultiRoot';
-
-export const Default = () => <MultiRoot />;
diff --git a/examples/ct-react-vite/src/components/MultiRoot.tsx b/examples/ct-react-vite/src/components/MultiRoot.tsx
deleted file mode 100644
index f29e397c0f..0000000000
--- a/examples/ct-react-vite/src/components/MultiRoot.tsx
+++ /dev/null
@@ -1,6 +0,0 @@
-export default function MultiRoot() {
- return <>
- <div>root 1</div>
- <div>root 2</div>
- </>
-}
diff --git a/examples/ct-react-vite/src/components/MultipleChildren.spec.tsx b/examples/ct-react-vite/src/components/MultipleChildren.spec.tsx
deleted file mode 100644
index e6ca55f961..0000000000
--- a/examples/ct-react-vite/src/components/MultipleChildren.spec.tsx
+++ /dev/null
@@ -1,8 +0,0 @@
-import { test, expect } from '@playwright/test';
-
-test('render named children', async ({ mount }) => {
- const component = await mount('components/MultipleChildren/Default');
- await expect(component).toContainText('Header');
- await expect(component).toContainText('Main Content');
- await expect(component).toContainText('Footer');
-});
diff --git a/examples/ct-react-vite/src/components/MultipleChildren.story.tsx b/examples/ct-react-vite/src/components/MultipleChildren.story.tsx
deleted file mode 100644
index 4ea9ac411a..0000000000
--- a/examples/ct-react-vite/src/components/MultipleChildren.story.tsx
+++ /dev/null
@@ -1,7 +0,0 @@
-import MultipleChildren from './MultipleChildren';
-
-export const Default = () => <MultipleChildren>
- <div>Header</div>
- <div>Main Content</div>
- <div>Footer</div>
-</MultipleChildren>;
diff --git a/examples/ct-react-vite/src/components/MultipleChildren.tsx b/examples/ct-react-vite/src/components/MultipleChildren.tsx
deleted file mode 100644
index 63bd0104c6..0000000000
--- a/examples/ct-react-vite/src/components/MultipleChildren.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-
-type MultipleChildrenProps = {
- children?: [any, any, any];
-}
-
-export default function MultipleChildren(props: MultipleChildrenProps) {
- return <div>
- <header>
- {props.children?.at(0)}
- </header>
- <main>
- {props.children?.at(1)}
- </main>
- <footer>
- {props.children?.at(2)}
- </footer>
-</div>
-}
diff --git a/examples/ct-react-vite/src/components/TitleWithFont.css b/examples/ct-react-vite/src/components/TitleWithFont.css
deleted file mode 100644
index 9fc7e0a7c0..0000000000
--- a/examples/ct-react-vite/src/components/TitleWithFont.css
+++ /dev/null
@@ -1,3 +0,0 @@
-.title-with-font {
- font-family: pwtest-iconfont, sans-serif;
-}
diff --git a/examples/ct-react-vite/src/components/TitleWithFont.spec.tsx b/examples/ct-react-vite/src/components/TitleWithFont.spec.tsx
deleted file mode 100644
index a5ea2761ff..0000000000
--- a/examples/ct-react-vite/src/components/TitleWithFont.spec.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-import { test, expect } from '@playwright/test';
-
-// The gallery imports the app's global CSS, so the story's @font-face triggers a real font load.
-test('load a web font', async ({ mount, page }) => {
- const promise = page.waitForEvent('requestfinished', r => r.url().includes('iconfont'));
- await mount('components/TitleWithFont/Default');
- const request = await promise;
- const response = await request.response();
- const body = await response!.body();
- expect(body.length).toBe(348);
-});
diff --git a/examples/ct-react-vite/src/components/TitleWithFont.story.tsx b/examples/ct-react-vite/src/components/TitleWithFont.story.tsx
deleted file mode 100644
index b684d31300..0000000000
--- a/examples/ct-react-vite/src/components/TitleWithFont.story.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-import TitleWithFont from './TitleWithFont';
-
-export const Default = () => <TitleWithFont />;
diff --git a/examples/ct-react-vite/src/components/TitleWithFont.tsx b/examples/ct-react-vite/src/components/TitleWithFont.tsx
deleted file mode 100644
index ad783205c3..0000000000
--- a/examples/ct-react-vite/src/components/TitleWithFont.tsx
+++ /dev/null
@@ -1,5 +0,0 @@
-import './TitleWithFont.css';
-
-export default function TitleWithFont() {
- return <div className='title-with-font'>+-</div>
-}
diff --git a/examples/ct-react-vite/src/main.tsx b/examples/ct-react-vite/src/main.tsx
deleted file mode 100644
index f3fe4a896d..0000000000
--- a/examples/ct-react-vite/src/main.tsx
+++ /dev/null
@@ -1,13 +0,0 @@
-import * as React from 'react';
-import { createRoot } from 'react-dom/client';
-import { BrowserRouter } from 'react-router-dom';
-import App from './App';
-import './assets/index.css';
-
-createRoot(document.getElementById("root")!).render(
- <React.StrictMode>
- <BrowserRouter>
- <App />
- </BrowserRouter>
- </React.StrictMode>
-);
diff --git a/examples/ct-react-vite/src/pages/DashboardPage.tsx b/examples/ct-react-vite/src/pages/DashboardPage.tsx
deleted file mode 100644
index 64307e87f3..0000000000
--- a/examples/ct-react-vite/src/pages/DashboardPage.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-export default function DashboardPage() {
- return <main>Dashboard</main>
-}
diff --git a/examples/ct-react-vite/src/pages/LoginPage.tsx b/examples/ct-react-vite/src/pages/LoginPage.tsx
deleted file mode 100644
index 96adc431ed..0000000000
--- a/examples/ct-react-vite/src/pages/LoginPage.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-export default function LoginPage() {
- return <main>Login</main>
-}
diff --git a/examples/ct-react-vite/src/vite-env.d.ts b/examples/ct-react-vite/src/vite-env.d.ts
deleted file mode 100644
index 11f02fe2a0..0000000000
--- a/examples/ct-react-vite/src/vite-env.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-/// <reference types="vite/client" />
diff --git a/examples/ct-react-vite/tsconfig.json b/examples/ct-react-vite/tsconfig.json
deleted file mode 100644
index c84ccd8aca..0000000000
--- a/examples/ct-react-vite/tsconfig.json
+++ /dev/null
@@ -1,18 +0,0 @@
-{
- "compilerOptions": {
- "target": "ESNext",
- "useDefineForClassFields": true,
- "lib": ["DOM", "DOM.Iterable", "ESNext"],
- "skipLibCheck": true,
- "allowSyntheticDefaultImports": true,
- "strict": true,
- "module": "ESNext",
- "moduleResolution": "Bundler",
- "resolveJsonModule": true,
- "isolatedModules": true,
- "noEmit": true,
- "jsx": "react-jsx",
- "types": ["vite/client"]
- },
- "include": ["src", "playwright"]
-}
diff --git a/examples/ct-react-vite/vite.config.ts b/examples/ct-react-vite/vite.config.ts
deleted file mode 100644
index b1b5f91e5f..0000000000
--- a/examples/ct-react-vite/vite.config.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-import { defineConfig } from 'vite'
-import react from '@vitejs/plugin-react'
-
-// https://vitejs.dev/config/
-export default defineConfig({
- plugins: [react()]
-})
diff --git a/package.json b/package.json
index cd2015d4fa..ac8a8bfebb 100644
--- a/package.json
+++ b/package.json
@@ -25,6 +25,8 @@
"itest": "playwright test --config=tests/installation/playwright.config.ts",
"stest": "playwright test --config=tests/stress/playwright.config.ts",
"biditest": "playwright test --config=tests/bidi/playwright.config.ts",
+ "test-html-reporter": "playwright test --config=packages/html-reporter",
+ "test-web": "playwright test --config=packages/web",
"ttest": "node ./tests/playwright-test/stable-test-runner/node_modules/@playwright/test/cli test --config=tests/playwright-test/playwright.config.ts",
"ct": "playwright test tests/components/test-all.spec.js --reporter=list",
"test": "playwright test --config=tests/library/playwright.config.ts",
diff --git a/packages/html-reporter/playwright.config.ts b/packages/html-reporter/playwright.config.ts
new file mode 100644
index 0000000000..d15ded9a00
--- /dev/null
+++ b/packages/html-reporter/playwright.config.ts
@@ -0,0 +1,53 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import path from 'path';
+import url from 'url';
+import { devices, defineConfig } from '@playwright/test';
+
+const dirname = path.dirname(url.fileURLToPath(import.meta.url));
+const outputDir = path.join(dirname, '..', '..', 'test-results');
+
+export default defineConfig({
+ testDir: 'src',
+ outputDir,
+ forbidOnly: !!process.env.CI,
+ retries: process.env.CI ? 2 : 0,
+ reporter: process.env.CI ? [
+ ['dot'],
+ ['json', { outputFile: path.join(outputDir, 'report.json') }],
+ ['blob', { outputDir: path.join(dirname, '..', '..', 'blob-report') }],
+ ['../../tests/config/parquetReporter.ts'],
+ ] : [
+ ['html', { open: 'on-failure' }]
+ ],
+ tag: process.env.PW_TAG,
+ use: {
+ baseURL: 'http://localhost:3101/playwright/gallery/index.html',
+ serviceWorkers: 'block',
+ reuseContext: true,
+ trace: 'on-first-retry',
+ },
+ projects: [{
+ name: 'chromium',
+ use: { ...devices['Desktop Chrome'] },
+ }],
+ webServer: {
+ command: 'npx vite --port 3101 --strictPort',
+ url: 'http://localhost:3101/playwright/gallery/index.html',
+ reuseExistingServer: !process.env.CI,
+ },
+});
diff --git a/packages/html-reporter/playwright/gallery/index.html b/packages/html-reporter/playwright/gallery/index.html
new file mode 100644
index 0000000000..0842528ca8
--- /dev/null
+++ b/packages/html-reporter/playwright/gallery/index.html
@@ -0,0 +1,32 @@
+<!--
+ Copyright (c) Microsoft Corporation.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <title>Component Gallery</title>
+ <style>
+ html, body { margin: 0; padding: 0; }
+ #root { position: fixed; inset: 0; }
+ </style>
+ </head>
+ <body>
+ <div id="root"></div>
+ <script type="module" src="./main.tsx"></script>
+ </body>
+</html>
diff --git a/packages/html-reporter/playwright/gallery/main.tsx b/packages/html-reporter/playwright/gallery/main.tsx
new file mode 100644
index 0000000000..38120efe0c
--- /dev/null
+++ b/packages/html-reporter/playwright/gallery/main.tsx
@@ -0,0 +1,48 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { flushSync } from 'react-dom';
+import { createRoot, type Root } from 'react-dom/client';
+import '../../src/theme.css';
+
+const stories = import.meta.glob('../../src/**/*.story.{tsx,jsx}');
+const storyId = (file: string) => file.replace(/^(\.\.\/)+src\//, '').replace(/\.story\.\w+$/, '');
+
+async function resolveStory(id: string): Promise<React.ComponentType<any> | undefined> {
+ const sep = id.lastIndexOf('/');
+ const [path, name] = [id.slice(0, sep), id.slice(sep + 1)];
+ const file = Object.keys(stories).find(f => storyId(f) === path || storyId(f).endsWith('/' + path));
+ const mod = (file && await stories[file]()) as Record<string, any> | undefined;
+ return mod?.[name] ?? mod?.default;
+}
+
+const rootElement = document.getElementById('root')!;
+let root: Root | undefined;
+
+(window as any).mount = async ({ story, props }: { story: string, props?: Record<string, any> }) => {
+ const Story = await resolveStory(story);
+ if (!Story)
+ throw new Error(`Unknown story: ${story}`);
+ // Reuse the root so that update() reconciles and preserves state.
+ root ??= createRoot(rootElement);
+ // flushSync so that a render error rejects the promise instead of being swallowed.
+ flushSync(() => root!.render(<Story {...props} />));
+};
+
+(window as any).unmount = async () => {
+ root?.unmount();
+ root = undefined;
+};
diff --git a/packages/html-reporter/src/DEPS.list b/packages/html-reporter/src/DEPS.list
index 058dd4d82b..87831ba08b 100644
--- a/packages/html-reporter/src/DEPS.list
+++ b/packages/html-reporter/src/DEPS.list
@@ -2,14 +2,11 @@
@web/**
@isomorphic/**
-[chip.spec.tsx]
+[chip.spec.ts]
***
-[headerView.spec.tsx]
+[headerView.spec.ts]
***
-[imageDiffView.spec.tsx]
-***
-
-[testCaseView.spec.tsx]
+[testCaseView.spec.ts]
***
diff --git a/packages/html-reporter/src/chip.spec.ts b/packages/html-reporter/src/chip.spec.ts
new file mode 100644
index 0000000000..770ce94722
--- /dev/null
+++ b/packages/html-reporter/src/chip.spec.ts
@@ -0,0 +1,58 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { expect, test } from '@playwright/test';
+
+test.use({ viewport: { width: 500, height: 500 } });
+
+test('expand collapse', async ({ mount }) => {
+ const component = await mount('chip/Auto');
+ await expect(component.getByText('Chip body')).toBeVisible();
+ await component.getByText('Title').click();
+ await expect(component.getByText('Chip body')).not.toBeVisible();
+ await component.getByText('Title').click();
+ await expect(component.getByText('Chip body')).toBeVisible();
+});
+
+test('render long title', async ({ mount }) => {
+ const title = 'Extremely long title. '.repeat(10);
+ const component = await mount('chip/Auto', { header: title });
+ await expect(component).toContainText('Extremely long title.');
+ await expect(component.getByText('Extremely long title.')).toHaveAttribute('title', title);
+});
+
+test('setExpanded is called', async ({ mount }) => {
+ const component = await mount('chip/Stateful');
+ await component.getByText('Title').click();
+ await expect(component.getByTestId('expanded')).toHaveValue('true');
+ await component.getByText('Title').click();
+ await expect(component.getByTestId('expanded')).toHaveValue('false');
+});
+
+test('body render prop is rendered', async ({ mount }) => {
+ const component = await mount('chip/WithBody');
+ await expect(component.getByText('Body from render prop')).toBeVisible();
+ await expect(component.getByText('Chip children')).toBeVisible();
+});
+
+test('setExpanded should work', async ({ mount }) => {
+ const component = await mount('chip/AutoCollapsed');
+ await component.getByText('Title').click();
+ await expect(component).toMatchAriaSnapshot(`
+ - button "Title" [expanded]
+ - region: Body
+ `);
+});
diff --git a/packages/html-reporter/src/chip.story.tsx b/packages/html-reporter/src/chip.story.tsx
new file mode 100644
index 0000000000..5945cfdb45
--- /dev/null
+++ b/packages/html-reporter/src/chip.story.tsx
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import * as React from 'react';
+import { AutoChip, Chip } from './chip';
+
+export const Auto = ({ header }: { header?: string }) =>
+ <AutoChip header={header ?? 'title'}>Chip body</AutoChip>;
+
+export const AutoCollapsed = () =>
+ <AutoChip header='Title' initialExpanded={false}>Body</AutoChip>;
+
+export const Stateful = () => {
+ const [expanded, setExpanded] = React.useState(false);
+ return <>
+ <Chip header='Title' expanded={expanded} setExpanded={setExpanded}></Chip>
+ <form hidden><input data-testid='expanded' readOnly value={String(expanded)} /></form>
+ </>;
+};
+
+export const WithBody = () =>
+ <AutoChip header='Title' body={() => 'Body from render prop'}>Chip children</AutoChip>;
diff --git a/packages/html-reporter/src/headerView.spec.ts b/packages/html-reporter/src/headerView.spec.ts
new file mode 100644
index 0000000000..67262ab994
--- /dev/null
+++ b/packages/html-reporter/src/headerView.spec.ts
@@ -0,0 +1,57 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { expect, test } from '@playwright/test';
+
+test.use({ viewport: { width: 720, height: 200 } });
+
+test('should render counters', async ({ mount }) => {
+ const component = await mount('headerView/Default');
+ await expect(component.locator('a', { hasText: 'All' }).locator('.counter')).toHaveText('90');
+ await expect(component.locator('a', { hasText: 'Passed' }).locator('.counter')).toHaveText('42');
+ await expect(component.locator('a', { hasText: 'Failed' }).locator('.counter')).toHaveText('31');
+ await expect(component.locator('a', { hasText: 'Flaky' }).locator('.counter')).toHaveText('17');
+ await expect(component.locator('a', { hasText: 'Skipped' }).locator('.counter')).toHaveText('10');
+ await expect(component).toMatchAriaSnapshot(`
+ - navigation:
+ - link "All90"
+ - link "Passed42"
+ - link "Failed31"
+ - link "Flaky17"
+ - link "Skipped10"
+ `);
+});
+
+test('should toggle filters', async ({ page, mount }) => {
+ const component = await mount('headerView/Default');
+ const filterText = component.getByTestId('filter-text');
+ await component.locator('a', { hasText: 'All' }).click();
+ await expect(filterText).toHaveValue('');
+ await component.locator('a', { hasText: 'Passed' }).click();
+ await expect(page).toHaveURL(/#\?q=s(:|%3A)passed/);
+ await expect(filterText).toHaveValue('s:passed ');
+ await component.locator('a', { hasText: 'Failed' }).click();
+ await expect(page).toHaveURL(/#\?q=s(:|%3A)failed/);
+ await expect(filterText).toHaveValue('s:failed ');
+ await component.locator('a', { hasText: 'Flaky' }).click();
+ await expect(page).toHaveURL(/#\?q=s(:|%3A)flaky/);
+ await expect(filterText).toHaveValue('s:flaky ');
+ await component.locator('a', { hasText: 'Skipped' }).click();
+ await expect(page).toHaveURL(/#\?q=s(:|%3A)skipped/);
+ await expect(filterText).toHaveValue('s:skipped ');
+ await component.getByRole('textbox').fill('annot:annotation type=annotation description');
+ await expect(filterText).toHaveValue('annot:annotation type=annotation description');
+});
diff --git a/packages/html-reporter/src/headerView.story.tsx b/packages/html-reporter/src/headerView.story.tsx
new file mode 100644
index 0000000000..d4c61c327b
--- /dev/null
+++ b/packages/html-reporter/src/headerView.story.tsx
@@ -0,0 +1,36 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import * as React from 'react';
+import { GlobalFilterView } from './headerView';
+import { SearchParamsProvider } from './links';
+
+const stats = {
+ total: 100,
+ expected: 42,
+ unexpected: 31,
+ flaky: 17,
+ skipped: 10,
+ ok: false,
+};
+
+export const Default = () => {
+ const [filterText, setFilterText] = React.useState('');
+ return <SearchParamsProvider>
+ <GlobalFilterView stats={stats} filterText={filterText} setFilterText={setFilterText} />
+ <form hidden><input data-testid='filter-text' readOnly value={filterText} /></form>
+ </SearchParamsProvider>;
+};
diff --git a/packages/html-reporter/src/testCaseView.spec.ts b/packages/html-reporter/src/testCaseView.spec.ts
new file mode 100644
index 0000000000..c9656d7c1d
--- /dev/null
+++ b/packages/html-reporter/src/testCaseView.spec.ts
@@ -0,0 +1,117 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { expect, test } from '@playwright/test';
+
+test.use({ viewport: { width: 800, height: 600 } });
+
+test('should render test case', async ({ mount }) => {
+ const component = await mount('testCaseView/Default');
+ await expect(component.getByText('Annotation text', { exact: false }).first()).toBeVisible();
+ await expect(component.getByText('Hidden annotation')).toBeHidden();
+ await component.getByText('Annotations').click();
+ await expect(component.getByText('Annotation text')).not.toBeVisible();
+ await expect(component.getByText('Outer step')).toBeVisible();
+ await expect(component.getByText('Inner step')).not.toBeVisible();
+ await component.getByText('Outer step').click();
+ await expect(component.getByText('Inner step')).toBeVisible();
+ await expect(component.getByText('test.spec.ts:42')).toBeVisible();
+ await expect(component.getByText('My test')).toBeVisible();
+});
+
+test('should render copy buttons for annotations', async ({ mount, page, context }) => {
+ await context.grantPermissions(['clipboard-read', 'clipboard-write']);
+
+ const component = await mount('testCaseView/Default');
+ await expect(component.getByText('Annotation text', { exact: false }).first()).toBeVisible();
+ await component.getByText('Annotation text', { exact: false }).first().hover();
+ await expect(component.locator('.test-case-annotation').getByLabel('Copy to clipboard').first()).toBeVisible();
+ await component.locator('.test-case-annotation').getByLabel('Copy to clipboard').first().click();
+ const handle = await page.evaluateHandle(() => navigator.clipboard.readText());
+ const clipboardContent = await handle.jsonValue();
+ expect(clipboardContent).toBe('Annotation text');
+});
+
+test('should correctly render links in annotations', async ({ mount }) => {
+ const component = await mount('testCaseView/AnnotationLinks');
+
+ const firstLink = component.getByText('https://playwright.dev/docs/intro').first();
+ await expect(firstLink).toBeVisible();
+ await expect(firstLink).toHaveAttribute('href', 'https://playwright.dev/docs/intro');
+
+ const secondLink = component.getByText('https://playwright.dev/docs/api/class-playwright').first();
+ await expect(secondLink).toBeVisible();
+ await expect(secondLink).toHaveAttribute('href', 'https://playwright.dev/docs/api/class-playwright');
+
+ const thirdLink = component.getByText('https://github.com/microsoft/playwright/issues/23180').first();
+ await expect(thirdLink).toBeVisible();
+ await expect(thirdLink).toHaveAttribute('href', 'https://github.com/microsoft/playwright/issues/23180');
+
+ const fourthLink = component.getByText('https://github.com/microsoft/playwright/issues/23181').first();
+ await expect(fourthLink).toBeVisible();
+ await expect(fourthLink).toHaveAttribute('href', 'https://github.com/microsoft/playwright/issues/23181');
+});
+
+test('should correctly render links in attachments', async ({ mount }) => {
+ const component = await mount('testCaseView/AttachmentLinks');
+ await component.getByText('first attachment').click();
+ const body = component.getByText('The body with https://playwright.dev/docs/intro link');
+ await expect(body).toBeVisible();
+ await expect(body.locator('a').filter({ hasText: 'playwright.dev' })).toHaveAttribute('href', 'https://playwright.dev/docs/intro');
+ await expect(body.locator('a').filter({ hasText: 'github.com' })).toHaveAttribute('href', 'https://github.com/microsoft/playwright/issues/31284');
+ await expect(component).toMatchAriaSnapshot(`
+ - link "https://playwright.dev/docs/intro"
+ - link "https://github.com/microsoft/playwright/issues/31284"
+ `);
+});
+
+test('should correctly render links in attachment name', async ({ mount }) => {
+ const component = await mount('testCaseView/AttachmentLinks');
+ const link = component.getByText('attachment with inline link').locator('a');
+ await expect(link).toHaveAttribute('href', 'https://github.com/microsoft/playwright/issues/31284');
+ await expect(link).toHaveText('https://github.com/microsoft/playwright/issues/31284');
+ await expect(component).toMatchAriaSnapshot(`
+ - link /https:\\/\\/github\\.com\\/microsoft\\/playwright\\/issues\\/\\d+/
+ `);
+});
+
+test('should correctly render prev and next', async ({ mount }) => {
+ const component = await mount('testCaseView/PrevNext');
+ await expect(component).toMatchAriaSnapshot(`
+ - text: group
+ - link "« previous"
+ - link "next »"
+ - text: "My test test.spec.ts:42 10ms chromium"
+ `);
+});
+
+test('total duration is selected run duration', async ({ mount, page }) => {
+ const component = await mount('testCaseView/TwoAttempts');
+ await expect(component).toMatchAriaSnapshot(`
+ - text: "My test test.spec.ts:42 200ms chromium"
+ - tablist:
+ - tab "Run 50ms"
+ - 'tab "Retry #1 150ms"'
+ `);
+ await page.getByRole('tab', { name: 'Run' }).click();
+ await expect(component).toMatchAriaSnapshot(`
+ - text: "My test test.spec.ts:42 200ms chromium"
+ `);
+ await page.getByRole('tab', { name: 'Retry' }).click();
+ await expect(component).toMatchAriaSnapshot(`
+ - text: "My test test.spec.ts:42 200ms chromium"
+ `);
+});
diff --git a/packages/html-reporter/src/testCaseView.story.tsx b/packages/html-reporter/src/testCaseView.story.tsx
new file mode 100644
index 0000000000..ba2f9066c5
--- /dev/null
+++ b/packages/html-reporter/src/testCaseView.story.tsx
@@ -0,0 +1,152 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { LoadedReport } from './loadedReport';
+import { TestCaseView } from './testCaseView';
+import type { HTMLReport, TestCase, TestCaseSummary, TestResult } from './types';
+
+const report: LoadedReport = {
+ json: () => ({ projectNames: ['chromium', 'webkit'] } as HTMLReport),
+ entry: async () => undefined,
+};
+
+const result: TestResult = {
+ retry: 0,
+ workerIndex: 0,
+ startTime: new Date(0).toUTCString(),
+ duration: 100,
+ errors: [],
+ steps: [{
+ title: 'Outer step',
+ startTime: new Date(100).toUTCString(),
+ duration: 10,
+ location: { file: 'test.spec.ts', line: 62, column: 0 },
+ count: 1,
+ steps: [{
+ title: 'Inner step',
+ startTime: new Date(200).toUTCString(),
+ duration: 10,
+ location: { file: 'test.spec.ts', line: 82, column: 0 },
+ steps: [],
+ attachments: [],
+ count: 1,
+ }],
+ attachments: [],
+ }],
+ annotations: [
+ { type: 'annotation', description: 'Annotation text' },
+ { type: 'annotation', description: 'Another annotation text' },
+ { type: '_annotation', description: 'Hidden annotation' },
+ ],
+ attachments: [],
+ status: 'passed',
+};
+
+const testCase: TestCase = {
+ testId: 'testid',
+ title: 'My test',
+ path: [],
+ projectName: 'chromium',
+ location: { file: 'test.spec.ts', line: 42, column: 0 },
+ annotations: result.annotations,
+ tags: [],
+ outcome: 'expected',
+ duration: 200,
+ ok: true,
+ results: [result]
+};
+
+const annotationLinkRenderingTestCase: TestCase = {
+ ...testCase,
+ duration: 10,
+ annotations: [],
+ results: [{
+ ...result,
+ annotations: [
+ { type: 'more info', description: 'read https://playwright.dev/docs/intro and https://playwright.dev/docs/api/class-playwright' },
+ { type: 'related issues', description: 'https://github.com/microsoft/playwright/issues/23180, https://github.com/microsoft/playwright/issues/23181' },
+ ]
+ }]
+};
+
+const resultWithAttachment: TestResult = {
+ ...result,
+ steps: [{
+ title: 'Outer step',
+ startTime: new Date(100).toUTCString(),
+ duration: 10,
+ location: { file: 'test.spec.ts', line: 62, column: 0 },
+ count: 1,
+ steps: [],
+ attachments: [1],
+ }],
+ attachments: [{
+ name: 'first attachment',
+ body: 'The body with https://playwright.dev/docs/intro link and https://github.com/microsoft/playwright/issues/31284.',
+ contentType: 'text/plain'
+ }, {
+ name: 'attachment with inline link https://github.com/microsoft/playwright/issues/31284',
+ contentType: 'text/plain'
+ }],
+ annotations: [],
+};
+
+const attachmentLinkRenderingTestCase: TestCase = {
+ ...testCase,
+ path: ['group'],
+ duration: 10,
+ annotations: [],
+ results: [resultWithAttachment]
+};
+
+const testCaseSummary: TestCaseSummary = {
+ ...attachmentLinkRenderingTestCase,
+ testId: 'nextTestId',
+ title: 'next test',
+ path: [],
+};
+
+const testCaseWithTwoAttempts: TestCase = {
+ ...testCase,
+ results: [
+ {
+ ...result,
+ errors: [{ message: 'Error message' }],
+ status: 'failed',
+ duration: 50,
+ },
+ {
+ ...result,
+ duration: 150,
+ status: 'passed',
+ },
+ ],
+};
+
+export const Default = () =>
+ <TestCaseView report={report} test={testCase} prev={undefined} next={undefined} run={0} />;
+
+export const AnnotationLinks = () =>
+ <TestCaseView report={report} test={annotationLinkRenderingTestCase} prev={undefined} next={undefined} run={0} />;
+
+export const AttachmentLinks = () =>
+ <TestCaseView report={report} test={attachmentLinkRenderingTestCase} prev={undefined} next={undefined} run={0} />;
+
+export const PrevNext = () =>
+ <TestCaseView report={report} test={attachmentLinkRenderingTestCase} prev={testCaseSummary} next={testCaseSummary} run={0} />;
+
+export const TwoAttempts = () =>
+ <TestCaseView report={report} test={testCaseWithTwoAttempts} prev={undefined} next={undefined} run={0} />;
diff --git a/packages/playwright-core/src/tools/skills/playwright-component-testing/SKILL.md b/packages/playwright-core/src/tools/skills/playwright-component-testing/SKILL.md
index 54e8bc218e..a475aefbf2 100644
--- a/packages/playwright-core/src/tools/skills/playwright-component-testing/SKILL.md
+++ b/packages/playwright-core/src/tools/skills/playwright-component-testing/SKILL.md
@@ -11,9 +11,9 @@ Test components with regular Playwright e2e tests against a small **story galler
- A **story** is a tiny wrapper component that embeds the component under test in one specific scenario: hard-coded props, mock data, providers, recorded callbacks. Stories live next to the component in `*.story.tsx` (or `.ts`/`.jsx`/`.js`/`.vue`) files; each named export is one story.
- The **gallery** is a single page you implement to `references/gallery-spec.md`: it exposes `window.mount(params)` / `window.unmount()` that render a story — resolved from your story files (e.g. with `import.meta.glob`) — into `#root`. It is framework-specific and yours to own — there is no template to copy for it.
-- Tests are plain Playwright tests. The built-in **`mount(storyId, props?)` fixture** (from `@playwright/test`) drives the gallery's `window.mount` and returns a `Locator` for the mounted component (the single element rendered into `#root`, or `#root` itself when the story renders a fragment) — so specs read just like the old component tests. Nothing to scaffold for it.
+- Tests are plain Playwright tests. The built-in **`mount(storyId, props?)` fixture** (from `@playwright/test`) drives the gallery's `window.mount` and returns a `Locator` for the gallery root (`#root`). Scope the queries from there — `component.getByRole('button').click()`, not `component.click()`. Nothing to scaffold for it.
-Everything the component needs must be set up *inside the story* (it runs in the browser); everything the test asserts must be observable *through the page* (DOM, URL, network). `mount(id, props)` passes `props` to the component, and props may include **callbacks** — the component calls them in the browser and your test-side function runs in Node.
+Everything the component needs must be set up *inside the story* (it runs in the browser); everything the test asserts must be observable *through the page* (DOM, URL, network). Where the component takes callbacks, the story creates the state, provides the callbacks and records the state into a hidden form for the test to assert on. `mount(id, props)` passes plain serializable `props` to the story.
## Setup workflow
@@ -54,38 +54,31 @@ Examples are React; the Vue equivalents differ only in story syntax.
### Callbacks and events
-**Pass the callback straight to `mount`** — it runs in Node, so you assert directly on what the component called it with:
-
-```ts
-test('fires onSubmit with the form data', async ({ mount }) => {
- const calls: any[] = [];
- const component = await mount('components/Form/Default', { onSubmit: (data: any) => calls.push(data) });
- await component.getByRole('button', { name: 'Save' }).click();
- expect(calls).toEqual([{ name: 'Ada' }]);
-});
-```
-
-Callbacks may be async and return a value the component `await`s — the return travels back from Node:
-
-```ts
-await mount('components/Field/Default', { validate: async (v: string) => v.length > 0 });
-```
-
-**Or record the effect in the DOM** inside the story — handy when you also want the state visible when eyeballing the gallery:
+**The story owns the state and provides the callbacks.** Where the component takes callbacks, create the state inside the story, wire the callbacks to it, and record the state into a hidden form next to the component. Tests perform operations and assert on the recorded values:
```tsx
-export const CountsClicks = () => {
- const [clicks, setClicks] = useState(0);
+export const Stateful = () => {
+ const [expanded, setExpanded] = useState(false);
return <>
- <Button title="Submit" onClick={() => setClicks(c => c + 1)} />
- <output data-testid="click-count">{clicks}</output>
+ <Expandable expanded={expanded} setExpanded={setExpanded} title="Title">Details</Expandable>
+ <form hidden><input data-testid="expanded" readOnly value={String(expanded)} /></form>
</>;
};
```
+```ts
+test('click should expand', async ({ mount }) => {
+ const component = await mount('components/Expandable/Stateful');
+ await component.locator('.codicon-chevron-right').click();
+ await expect(component.getByTestId('expanded')).toHaveValue('true');
+});
+```
+
+This keeps the whole scenario in the browser: no callback marshalling, the story doubles as documentation, and the recorded state is visible when eyeballing the gallery. Record each observed value in its own `data-testid` input (`String(...)` or `JSON.stringify(...)` for payloads) and assert with `toHaveValue()` — a web-first assertion that retries until the state lands. The negative direction works the same way: perform the operation, then assert the value did **not** change.
+
### Per-test props
-When a scenario is genuinely parametric (e.g. a boundary-value sweep), pass props as the second argument to `mount`; the gallery hands them to the story as its props. Props may include functions.
+When a scenario is genuinely parametric (e.g. a boundary-value sweep), pass props as the second argument to `mount`; the gallery hands them to the story as its props. Keep props to plain serializable data — callbacks belong inside the story.
```tsx
export const WithTitle = ({ title = 'Default' }: { title?: string }) =>
@@ -118,7 +111,7 @@ await expect(await mount('Button/Primary')).toHaveScreenshot('primary.png');
await expect(await mount('Button/Disabled')).toHaveScreenshot('disabled.png');
```
-For visual comparison, screenshot the component locator (as above), not the page, to avoid asserting on gallery chrome.
+For visual comparison, screenshot the returned root locator (as above), not the page, to avoid asserting on browser chrome.
### Network mocking
diff --git a/packages/playwright-core/src/tools/skills/playwright-component-testing/references/gallery-spec.md b/packages/playwright-core/src/tools/skills/playwright-component-testing/references/gallery-spec.md
index 315b854063..1aa7c996bf 100644
--- a/packages/playwright-core/src/tools/skills/playwright-component-testing/references/gallery-spec.md
+++ b/packages/playwright-core/src/tools/skills/playwright-component-testing/references/gallery-spec.md
@@ -7,18 +7,16 @@ Playwright config, that exposes two methods on `window` for Playwright to drive:
- `window.unmount()` — unmount the current story.
The built-in `mount` fixture navigates to the gallery, then calls `window.mount` via
-`page.evaluate(fn, params, { exposeFunctions: true })`. Because `exposeFunctions` turns functions
-in the arguments into real, browser-callable functions, **props may include callbacks** — the
-component invokes them in the browser and your test-side function runs in Node (and can return a
-value back).
+`page.evaluate()`. Keep props to plain serializable data — where the component takes callbacks,
+the story creates the state, provides the callbacks and records the state into a hidden form for
+the test to assert on.
## `window.mount(params)`
`params` is `{ story, props }`, straight from the test's `mount(story, props)` call:
- `story` — the story id (string). Resolve it (see id grammar) to a component.
-- `props` — the props object passed to the component. May contain **functions**; they are real
- callbacks, not data — call them and, if you like, `await` their result.
+- `props` — the plain serializable props object passed to the component.
Render the resolved component with `props` into `#root`. Return a `Promise` that resolves once the
component is mounted and **rejects on failure** (unknown story, render throw). The rejection
@@ -46,12 +44,10 @@ fresh, so tests are already isolated.
## `#root`
-Render the component into an element with `id="root"`. `mount` returns a `Locator` for the mounted
-component itself — the single element child of `#root` — so `component.click()` and
-`expect(component).toHaveClass(...)` target the component. When
-the story renders a fragment (several top-level elements, e.g. the component plus an `<output>`
-recording events), the locator falls back to `#root`; tests then scope their queries
-(`component.getByRole('button')`).
+Render the component into an element with `id="root"`. `mount` returns a `Locator` for `#root`
+itself, so tests scope their queries from there — `component.getByRole('button').click()`, not
+`component.click()`. Stories are free to render fragments, e.g. the component plus a hidden form
+recording its state.
## Story id grammar (recommended)
@@ -144,6 +140,5 @@ let app: App | undefined;
};
```
-A callback prop just arrives as a function — `props.onSave?.(data)` inside the component runs the
-test's callback. Keep the story-resolution glob and the framework mount in this file; everything
+Keep the story-resolution glob and the framework mount in this file; everything
else lives in your stories and tests.
diff --git a/packages/playwright-core/src/tools/skills/playwright-component-testing/references/migration.md b/packages/playwright-core/src/tools/skills/playwright-component-testing/references/migration.md
index 326f428d9a..13eb9ec768 100644
--- a/packages/playwright-core/src/tools/skills/playwright-component-testing/references/migration.md
+++ b/packages/playwright-core/src/tools/skills/playwright-component-testing/references/migration.md
@@ -1,17 +1,17 @@
# Migrating from @playwright/experimental-ct-react / -vue
The CT packages compiled JSX in the test file and marshalled it into the browser. The gallery
-pattern splits that in two: **structure** (which component, its children, providers) moves into a
-story export that runs natively in the browser; **data and behavior** (props, callbacks) stay in
-the test and travel through `mount(storyId, props)`. Callbacks, `update()` and `unmount()` work as
-before, so most specs port mechanically.
+pattern moves the scenario into a story export that runs natively in the browser: structure (which
+component, its children, providers) plus behavior (state and callbacks, recorded into a hidden
+form for the test to assert on). Plain data props travel through `mount(storyId, props)`;
+`update()` and `unmount()` work as before.
## Concept mapping
| `@playwright/experimental-ct-*` | Gallery pattern |
|---|---|
-| `mount(<Button title="…" onClick={spy} />)` | Story export `Default = props => <Button title="…" {...props} />` + `mount('Button/Default', { onClick: spy })` |
-| Props / callback props from the test | Unchanged in spirit: `mount(id, props)` — functions cross and run in Node, may be async and return values |
+| `mount(<Button title="…" onClick={spy} />)` | Stateful story: the story provides `onClick`, records the effect into a hidden form input; the test asserts `toHaveValue()` |
+| Plain data props from the test | Unchanged in spirit: `mount(id, props)` |
| JSX children / slots from the test | Cannot cross — bake each composition into its own story export (Vue: `.story.vue` for slot-heavy scenarios) |
| `component.update(<Button count={2} />)` | `component.update({ count: 2 })` — state-preserving, needs the gallery to reuse its root (`gallery-spec.md`) |
| `component.unmount()` | `component.unmount()` — backed by the gallery's `window.unmount()` |
@@ -27,12 +27,15 @@ before, so most specs port mechanically.
1. Set up the gallery and config per `SKILL.md`. Keep the old CT project running until the last
spec is migrated.
2. For each CT spec, split every `mount(<…/>)` call: JSX structure becomes a story export next to
- the component; test-supplied props and callbacks stay in the test as `mount`'s second argument.
- A call site that only varies props/callbacks usually needs just one generic story that spreads
- them: `export const Default = (props: ButtonProps) => <Button title="Submit" {...props} />`.
-3. Rewrite the spec: import `test`/`expect` from `@playwright/test`; `mount(<X a={1} onB={spy}/>)`
- → `mount('X/Default', { a: 1, onB: spy })`; `update(<X a={2}/>)` → `update({ a: 2 })`;
- `unmount()` unchanged. Callback spies and their assertions survive verbatim.
+ the component; plain data props stay in the test as `mount`'s second argument. Callback spies
+ become story state recorded into a hidden form. A call site that only varies data props usually
+ needs just one generic story that spreads them:
+ `export const Default = (props: ButtonProps) => <Button title="Submit" {...props} />`.
+3. Rewrite the spec: import `test`/`expect` from `@playwright/test`; `mount(<X a={1}/>)`
+ → `mount('X/Default', { a: 1 })`; `update(<X a={2}/>)` → `update({ a: 2 })`;
+ `unmount()` unchanged. `mount` returns a locator for the gallery root — scope the queries:
+ `component.getByRole('button').click()`. Spy assertions become `toHaveValue()` on the story's
+ recorded state.
4. Port `beforeMount` hooks: app-wide setup into the gallery's `window.mount`; per-test
`hooksConfig` branches into props interpreted by a story or decorator.
5. When all specs are green, delete the CT project from the config, drop the
diff --git a/packages/playwright-core/src/tools/skills/playwright-component-testing/references/vue.md b/packages/playwright-core/src/tools/skills/playwright-component-testing/references/vue.md
index 5243ac85da..4914f0e9af 100644
--- a/packages/playwright-core/src/tools/skills/playwright-component-testing/references/vue.md
+++ b/packages/playwright-core/src/tools/skills/playwright-component-testing/references/vue.md
@@ -22,7 +22,7 @@ const clicks = ref(0);
<template>
<Button title="Submit" @click="clicks++" />
- <output data-testid="click-count">{{ clicks }}</output>
+ <form hidden><input data-testid="click-count" readonly :value="String(clicks)" /></form>
</template>
```
diff --git a/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/react/Button.story.tsx b/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/react/Button.story.tsx
index 0df097ef8b..9d416a6e7c 100644
--- a/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/react/Button.story.tsx
+++ b/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/react/Button.story.tsx
@@ -1,7 +1,7 @@
// Example story file. Stories live next to the component they exercise:
// this file is src/components/Button.story.tsx for src/components/Button.tsx.
// Each named export is one story: a scenario-specific wrapper around the
-// component. Wire providers, mock data and event recording here, not in tests.
+// component. Wire providers, mock data, state and callbacks here, not in tests.
import { useState } from 'react';
import { Button } from './Button';
@@ -9,11 +9,12 @@ export const Primary = () => <Button title="Submit" />;
export const Disabled = () => <Button title="Submit" disabled />;
-// Callbacks are asserted through the DOM: record events into visible output.
+// The story owns the state and provides the callbacks. Record the state into
+// a hidden form for the test to assert on.
export const CountsClicks = () => {
const [clicks, setClicks] = useState(0);
return <>
<Button title="Submit" onClick={() => setClicks(count => count + 1)} />
- <output data-testid="click-count">{clicks}</output>
+ <form hidden><input data-testid="click-count" readOnly value={String(clicks)} /></form>
</>;
};
diff --git a/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/react/button.spec.ts b/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/react/button.spec.ts
index bcefdd2594..5fe64a5268 100644
--- a/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/react/button.spec.ts
+++ b/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/react/button.spec.ts
@@ -1,18 +1,19 @@
// Example component test. `mount` is a built-in fixture of @playwright/test.
+// It returns a locator for the gallery root, scope the queries from there.
import { test, expect } from '@playwright/test';
test('renders primary button', async ({ mount }) => {
const component = await mount('components/Button/Primary');
- await expect(component).toHaveText('Submit');
+ await expect(component.getByRole('button')).toHaveText('Submit');
});
test('disabled button is disabled', async ({ mount }) => {
const component = await mount('components/Button/Disabled');
- await expect(component).toBeDisabled();
+ await expect(component.getByRole('button')).toBeDisabled();
});
-test('button click fires callback', async ({ mount, page }) => {
+test('button click fires callback', async ({ mount }) => {
const component = await mount('components/Button/CountsClicks');
await component.getByRole('button').click();
- await expect(page.getByTestId('click-count')).toHaveText('1');
+ await expect(component.getByTestId('click-count')).toHaveValue('1');
});
diff --git a/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/vue/Button.story.ts b/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/vue/Button.story.ts
index e8f1e32f71..e2d4d371ed 100644
--- a/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/vue/Button.story.ts
+++ b/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/vue/Button.story.ts
@@ -1,7 +1,7 @@
// Example story file. Stories live next to the component they exercise:
// this file is src/components/Button.story.ts for src/components/Button.vue.
// Each named export is one story: a scenario-specific wrapper around the
-// component. Wire providers, mock data and event recording here, not in tests.
+// component. Wire providers, mock data, state and callbacks here, not in tests.
// Alternatively, write a story as a Button.<scenario>.story.vue single-file
// component — its default export is the story.
import { defineComponent, h, ref } from 'vue';
@@ -11,11 +11,14 @@ export const Primary = defineComponent(() => () => h(Button, { title: 'Submit' }
export const Disabled = defineComponent(() => () => h(Button, { title: 'Submit', disabled: true }));
-// Callbacks are asserted through the DOM: record events into visible output.
+// The story owns the state and provides the callbacks. Record the state into
+// a hidden form for the test to assert on.
export const CountsClicks = defineComponent(() => {
const clicks = ref(0);
return () => h('div', [
h(Button, { title: 'Submit', onClick: () => clicks.value++ }),
- h('output', { 'data-testid': 'click-count' }, String(clicks.value)),
+ h('form', { hidden: true }, [
+ h('input', { 'data-testid': 'click-count', readonly: true, value: String(clicks.value) }),
+ ]),
]);
});
diff --git a/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/vue/button.spec.ts b/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/vue/button.spec.ts
index bcefdd2594..5fe64a5268 100644
--- a/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/vue/button.spec.ts
+++ b/packages/playwright-core/src/tools/skills/playwright-component-testing/templates/vue/button.spec.ts
@@ -1,18 +1,19 @@
// Example component test. `mount` is a built-in fixture of @playwright/test.
+// It returns a locator for the gallery root, scope the queries from there.
import { test, expect } from '@playwright/test';
test('renders primary button', async ({ mount }) => {
const component = await mount('components/Button/Primary');
- await expect(component).toHaveText('Submit');
+ await expect(component.getByRole('button')).toHaveText('Submit');
});
test('disabled button is disabled', async ({ mount }) => {
const component = await mount('components/Button/Disabled');
- await expect(component).toBeDisabled();
+ await expect(component.getByRole('button')).toBeDisabled();
});
-test('button click fires callback', async ({ mount, page }) => {
+test('button click fires callback', async ({ mount }) => {
const component = await mount('components/Button/CountsClicks');
await component.getByRole('button').click();
- await expect(page.getByTestId('click-count')).toHaveText('1');
+ await expect(component.getByTestId('click-count')).toHaveValue('1');
});
diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.ts
index 7b2ba2575a..92fdc6c0f2 100644
--- a/packages/playwright/src/index.ts
+++ b/packages/playwright/src/index.ts
@@ -511,7 +511,8 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures, UtilityTestFixt
// The gallery is a single page (served at baseURL) that exposes window.mount()/window.unmount().
await page.goto(baseURL);
await callMount({ story: storyId, props });
- return Object.assign(page.locator('#root >> internal:control=component'), {
+ // Points at the gallery root, scope the queries: component.getByRole(...).
+ return Object.assign(page.locator('#root'), {
// update() re-renders the same story with new props without navigating; if the gallery
// reuses its root/instance, the framework reconciles and component state is preserved.
update: (newProps?: Record<string, any>) => callMount({ story: storyId, props: newProps }),
diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts
index 472c9e021a..0ed849a7ce 100644
--- a/packages/playwright/types/test.d.ts
+++ b/packages/playwright/types/test.d.ts
@@ -7866,7 +7866,8 @@ export interface PlaywrightTestArgs {
*/
request: APIRequestContext;
// Experimental, undocumented: mount a story from the component gallery and return a locator
- // for the mounted component, augmented with update()/unmount(). See the playwright-component-testing skill.
+ // for the gallery root, augmented with update()/unmount(). Scope the queries:
+ // component.getByRole(...). See the playwright-component-testing skill.
mount: (storyId: string, props?: Record<string, any>) => Promise<Locator & { update(props?: Record<string, any>): Promise<void>, unmount(): Promise<void> }>;
}
diff --git a/packages/web/playwright.config.ts b/packages/web/playwright.config.ts
new file mode 100644
index 0000000000..b8eb76a2f8
--- /dev/null
+++ b/packages/web/playwright.config.ts
@@ -0,0 +1,51 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import path from 'path';
+import { devices, defineConfig } from '@playwright/test';
+
+const outputDir = path.join(__dirname, '..', '..', 'test-results');
+
+export default defineConfig({
+ testDir: 'src',
+ outputDir,
+ forbidOnly: !!process.env.CI,
+ retries: process.env.CI ? 2 : 0,
+ reporter: process.env.CI ? [
+ ['dot'],
+ ['json', { outputFile: path.join(outputDir, 'report.json') }],
+ ['blob', { outputDir: path.join(__dirname, '..', '..', 'blob-report') }],
+ ['../../tests/config/parquetReporter.ts'],
+ ] : [
+ ['html', { open: 'on-failure' }]
+ ],
+ tag: process.env.PW_TAG,
+ use: {
+ baseURL: 'http://localhost:3102/playwright/gallery/index.html',
+ serviceWorkers: 'block',
+ reuseContext: true,
+ trace: 'on-first-retry',
+ },
+ projects: [{
+ name: 'chromium',
+ use: { ...devices['Desktop Chrome'] },
+ }],
+ webServer: {
+ command: 'npx vite --config playwright/vite.config.ts',
+ url: 'http://localhost:3102/playwright/gallery/index.html',
+ reuseExistingServer: !process.env.CI,
+ },
+});
diff --git a/packages/web/playwright/gallery/index.html b/packages/web/playwright/gallery/index.html
new file mode 100644
index 0000000000..0842528ca8
--- /dev/null
+++ b/packages/web/playwright/gallery/index.html
@@ -0,0 +1,32 @@
+<!--
+ Copyright (c) Microsoft Corporation.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="UTF-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <title>Component Gallery</title>
+ <style>
+ html, body { margin: 0; padding: 0; }
+ #root { position: fixed; inset: 0; }
+ </style>
+ </head>
+ <body>
+ <div id="root"></div>
+ <script type="module" src="./main.tsx"></script>
+ </body>
+</html>
diff --git a/packages/web/playwright/gallery/main.tsx b/packages/web/playwright/gallery/main.tsx
new file mode 100644
index 0000000000..55a8d091cf
--- /dev/null
+++ b/packages/web/playwright/gallery/main.tsx
@@ -0,0 +1,51 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { flushSync } from 'react-dom';
+import { createRoot, type Root } from 'react-dom/client';
+import '../../src/common.css';
+import '../../src/theme';
+import '../../src/third_party/vscode/codicon.css';
+import '../../src/third_party/vscode/colors.css';
+
+const stories = import.meta.glob('../../src/**/*.story.{tsx,jsx}');
+const storyId = (file: string) => file.replace(/^(\.\.\/)+src\//, '').replace(/\.story\.\w+$/, '');
+
+async function resolveStory(id: string): Promise<React.ComponentType<any> | undefined> {
+ const sep = id.lastIndexOf('/');
+ const [path, name] = [id.slice(0, sep), id.slice(sep + 1)];
+ const file = Object.keys(stories).find(f => storyId(f) === path || storyId(f).endsWith('/' + path));
+ const mod = (file && await stories[file]()) as Record<string, any> | undefined;
+ return mod?.[name] ?? mod?.default;
+}
+
+const rootElement = document.getElementById('root')!;
+let root: Root | undefined;
+
+(window as any).mount = async ({ story, props }: { story: string, props?: Record<string, any> }) => {
+ const Story = await resolveStory(story);
+ if (!Story)
+ throw new Error(`Unknown story: ${story}`);
+ // Reuse the root so that update() reconciles and preserves state.
+ root ??= createRoot(rootElement);
+ // flushSync so that a render error rejects the promise instead of being swallowed.
+ flushSync(() => root!.render(<Story {...props} />));
+};
+
+(window as any).unmount = async () => {
+ root?.unmount();
+ root = undefined;
+};
diff --git a/packages/web/playwright/vite.config.ts b/packages/web/playwright/vite.config.ts
new file mode 100644
index 0000000000..4e395968fa
--- /dev/null
+++ b/packages/web/playwright/vite.config.ts
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { defineConfig } from 'vite';
+import react from '@vitejs/plugin-react';
+import path from 'path';
+
+// Serves the component gallery at /playwright/gallery/index.html for the
+// component tests, see playwright.config.ts.
+export default defineConfig({
+ root: path.resolve(__dirname, '..'),
+ plugins: [react()],
+ server: {
+ port: 3102,
+ strictPort: true,
+ },
+});
diff --git a/packages/web/src/components/DEPS.list b/packages/web/src/components/DEPS.list
index f49abefe37..1ed158bbb9 100644
--- a/packages/web/src/components/DEPS.list
+++ b/packages/web/src/components/DEPS.list
@@ -7,11 +7,11 @@
../shared
../../../isomorphic/**
-[expandable.spec.tsx]
+[expandable.spec.ts]
***
-[codeMirrorWrapper.spec.tsx]
+[codeMirrorWrapper.spec.ts]
***
-[splitView.spec.tsx]
+[splitView.spec.ts]
***
diff --git a/packages/web/src/components/codeMirrorWrapper.spec.ts b/packages/web/src/components/codeMirrorWrapper.spec.ts
new file mode 100644
index 0000000000..eb4a6355fc
--- /dev/null
+++ b/packages/web/src/components/codeMirrorWrapper.spec.ts
@@ -0,0 +1,119 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { expect, test } from '@playwright/test';
+
+test.use({ viewport: { width: 500, height: 500 } });
+
+const javascriptSnippet = `import { test, expect } from '@playwright/test';
+
+test('basic test', async ({ page }) => {
+ await page.goto('https://playwright.dev/');
+ const title = page.locator('.navbar__inner .navbar__title');
+ await expect(title).toHaveText('Playwright');
+});
+`;
+
+const pythonSnippet = `import asyncio
+from playwright.async_api import async_playwright
+
+async def main():
+ async with async_playwright() as p:
+ # Works across chromium, firefox and webkit
+ browser = await p.chromium.launch(headless=False)
+
+asyncio.run(main())
+`;
+
+const javaSnippet = `import com.microsoft.playwright.*;
+
+public class Example {
+ public static void main(String[] args) {
+ try (Playwright playwright = Playwright.create()) {
+ BrowserType chromium = playwright.chromium();
+ Browser browser = chromium.launch(new BrowserType.LaunchOptions().setHeadless(false));
+ }
+ }
+}
+`;
+
+const csharpSnippet = `
+using Microsoft.Playwright;
+using System.Threading.Tasks;
+
+class Program
+{
+ public static async Task Main()
+ {
+ using var playwright = await Playwright.CreateAsync();
+ await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions
+ {
+ Headless = false
+ });
+ }
+}
+`;
+
+test('highlight JavaScript', async ({ mount }) => {
+ const component = await mount('components/codeMirrorWrapper/Default', { text: javascriptSnippet, highlighter: 'javascript' });
+ await expect(component.locator('text="async"').first()).toHaveClass('cm-keyword');
+});
+
+test('highlight Python', async ({ mount }) => {
+ const component = await mount('components/codeMirrorWrapper/Default', { text: pythonSnippet, highlighter: 'python' });
+ await expect(component.locator('text="async"').first()).toHaveClass('cm-keyword');
+});
+
+test('highlight Java', async ({ mount }) => {
+ const component = await mount('components/codeMirrorWrapper/Default', { text: javaSnippet, highlighter: 'java' });
+ await expect(component.locator('text="public"').first()).toHaveClass('cm-keyword');
+});
+
+test('highlight C#', async ({ mount }) => {
+ const component = await mount('components/codeMirrorWrapper/Default', { text: csharpSnippet, highlighter: 'csharp' });
+ await expect(component.locator('text="public"').first()).toHaveClass('cm-keyword');
+});
+
+test('should report changes via onChange', async ({ mount, page }) => {
+ const component = await mount('components/codeMirrorWrapper/Editable');
+ await component.locator('.CodeMirror').click();
+ await page.keyboard.type('!');
+ await expect(component.getByTestId('value')).toHaveValue(/!/);
+ await expect(component.getByTestId('value')).toHaveValue(/initial/);
+});
+
+test('should not report changes when read-only', async ({ mount, page }) => {
+ const component = await mount('components/codeMirrorWrapper/Editable', { readOnly: true });
+ await component.locator('.CodeMirror').click();
+ await page.keyboard.type('!');
+ await expect(component.locator('.CodeMirror')).toContainText('initial');
+ await expect(component.getByTestId('value')).toHaveValue('');
+});
+
+test('highlight lines', async ({ mount }) => {
+ const component = await mount('components/codeMirrorWrapper/Default', {
+ text: javascriptSnippet,
+ highlighter: 'javascript',
+ highlight: [
+ { line: 4, type: 'running' },
+ { line: 5, type: 'paused' },
+ { line: 6, type: 'error' },
+ ],
+ });
+ await expect(component.locator('.source-line-running')).toContainText('goto');
+ await expect(component.locator('.source-line-paused')).toContainText('title');
+ await expect(component.locator('.source-line-error')).toContainText('expect');
+});
diff --git a/packages/web/src/components/codeMirrorWrapper.story.tsx b/packages/web/src/components/codeMirrorWrapper.story.tsx
new file mode 100644
index 0000000000..06a0b218f6
--- /dev/null
+++ b/packages/web/src/components/codeMirrorWrapper.story.tsx
@@ -0,0 +1,36 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import * as React from 'react';
+import type { SourceHighlight, SourceProps } from './codeMirrorWrapper';
+import { CodeMirrorWrapper } from './codeMirrorWrapper';
+
+type StoryProps = {
+ text?: string,
+ highlighter?: SourceProps['highlighter'],
+ highlight?: SourceHighlight[],
+};
+
+export const Default = ({ text, highlighter, highlight }: StoryProps) =>
+ <CodeMirrorWrapper text={text ?? ''} highlighter={highlighter} highlight={highlight} />;
+
+export const Editable = ({ readOnly }: { readOnly?: boolean }) => {
+ const [value, setValue] = React.useState('');
+ return <>
+ <CodeMirrorWrapper text='initial' readOnly={readOnly} onChange={setValue} />
+ <form hidden><input data-testid='value' readOnly value={value} /></form>
+ </>;
+};
diff --git a/packages/web/src/components/expandable.spec.ts b/packages/web/src/components/expandable.spec.ts
new file mode 100644
index 0000000000..42ee28d872
--- /dev/null
+++ b/packages/web/src/components/expandable.spec.ts
@@ -0,0 +1,53 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { expect, test } from '@playwright/test';
+
+test.use({ viewport: { width: 500, height: 500 } });
+
+test('should render collapsed', async ({ mount }) => {
+ const component = await mount('components/expandable/Collapsed');
+ await expect(component.locator('text=Title')).toBeVisible();
+ await expect(component.locator('text=Details')).toBeHidden();
+ await expect(component.locator('.codicon-chevron-right')).toBeVisible();
+});
+
+test('should render expanded', async ({ mount }) => {
+ const component = await mount('components/expandable/Expanded');
+ await expect(component.locator('text=Title')).toBeVisible();
+ await expect(component.locator('text=Details')).toBeVisible();
+ await expect(component.locator('.codicon-chevron-down')).toBeVisible();
+});
+
+test('click should expand', async ({ mount }) => {
+ const component = await mount('components/expandable/Stateful');
+ await component.locator('.codicon-chevron-right').click();
+ await expect(component.getByTestId('expanded')).toHaveValue('true');
+ await expect(component.locator('text=Details')).toBeVisible();
+});
+
+test('title click should expand when enabled', async ({ mount }) => {
+ const component = await mount('components/expandable/StatefulTitleClick');
+ await component.getByText('Title').click();
+ await expect(component.getByTestId('expanded')).toHaveValue('true');
+});
+
+test('title click should not expand by default', async ({ mount }) => {
+ const component = await mount('components/expandable/Stateful');
+ await component.getByText('Title').click();
+ await expect(component.locator('.codicon-chevron-right')).toBeVisible();
+ await expect(component.getByTestId('expanded')).toHaveValue('false');
+});
diff --git a/packages/web/src/components/expandable.story.tsx b/packages/web/src/components/expandable.story.tsx
new file mode 100644
index 0000000000..99796b8135
--- /dev/null
+++ b/packages/web/src/components/expandable.story.tsx
@@ -0,0 +1,40 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import * as React from 'react';
+import { Expandable } from './expandable';
+
+export const Collapsed = () =>
+ <Expandable expanded={false} setExpanded={() => {}} title='Title'>Details text</Expandable>;
+
+export const Expanded = () =>
+ <Expandable expanded={true} setExpanded={() => {}} title='Title'>Details text</Expandable>;
+
+export const Stateful = () => {
+ const [expanded, setExpanded] = React.useState(false);
+ return <>
+ <Expandable expanded={expanded} setExpanded={setExpanded} title='Title'>Details text</Expandable>
+ <form hidden><input data-testid='expanded' readOnly value={String(expanded)} /></form>
+ </>;
+};
+
+export const StatefulTitleClick = () => {
+ const [expanded, setExpanded] = React.useState(false);
+ return <>
+ <Expandable expanded={expanded} setExpanded={setExpanded} expandOnTitleClick title='Title'>Details text</Expandable>
+ <form hidden><input data-testid='expanded' readOnly value={String(expanded)} /></form>
+ </>;
+};
diff --git a/packages/web/src/components/splitView.spec.ts b/packages/web/src/components/splitView.spec.ts
new file mode 100644
index 0000000000..ae3bd07472
--- /dev/null
+++ b/packages/web/src/components/splitView.spec.ts
@@ -0,0 +1,61 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { expect, test } from '@playwright/test';
+
+test.use({ viewport: { width: 500, height: 500 } });
+
+test('should render', async ({ mount }) => {
+ const component = await mount('components/splitView/Default');
+ const mainBox = await component.locator('#main').boundingBox();
+ const sidebarBox = await component.locator('#sidebar').boundingBox();
+ expect.soft(mainBox).toEqual({ x: 0, y: 0, width: 500, height: 400 });
+ expect.soft(sidebarBox).toEqual({ x: 0, y: 401, width: 500, height: 99 });
+});
+
+test('should render sidebar first', async ({ mount }) => {
+ const component = await mount('components/splitView/Default', { sidebarIsFirst: true });
+ const mainBox = await component.locator('#main').boundingBox();
+ const sidebarBox = await component.locator('#sidebar').boundingBox();
+ expect.soft(mainBox).toEqual({ x: 0, y: 100, width: 500, height: 400 });
+ expect.soft(sidebarBox).toEqual({ x: 0, y: 0, width: 500, height: 99 });
+});
+
+test('should render horizontal split', async ({ mount }) => {
+ const component = await mount('components/splitView/Default', { sidebarIsFirst: true, orientation: 'horizontal' });
+ const mainBox = await component.locator('#main').boundingBox();
+ const sidebarBox = await component.locator('#sidebar').boundingBox();
+ expect.soft(mainBox).toEqual({ x: 100, y: 0, width: 400, height: 500 });
+ expect.soft(sidebarBox).toEqual({ x: 0, y: 0, width: 99, height: 500 });
+});
+
+test('should hide sidebar', async ({ mount }) => {
+ const component = await mount('components/splitView/Default', { orientation: 'horizontal', sidebarHidden: true });
+ const mainBox = await component.locator('#main').boundingBox();
+ expect.soft(mainBox).toEqual({ x: 0, y: 0, width: 500, height: 500 });
+});
+
+test('drag resize', async ({ page, mount }) => {
+ const component = await mount('components/splitView/Default');
+ await page.mouse.move(25, 400);
+ await page.mouse.down();
+ await page.mouse.move(25, 100);
+ await page.mouse.up();
+ const mainBox = await component.locator('#main').boundingBox();
+ const sidebarBox = await component.locator('#sidebar').boundingBox();
+ expect.soft(mainBox).toEqual({ x: 0, y: 0, width: 500, height: 100 });
+ expect.soft(sidebarBox).toEqual({ x: 0, y: 101, width: 500, height: 399 });
+});
diff --git a/packages/web/src/components/splitView.story.tsx b/packages/web/src/components/splitView.story.tsx
new file mode 100644
index 0000000000..931cd377c1
--- /dev/null
+++ b/packages/web/src/components/splitView.story.tsx
@@ -0,0 +1,27 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { SplitView, type SplitViewProps } from './splitView';
+
+type StoryProps = Partial<Pick<SplitViewProps, 'sidebarSize' | 'sidebarHidden' | 'sidebarIsFirst' | 'orientation'>>;
+
+export const Default = (props: StoryProps) =>
+ <SplitView
+ sidebarSize={100}
+ {...props}
+ main={<div id='main' style={{ border: '1px solid red', flex: 'auto' }}>main</div>}
+ sidebar={<div id='sidebar' style={{ border: '1px solid blue', flex: 'auto' }}>sidebar</div>}
+ />;
diff --git a/packages/web/src/shared/DEPS.list b/packages/web/src/shared/DEPS.list
index 82081a1d2f..618e175189 100644
--- a/packages/web/src/shared/DEPS.list
+++ b/packages/web/src/shared/DEPS.list
@@ -1,5 +1,5 @@
[*]
../uiUtils.ts
-[imageDiffView.spec.tsx]
+[imageDiffView.spec.ts]
***
diff --git a/packages/web/src/shared/imageDiffView.spec.ts b/packages/web/src/shared/imageDiffView.spec.ts
new file mode 100644
index 0000000000..a0afc75826
--- /dev/null
+++ b/packages/web/src/shared/imageDiffView.spec.ts
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { expect, test } from '@playwright/test';
+
+test.use({ viewport: { width: 1000, height: 800 } });
+
+test('should render links', async ({ mount }) => {
+ const component = await mount('shared/imageDiffView/Default');
+ await expect(component.locator('a')).toHaveText([
+ 'screenshot-diff.png',
+ 'screenshot-actual.png',
+ 'screenshot-expected.png',
+ ]);
+});
+
+test('should show diff by default', async ({ mount }) => {
+ const component = await mount('shared/imageDiffView/Default');
+ const image = component.locator('img');
+ const box = await image.boundingBox();
+ expect(box).toEqual(expect.objectContaining({ width: 48, height: 48 }));
+});
diff --git a/packages/web/src/shared/imageDiffView.story.tsx b/packages/web/src/shared/imageDiffView.story.tsx
new file mode 100644
index 0000000000..47fb98a42d
--- /dev/null
+++ b/packages/web/src/shared/imageDiffView.story.tsx
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) Microsoft Corporation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { ImageDiff } from './imageDiffView';
+import { ImageDiffView } from './imageDiffView';
+
+const expectedPng = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAQAAAD9CzEMAAACMElEQVRYw+1XT0tCQRD/9Qci0Cw7mp1C6BMYnt5niMhPEEFCh07evNk54XnuGkhFehA/QxHkqYMEFWXpscMTipri7fqeu+vbfY+EoBkQ3Zn5zTo7MzsL/NNfoClkUUQNN3jCJ/ETfavRSpYkkSmFQzz8wMr4gaSp8OBJ2HCU4Iwd0kqGgd9GPxCccZ+0jWgWVW1wxlWy0qR51I3hv7lOllq7b4SC/+aGzr+QBadjEKgAykvzJGXwr/Lj4JfRk5hUSLKIa00HPUJRki0xeMWSWxVXmi5sddXKymqTyxdwquXAUVV3WREeLx3gTcNFWQY/jXtB8QIzgt4qTvAR4OCe0ATKCmrnmFMEM0Pp2BvrIisaFUdUjgKKZgYWSjjDLR5J+x13lATHuHSti6JBzQP+gq2QHXjfRaiJojbPgYqbmGFow0VpiyIW0/VIF9QKLzeBWA2MHmwCu8QJQV++Ps/joHQQH4HpuO0uobUeVztgIcr4Vnf4we9orWfUIWKHbEVyYKkPmaVpIVKICuo0ZYXWjHTITXWhsVYxkIDpUoKsla1i2Oz2QjvYG9fshu36GbFQ8DGyHNOuvRdOKZSDUtCFM7wyHeSM4XN8e7bOpd9F2gg+TRYal753bGkbuEjzMg0YW/yDV1czUDm+e43Byz86OnRwsYDMKXlmkYbeAOwffrtU/nGpXpwkXfPhVza+D9AiMAtrtOMYfVr0q8Wr1nh8n8ADZCJPqAk8AifyjP2n36cvkA6/Wln9MokAAAAASUVORK5CYII=';
+const actualPng = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAQAAAD9CzEMAAACcElEQVRYw+2XQU9TQRDHfxAiYoFE8IaHhhjjN3hw4+SJk0npGU+iCQYv1kQjIQInj6+foh4amhjvEi8EI3yAIk24lBgoBkmqqYfuLvt23763r8QmJszc3sz+/29nZ3Zm4Vr+BxkgoESFPY7o0OGIPSqUCBi4OvgUmzToOLTBJlO9g08QcuEEl3pByEQv8Ascp4JLPWYhG/gQ5QjAGVWWmSXPTUa5xxxLfDJ2V2bIF36ELW3hASuMxfqNsiSOvatbjPj9fU0tabPOjUTvHG/4pfxrPrvQg7PqteNA20c5zbkYiWubgmZbZJcTzvjKGneMZP6m1hST4CdpGvmhU0zzXX0/5VFk5V21iyaTboJQwa7STqH4Y1AE6ixCd9XKxHsHFFIpTo1AvVal56juDeFQZxi8KNaMjJJh2oiDH+RQmFfUtzSKXQPjifh+yGBcsnWNrUhZJVO0DIxxFeTAJigJU9X4nkRxYqF8FL4lm6AiTMuW5bMzaXcs36fCs2IT7AvTjHNvNsVjy3dO+O3bBLLE8jF9oemsblPuq3KzRB7PrZhl8/z2pBhTteAkyMUunI+0HzdFzk0gwzDtvKde8SU2o3TJu0MkD3k28bYtpFDMuA/ZnaZZKJ6707SkuhJXoKi6Cy1QDT7XM8U4LfdVEXfZSXnAMz6wTZ1zzqmzrVWGTvEi6bK7vK4bWqO/zUtF7FJJMcxB0nWtN5y3omje89Nr8OpSrKc1HL1lBjzUGosPxWWTDX2a/o8M4FFNbPrm2NKLFrMMXtk1dfCKjo5ZteY3AEeHX3/1HH7jxne/4HiP7314gPTlCdWHR2BfnrHX8u/lL/ENCdIFFeD3AAAAAElFTkSuQmCC';
+
+const imageDiff: ImageDiff = {
+ name: 'log in',
+ actual: { attachment: { name: 'screenshot-actual.png', path: actualPng, contentType: 'image/png' } },
+ expected: { attachment: { name: 'screenshot-expected.png', path: expectedPng, contentType: 'image/png' }, title: 'Expected' },
+ diff: { attachment: { name: 'screenshot-diff.png', path: expectedPng, contentType: 'image/png' } },
+};
+
+export const Default = () => <ImageDiffView diff={imageDiff} />;
diff --git a/utils/generate_types/overrides-test.d.ts b/utils/generate_types/overrides-test.d.ts
index 66f6dc3605..337b202552 100644
--- a/utils/generate_types/overrides-test.d.ts
+++ b/utils/generate_types/overrides-test.d.ts
@@ -310,7 +310,8 @@ export interface PlaywrightTestArgs {
page: Page;
request: APIRequestContext;
// Experimental, undocumented: mount a story from the component gallery and return a locator
- // for the mounted component, augmented with update()/unmount(). See the playwright-component-testing skill.
+ // for the gallery root, augmented with update()/unmount(). Scope the queries:
+ // component.getByRole(...). See the playwright-component-testing skill.
mount: (storyId: string, props?: Record<string, any>) => Promise<Locator & { update(props?: Record<string, any>): Promise<void>, unmount(): Promise<void> }>;
}