Compare commits

...
Author SHA1 Message Date
KenandCopilot a4e97439ee Storybook tests: run in Chromium, Firefox and WebKit
CI runs one job per browser. Copilot CLI runs only Chromium, since
Firefox and WebKit can't launch inside the cplt sandbox on macOS.
Fix two Chromium-flaky play tests that raced the deferred initial focus.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-20 22:23:46 +01:00
6 changed files with 20 additions and 11 deletions

No files matched your search

+2 -2
View File
@@ -48,8 +48,8 @@
- `corepack yarn tsc --noEmit --incremental false --project <tsconfig>` - targeted type-check
- `corepack yarn workspace <name> <script>` - e.g. `@navikt/ds-react test` (Vitest + tsc), `website test`
- `corepack yarn lint` / `corepack yarn test` / `corepack yarn boot` - root suites (slow; cross-workspace changes only)
- `corepack yarn storybook` (:6006) / `corepack yarn storybook:aksel` (website examples, :6007, no secrets) / `corepack yarn storybook:test` (play tests, Playwright Firefox; Chromium when `COPILOT_CLI` is set) / `corepack yarn dev` (website, :3000, needs Sanity token)
- Targeted play tests: `corepack yarn storybook:test <path/to/X.tests.stories.tsx>` (repo root). Run after changing play tests. Under Copilot CLI this runs Chromium; if the browser can't launch, report tests as not run with the exact command.
- `corepack yarn storybook` (:6006) / `corepack yarn storybook:aksel` (website examples, :6007, no secrets) / `corepack yarn storybook:test` (play tests in Playwright Chromium, Firefox and WebKit; only Chromium when `COPILOT_CLI` is set; filter with `--browser.name=<browser>`) / `corepack yarn dev` (website, :3000, needs Sanity token)
- Targeted play tests: `corepack yarn storybook:test <path/to/X.tests.stories.tsx>` (repo root). Run after changing play tests. Under Copilot CLI this runs only Chromium (Firefox/WebKit can't launch in the cplt sandbox; CI covers them); if the browser can't launch, report tests as not run with the exact command.
## Where to edit
+1 -1
View File
@@ -17,4 +17,4 @@ applyTo: "**/*.test.ts,**/*.test.tsx,**/*.stories.tsx"
- Before removing or consolidating tests, map each meaningful old scenario/assertion to its replacement story or test. Keep coverage that still represents a supported behavior; explain when a scenario is intentionally obsolete.
- For state, accessibility, keyboard or focus behavior, use the [component-contract skill](../skills/component-contract/SKILL.md) to identify the contract and evidence to preserve.
- ds-react unit tests run with `TZ=UTC`. Date logic must not depend on the local timezone.
- Browser tests need Playwright Firefox (Chromium under Copilot CLI, see `vitest.config.mts`). Yarn has `enableScripts: false`, so if the browser is missing, report it instead of installing globally.
- Browser tests run in Playwright Chromium, Firefox and WebKit (one CI job each). Under Copilot CLI only Chromium runs, since Firefox/WebKit can't launch in the cplt sandbox (see `vitest.config.mts`). Run one browser with `--browser.name=<browser>`. Yarn has `enableScripts: false`, so if the browser is missing, report it instead of installing globally.
+6 -2
View File
@@ -71,11 +71,15 @@ jobs:
run: yarn test
ui:
name: UI tests (Storybook)
name: UI tests (Storybook, ${{ matrix.browser }})
runs-on: ubuntu-latest
timeout-minutes: 10
container:
image: mcr.microsoft.com/playwright:v1.61.1-noble
strategy:
fail-fast: false
matrix:
browser: [chromium, firefox, webkit]
steps:
- name: Checkout code
uses: actions/checkout@v7
@@ -89,6 +93,6 @@ jobs:
npm_auth_token: ${{ secrets.READER_TOKEN }}
- name: Test UI
run: yarn storybook:test --max-workers=2
run: yarn storybook:test --max-workers=2 --browser.name=${{ matrix.browser }}
env:
HOME: /root
@@ -701,6 +701,7 @@ export const TabToLinks: Story = {
play: async ({ canvasElement, args }) => {
const { canvas } = testUtils(canvasElement, args);
await waitFor(() => expect(canvas.getByTestId("popup")).toHaveFocus());
await userEvent.tab();
expect(canvas.getByPlaceholderText("test")).toHaveFocus();
await userEvent.tab();
@@ -44,8 +44,7 @@ export const Loop: Story = {
const middle = canvas.getByLabelText(Field_TWO);
const last = canvas.getByText(BUTTON_THREE);
/* Regular focus */
first.focus();
/* Mount focus lands on the first field in the next frame. Wait so it can't steal focus mid-test */
await waitFor(() => expect(first).toHaveFocus());
await userEvent.tab();
+9 -4
View File
@@ -2,6 +2,14 @@ import { storybookTest } from "@storybook/addon-vitest/vitest-plugin";
import { playwright } from "@vitest/browser-playwright";
import { defineConfig } from "vitest/config";
/*
* Firefox and WebKit can't launch inside the cplt sandbox used by Copilot CLI on macOS,
* so agents only run Chromium. CI runs all three. Filter with `--browser.name=<browser>`.
*/
const browsers = process.env.COPILOT_CLI
? (["chromium"] as const)
: (["chromium", "firefox", "webkit"] as const);
// More info at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon
export default defineConfig({
test: {
@@ -23,10 +31,7 @@ export default defineConfig({
enabled: true,
headless: true,
provider: playwright(),
/* Firefox can't start inside the cplt sandbox used by Copilot CLI */
instances: [
{ browser: process.env.COPILOT_CLI ? "chromium" : "firefox" },
],
instances: browsers.map((browser) => ({ browser })),
},
},
},