Compare commits

..
Author SHA1 Message Date
KenandCopilot ea94696a42 Storybook tests: run WebKit test files serially (#5571)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-21 12:23:42 +01:00
KenandCopilot d1bb8ec012 Remove temporary Dialog diagnostics and ineffective DismissableLayer wait
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-21 10:35:50 +01:00
KenandCopilot 5ea403d1a1 Stabilize WebKit play tests; add temporary Dialog focus diagnostics
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-21 10:27:08 +01:00
KenandCopilot 2d93fa28ef Dialog: account for WebKit not focusing buttons on click in focus-trap test
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-21 10:18:11 +01:00
KenandCopilot b06b3a46f6 Fix cross-browser play test failures
- Data ResizeAuto: allow ±5% on measured column widths (text metrics differ per engine)
- DismissableLayer NestedPointerEvents: await waitFor before clicking outside

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-21 10:07:26 +01:00
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
9 changed files with 44 additions and 21 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
@@ -280,12 +280,19 @@ export const ResizeAuto: Story = {
const headers = canvas.getAllByRole("columnheader");
expect(headers.length).toBe(7);
expect(headers[0]).toHaveStyle({ width: "126px" });
expect(headers[1]).toHaveStyle({ width: "80px" });
expect(headers[2]).toHaveStyle({ width: "82px" });
expect(headers[3]).toHaveStyle({ width: "103px" });
expect(headers[4]).toHaveStyle({ width: "168px" });
expect(headers[5]).toHaveStyle({ width: "248px" });
expect(headers[6]).toHaveStyle({ width: "168px" });
expectWidthNear(headers[0], 126);
expectWidthNear(headers[1], 80);
expectWidthNear(headers[2], 82);
expectWidthNear(headers[3], 103);
expectWidthNear(headers[4], 168);
expectWidthNear(headers[5], 248);
expectWidthNear(headers[6], 168);
},
};
/* Auto-resized widths are measured from rendered text, which differs slightly between browser engines */
function expectWidthNear(element: HTMLElement, expected: number) {
const width = parseFloat(getComputedStyle(element).width);
expect(width).toBeGreaterThanOrEqual(expected * 0.95);
expect(width).toBeLessThanOrEqual(expected * 1.05);
}
@@ -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();
@@ -135,7 +135,7 @@ export const OpenDelay: Story = {
{ timeout: 250 },
);
await waitFor(() => expect(canvas.getByRole("tooltip")).toBeVisible(), {
timeout: 500,
timeout: 1000,
});
},
};
@@ -320,14 +320,14 @@ export const NestedPointerEvents: StoryObj<{
await fireEvent.pointerDown(outside);
waitFor(() => {
await waitFor(() => {
expect(args.root.onDismiss).not.toHaveBeenCalled();
expect(args.nested.onDismiss).toHaveBeenCalledTimes(1);
});
await userEvent.click(outside);
waitFor(() => {
await waitFor(() => {
expect(args.root.onDismiss).toHaveBeenCalledTimes(1);
expect(args.nested.onDismiss).toHaveBeenCalledTimes(1);
});
@@ -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();
+16 -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,14 @@ 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,
/*
* Parallel WebKit pages interfere with each other's focus, so focus
* assertions (e.g. Dialog mount focus) fail at random. Run WebKit files serially.
*/
fileParallelism: browser !== "webkit",
})),
},
},
},