penpot/frontend/playwright.config.js
Luke Lau 08365f6e1f 🐛 Fix render-wasm Playwright specs on macOS
This PR contains two fixes.

The first is that some of the render-wasm specs fail on macOS because
the `devices["Desktop Chrome"]` playwright preset uses a Windows user
agent by default. So penpot registers ctrl shortcuts, but Playwright
sends Meta via the ControlOrMeta command if the tests are running on
macOS.

The `platform === 'darwin'` check didn't work due to a typo (I believe
it should be `platform() == 'darwin'`. But removing the preset also
fixes it by letting the browser send its own user agent, which matches
the host OS.

The second is that the "Renders background blur under strokes on
rects, paths and texts" spec failed because this.pageName matched
multiple elements, and playwright complained in strict mode. This
fixes it by using .first() in a few places and making
waitForWebSocketReadiness match the exact name. It also means we can
remove the workaround in rename-page.spec.js.

AI-assisted-by: claude-opus-5-5
2026-11-26 16:06:17 +01:00

109 lines
3.1 KiB
JavaScript

import { defineConfig } from "@playwright/test";
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();
// Default timeout of the retrying expects (toBeVisible and friends). CI
// runners are slower and the first load of a page fetches its module, so
// they get more time. A project that sets its own `expect` replaces the
// top-level one instead of merging with it, so every such project has to
// repeat this timeout or it falls back to Playwright's 5 seconds.
const expectTimeout = process.env.CI ? 40000 : 5000;
/**
* @see https://playwright.dev/docs/test-configuration
*/
export default defineConfig({
testDir: "./playwright",
outputDir: './test-results',
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests by default; can be overriden with --workers */
workers: 1,
/* Timeout for expects (longer in CI) */
timeout: 80000,
expect: {
timeout: expectTimeout,
},
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: "list",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: "http://localhost:3000",
locale: "en-US",
/* Profiles without a theme follow the system one; run the UI in dark */
colorScheme: "dark",
permissions: ["clipboard-write", "clipboard-read"],
},
/* Configure projects for major browsers */
projects: [
{
name: "default",
testDir: "./playwright/ui/specs",
use: {
viewport: { width: 1920, height: 1080 }, // Add custom viewport size
video: 'retain-on-failure',
trace: 'retain-on-failure',
},
snapshotPathTemplate: "{testDir}/{testFilePath}-snapshots/{arg}.png",
expect: {
timeout: expectTimeout,
toHaveScreenshot: {
maxDiffPixelRatio: 0.001,
},
},
},
{
name: "ds",
testDir: "./playwright/ui/visual-specs",
expect: {
timeout: expectTimeout,
toHaveScreenshot: { maxDiffPixelRatio: 0.005 },
},
},
{
name: "render-wasm",
use: {
viewport: { width: 1920, height: 1080 }, // Add custom viewport size
deviceScaleFactor: 2,
launchOptions: {
args: [
'--enable-gpu',
],
}
},
testDir: "./playwright/ui/render-wasm-specs",
snapshotPathTemplate: "{testDir}/{testFilePath}-snapshots/{arg}.png",
timeout: 2 * 60 * 1000,
expect: {
timeout: process.env.CI ? 20000 : 10000,
toHaveScreenshot: {
maxDiffPixelRatio: 0.001,
},
},
},
],
/* Run your local dev server before starting the tests */
webServer: {
timeout: 2 * 60 * 1000,
command: "node ./scripts/e2e-server.js",
url: "http://localhost:3000",
reuseExistingServer: !process.env.CI,
},
});