🐛 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
This commit is contained in:
Luke Lau 2026-11-24 16:46:07 +08:00 committed by Belén Albeza
parent b80456b607
commit 08365f6e1f
4 changed files with 10 additions and 21 deletions

View File

@ -1,5 +1,4 @@
import { defineConfig, devices } from "@playwright/test";
import { platform } from "os";
import { defineConfig } from "@playwright/test";
/**
* Read environment variables from file.
@ -7,10 +6,6 @@ import { platform } from "os";
*/
// 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;
// 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
@ -60,11 +55,9 @@ export default defineConfig({
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: {
@ -76,7 +69,6 @@ export default defineConfig({
},
{
name: "ds",
use: { ...devices["Desktop Chrome"] },
testDir: "./playwright/ui/visual-specs",
expect: {
timeout: expectTimeout,
@ -86,7 +78,6 @@ export default defineConfig({
{
name: "render-wasm",
use: {
...devices["Desktop Chrome"],
viewport: { width: 1920, height: 1080 }, // Add custom viewport size
deviceScaleFactor: 2,
launchOptions: {

View File

@ -53,7 +53,8 @@ export class WasmWorkspacePage extends WorkspacePage {
}
async waitForFirstRender() {
await this.pageName.waitFor();
// 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);
@ -81,7 +82,7 @@ export class WasmWorkspacePage extends WorkspacePage {
async hideUI() {
await this.page.keyboard.press("\\");
await expect(this.pageName).not.toBeVisible();
await expect(this.pageName.first()).not.toBeVisible();
}
static async mockGoogleFont(page, fontSlug, assetFilename, options = {}) {

View File

@ -275,7 +275,12 @@ export class WorkspacePage extends BaseWebSocketPage {
async #waitForWebSocketReadiness(pageName) {
// TODO: find a better event to settle whether the app is ready to receive notifications via ws
await expect(this.pageName).toHaveText(pageName, { timeout: 30000 })
// The sitemap shows every page of the file: wait for the one we opened.
// The anchored match tells "Page 1" from "Page 10".
const item = this.pageName.filter({
hasText: new RegExp(`^${escapeRegExp(pageName)}$`),
});
await expect(item).toBeAttached({ timeout: 30000 });
}
async sendPresenceMessage(fixture) {

View File

@ -55,14 +55,6 @@ async function setupWorkspace(workspacePage) {
"workspace/update-file-create-rect.json",
);
// The base WorkspacePage uses `this.pageName` (getByTestId("page-name")) as a
// readiness signal inside goToWorkspace. With 3 pages in the sidebar there are
// 3 matching elements, which violates Playwright's strict mode. Narrow the
// locator to the first occurrence so the internal readiness check can pass.
workspacePage.pageName = workspacePage.page
.getByTestId("page-name")
.first();
await workspacePage.goToWorkspace({
fileId: FILE_ID,
pageId: PAGE1_ID,