penpot/frontend/playwright.config.js
2026-09-29 16:07:08 +02:00

134 lines
3.8 KiB
JavaScript

import { defineConfig, devices } from "@playwright/test";
import { platform } from "os";
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();
const userAgent = platform === 'darwin' ?
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" :
undefined;
// GPU memory harness (playwright/perf). Never run in CI: select it with
// `--project gpu-memory-<engine>`. Headed, since headless Chromium falls
// back to SwiftShader and measures nothing real.
function gpuMemoryProjects() {
const engines = {
chromium: {
...devices["Desktop Chrome"],
launchOptions: { args: ["--enable-gpu", "--ignore-gpu-blocklist"] },
},
firefox: devices["Desktop Firefox"],
webkit: devices["Desktop Safari"],
};
return Object.entries(engines).map(([engine, use]) => ({
name: `gpu-memory-${engine}`,
testDir: "./playwright/perf",
timeout: 15 * 60 * 1000,
use: {
...use,
// The global clipboard permissions only exist in Chromium.
permissions: [],
viewport: { width: 1920, height: 1080 },
deviceScaleFactor: Number(process.env.PERF_DPR ?? 2),
headless: false,
},
}));
}
/**
* @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: process.env.CI ? 40000 : 5000,
},
/* 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",
permissions: ["clipboard-write", "clipboard-read"],
},
/* Configure projects for major browsers */
projects: [
{
name: "default",
testDir: "./playwright/ui/specs",
use: {
...devices["Desktop Chrome"],
viewport: { width: 1920, height: 1080 }, // Add custom viewport size
video: 'retain-on-failure',
trace: 'retain-on-failure',
userAgent,
},
snapshotPathTemplate: "{testDir}/{testFilePath}-snapshots/{arg}.png",
expect: {
toHaveScreenshot: {
maxDiffPixelRatio: 0.001,
},
},
},
{
name: "ds",
use: { ...devices["Desktop Chrome"] },
testDir: "./playwright/ui/visual-specs",
expect: {
toHaveScreenshot: { maxDiffPixelRatio: 0.005 },
},
},
{
name: "render-wasm",
use: {
...devices["Desktop Chrome"],
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,
},
},
},
...gpuMemoryProjects(),
],
/* 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,
},
});