fix stubs playwright (#6274)

This commit is contained in:
Anthony Stirling
2026-04-30 12:37:15 +01:00
committed by GitHub
parent b552feaf28
commit d8c1ffa8ef
3 changed files with 47 additions and 5 deletions

View File

@@ -14,7 +14,25 @@ import type { Page, Route } from "@playwright/test";
* patterns.
*/
const ALL_TOOL_IDS = [
/**
* URL-path slugs for backend endpoints under `/api/v1/`. Used only to seed
* the stub responses for `endpoints-availability` and `endpoints-enabled`
* so the React app sees a populated map at startup.
*
* NOTE: this is *not* the frontend tool-registry IDs and several entries
* here have already drifted from the real registry endpoints (e.g. `merge`
* vs `merge-pdfs`, `compress` vs `compress-pdf`, `ocr` vs `ocr-pdf`).
* Tests still pass because the frontend's `useEndpointConfig` defaults
* absent keys to `enabled: true`, so a wrong key is functionally the same
* as a missing key — every endpoint reports enabled either way.
*
* TODO: derive this from `getAllApplicationEndpoints(registry, …)` instead
* of hand-maintaining it. That requires extracting endpoint metadata out of
* `useTranslatedToolRegistry` (currently a React hook with deep i18n + tool
* component imports — can't be called from Node-side Playwright setup) into
* a pure-data module both the hook and this helper can import.
*/
const ALL_BACKEND_ENDPOINTS = [
"pdf-to-img",
"img-to-pdf",
"pdf-to-word",
@@ -73,10 +91,28 @@ const ALL_TOOL_IDS = [
"remove-blanks",
"remove-annotations",
"remove-image",
"extract-pages",
"reorganize-pages",
"extract-images",
"add-stamp",
"add-attachments",
"change-metadata",
"overlay-pdfs",
"get-pdf-info",
"validate-signature",
"timestamp-pdf",
"replace-color",
"show-j-s",
"booklet-imposition",
"pdf-text-editor",
"form-fill",
"multi-tool",
"read",
"automate",
];
const DEFAULT_ENDPOINTS_AVAILABILITY = Object.fromEntries(
ALL_TOOL_IDS.map((k) => [k, { enabled: true }]),
ALL_BACKEND_ENDPOINTS.map((k) => [k, { enabled: true }]),
);
export interface MockAppApiOptions {

View File

@@ -49,7 +49,11 @@ export const test = base.extend<StubFixtures>({
await skipOnboarding(page);
await mockAppApis(page, stubOptions);
if (autoGoto !== false) {
await page.goto(autoGoto);
// waitUntil: 'domcontentloaded' avoids hanging on third-party CDN
// resources (iconify, posthog, stripe) the stub doesn't mock — the
// default 'load' event waits for ALL subresources, which can time out
// on slow runners and is rarely what tests actually need.
await page.goto(autoGoto, { waitUntil: "domcontentloaded" });
}
await use(page);
},

View File

@@ -90,8 +90,10 @@ async function verifyToolPageLoads(
page: import("@playwright/test").Page,
urlPath: string,
) {
await page.goto(urlPath);
await page.waitForLoadState("domcontentloaded");
// waitUntil: 'domcontentloaded' avoids hanging on third-party CDN resources
// (iconify, posthog, stripe) the stub doesn't mock — the default 'load'
// event waits for ALL subresources, which can time out on slow runners.
await page.goto(urlPath, { waitUntil: "domcontentloaded" });
// Page should not show an unhandled error / white screen
await expect(page.locator("body").first()).not.toBeEmpty();