ui: fix running storybook tests in ci

This commit is contained in:
Glen Huang
2025-10-22 19:06:17 +08:00
parent 5fb4751bd8
commit 90e6d77e26
5 changed files with 19 additions and 10 deletions

View File

@@ -22,7 +22,6 @@
clan-ts-api = config.packages.clan-ts-api; clan-ts-api = config.packages.clan-ts-api;
fonts = config.packages.fonts; fonts = config.packages.fonts;
}; };
}; };
# // # //
# todo add darwin support # todo add darwin support
@@ -45,8 +44,8 @@
checks = checks =
config.packages.clan-app.tests config.packages.clan-app.tests
# Clan's darwin CI is a sandbox too limiting to spawn a headless brwoser # Sandboxed Darwin nix build can't spawn a headless brwoser
// lib.optionalAttrs (!lib.hasSuffix system "darwin") { // lib.optionalAttrs (!lib.hasSuffix "darwin" system) {
inherit (config.packages.clan-app-ui.tests) clan-app-ui-storybook; inherit (config.packages.clan-app-ui.tests) clan-app-ui-storybook;
}; };
}; };

View File

@@ -128,8 +128,8 @@ mkShell {
export PLAYWRIGHT_BROWSERS_PATH=${ export PLAYWRIGHT_BROWSERS_PATH=${
playwright.browsers.override { playwright.browsers.override {
withFfmpeg = false; withFfmpeg = false;
withFirefox = false; withFirefox = true;
withWebkit = true; withWebkit = false;
withChromium = false; withChromium = false;
withChromiumHeadlessShell = false; withChromiumHeadlessShell = false;
} }
@@ -142,7 +142,7 @@ mkShell {
# stop playwright from trying to validate it has downloaded the necessary browsers # stop playwright from trying to validate it has downloaded the necessary browsers
# we are providing them manually via nix # we are providing them manually via nix
export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=true export PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=1
fi fi
''; '';
} }

View File

@@ -58,8 +58,8 @@ buildNpmPackage (finalAttrs: {
env = { env = {
PLAYWRIGHT_BROWSERS_PATH = "${playwright.browsers.override { PLAYWRIGHT_BROWSERS_PATH = "${playwright.browsers.override {
withFfmpeg = false; withFfmpeg = false;
withFirefox = false; withFirefox = true;
withWebkit = true; withWebkit = false;
withChromium = false; withChromium = false;
withChromiumHeadlessShell = false; withChromiumHeadlessShell = false;
}}"; }}";
@@ -68,6 +68,7 @@ buildNpmPackage (finalAttrs: {
# the playwright nix package does not support: # the playwright nix package does not support:
# https://github.com/NixOS/nixpkgs/blob/f9c3b27aa3f9caac6717973abcc549dbde16bdd4/pkgs/development/web/playwright/driver.nix#L261 # https://github.com/NixOS/nixpkgs/blob/f9c3b27aa3f9caac6717973abcc549dbde16bdd4/pkgs/development/web/playwright/driver.nix#L261
PLAYWRIGHT_HOST_PLATFORM_OVERRIDE = "nixos"; PLAYWRIGHT_HOST_PLATFORM_OVERRIDE = "nixos";
DEBUG = "vitest:*";
}; };
preBuild = finalAttrs.preBuild + '' preBuild = finalAttrs.preBuild + ''
playwright_ver=$(jq --raw-output .devDependencies.playwright ${./ui/package.json}) playwright_ver=$(jq --raw-output .devDependencies.playwright ${./ui/package.json})

View File

@@ -15,7 +15,7 @@
"storybook": "storybook", "storybook": "storybook",
"knip": "knip --fix", "knip": "knip --fix",
"storybook-dev": "storybook dev -p 6006", "storybook-dev": "storybook dev -p 6006",
"test-storybook": "vitest run --project storybook --reporter verbose", "test-storybook": "vitest run --project storybook",
"test-storybook-update-snapshots": "vitest run --project storybook --update" "test-storybook-update-snapshots": "vitest run --project storybook --update"
}, },
"license": "MIT", "license": "MIT",

View File

@@ -94,7 +94,16 @@ export default defineConfig({
provider: "playwright", provider: "playwright",
instances: [ instances: [
{ {
browser: "webkit", // Ideally we should use webkit to match clan-app, but inside a
// sandboxed nix build, webkit takes forever to finish
// launching. Chromium randomly closes itself during testing, as
// reported here:
// https://github.com/vitest-dev/vitest/discussions/7981
//
// Firefox is the only browser that can reliably finish the
// tests. We want to test storybook only, and the differences
// between browsers are probably neglegible to us
browser: "firefox",
}, },
], ],
}, },