penpot/frontend/playwright/ui/pages/WasmWorkspacePage.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

114 lines
3.1 KiB
JavaScript

import { expect } from "@playwright/test";
import { WorkspacePage } from "./WorkspacePage";
export const WASM_PROFILE = "logged-in-user/get-profile-wasm-renderer.json";
export const WASM_FLAGS = [
"enable-feature-render-wasm",
"enable-render-wasm-dpr",
"enable-feature-text-editor-v2",
// Default flags enable render-wasm-info; keep screenshots stable in e2e.
"disable-render-wasm-info",
];
export class WasmWorkspacePage extends WorkspacePage {
static async init(page) {
await super.init(page);
await WasmWorkspacePage.mockConfigFlags(page, WASM_FLAGS);
await WasmWorkspacePage.mockRPC(page, "get-profile", WASM_PROFILE);
await page.addInitScript(() => {
document.addEventListener("penpot:wasm:loaded", () => {
window.wasmModuleLoaded = true;
});
document.addEventListener("penpot:wasm:render", () => {
window.wasmRenderCount = (window.wasmRenderCount || 0) + 1;
});
document.addEventListener("penpot:wasm:set-objects", () => {
window.wasmSetObjectsFinished = true;
});
});
}
static async mockConfigFlags(page, flags) {
await super.mockConfigFlags(page, [...WASM_FLAGS, ...flags]);
}
async mockConfigFlags(flags) {
return WasmWorkspacePage.mockConfigFlags(this.page, flags);
}
constructor(page, options) {
super(page, options);
this.canvas = page.getByTestId("canvas-wasm-shapes");
}
async waitForIdle(options) {
return this.page.evaluate(
(options) => new Promise((resolve) => globalThis.requestIdleCallback(resolve, options)),
options
);
}
async waitForFirstRender() {
// The sitemap shows one name per page; any of them proves the UI is up.
await this.pageName.first().waitFor();
await this.canvas.waitFor();
await this.page.waitForFunction(() => {
console.log("RAF:", window.wasmSetObjectsFinished);
return window.wasmSetObjectsFinished;
});
}
async waitForFirstRenderWithoutUI() {
await this.waitForFirstRender();
await this.hideUI();
}
async getRenderCount() {
return this.page.evaluate(() => window.wasmRenderCount || 0);
}
async waitForNextRender(previousCount = null) {
const baseCount =
previousCount === null ? await this.getRenderCount() : previousCount;
await this.page.waitForFunction(
(count) => (window.wasmRenderCount || 0) > count,
baseCount,
);
}
async hideUI() {
await this.page.keyboard.press("\\");
await expect(this.pageName.first()).not.toBeVisible();
}
static async mockGoogleFont(page, fontSlug, assetFilename, options = {}) {
const url = new RegExp(`/internal/gfonts/font/${fontSlug}`);
return await page.route(url, (route) =>
route.fulfill({
status: 200,
path: `playwright/data/${assetFilename}`,
contentType: "application/font-ttf",
...options,
}),
);
}
async mockGoogleFont(fontSlug, assetFilename, options) {
return WasmWorkspacePage.mockGoogleFont(
this.page,
fontSlug,
assetFilename,
options,
);
}
async setupEmptyFile() {
await super.setupEmptyFile();
await this.mockRPC("get-profile", WASM_PROFILE);
}
}