Skip to content

Commit d8c1ffa

Browse files
authored
fix stubs playwright (Stirling-Tools#6274)
1 parent b552fea commit d8c1ffa

3 files changed

Lines changed: 47 additions & 5 deletions

File tree

frontend/src/core/tests/helpers/api-stubs.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,25 @@ import type { Page, Route } from "@playwright/test";
1414
* patterns.
1515
*/
1616

17-
const ALL_TOOL_IDS = [
17+
/**
18+
* URL-path slugs for backend endpoints under `/api/v1/`. Used only to seed
19+
* the stub responses for `endpoints-availability` and `endpoints-enabled`
20+
* so the React app sees a populated map at startup.
21+
*
22+
* NOTE: this is *not* the frontend tool-registry IDs and several entries
23+
* here have already drifted from the real registry endpoints (e.g. `merge`
24+
* vs `merge-pdfs`, `compress` vs `compress-pdf`, `ocr` vs `ocr-pdf`).
25+
* Tests still pass because the frontend's `useEndpointConfig` defaults
26+
* absent keys to `enabled: true`, so a wrong key is functionally the same
27+
* as a missing key — every endpoint reports enabled either way.
28+
*
29+
* TODO: derive this from `getAllApplicationEndpoints(registry, …)` instead
30+
* of hand-maintaining it. That requires extracting endpoint metadata out of
31+
* `useTranslatedToolRegistry` (currently a React hook with deep i18n + tool
32+
* component imports — can't be called from Node-side Playwright setup) into
33+
* a pure-data module both the hook and this helper can import.
34+
*/
35+
const ALL_BACKEND_ENDPOINTS = [
1836
"pdf-to-img",
1937
"img-to-pdf",
2038
"pdf-to-word",
@@ -73,10 +91,28 @@ const ALL_TOOL_IDS = [
7391
"remove-blanks",
7492
"remove-annotations",
7593
"remove-image",
94+
"extract-pages",
95+
"reorganize-pages",
96+
"extract-images",
97+
"add-stamp",
98+
"add-attachments",
99+
"change-metadata",
100+
"overlay-pdfs",
101+
"get-pdf-info",
102+
"validate-signature",
103+
"timestamp-pdf",
104+
"replace-color",
105+
"show-j-s",
106+
"booklet-imposition",
107+
"pdf-text-editor",
108+
"form-fill",
109+
"multi-tool",
110+
"read",
111+
"automate",
76112
];
77113

78114
const DEFAULT_ENDPOINTS_AVAILABILITY = Object.fromEntries(
79-
ALL_TOOL_IDS.map((k) => [k, { enabled: true }]),
115+
ALL_BACKEND_ENDPOINTS.map((k) => [k, { enabled: true }]),
80116
);
81117

82118
export interface MockAppApiOptions {

frontend/src/core/tests/helpers/stub-test-base.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ export const test = base.extend<StubFixtures>({
4949
await skipOnboarding(page);
5050
await mockAppApis(page, stubOptions);
5151
if (autoGoto !== false) {
52-
await page.goto(autoGoto);
52+
// waitUntil: 'domcontentloaded' avoids hanging on third-party CDN
53+
// resources (iconify, posthog, stripe) the stub doesn't mock — the
54+
// default 'load' event waits for ALL subresources, which can time out
55+
// on slow runners and is rarely what tests actually need.
56+
await page.goto(autoGoto, { waitUntil: "domcontentloaded" });
5357
}
5458
await use(page);
5559
},

frontend/src/core/tests/stubbed/all-tool-pages-load.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ async function verifyToolPageLoads(
9090
page: import("@playwright/test").Page,
9191
urlPath: string,
9292
) {
93-
await page.goto(urlPath);
94-
await page.waitForLoadState("domcontentloaded");
93+
// waitUntil: 'domcontentloaded' avoids hanging on third-party CDN resources
94+
// (iconify, posthog, stripe) the stub doesn't mock — the default 'load'
95+
// event waits for ALL subresources, which can time out on slow runners.
96+
await page.goto(urlPath, { waitUntil: "domcontentloaded" });
9597

9698
// Page should not show an unhandled error / white screen
9799
await expect(page.locator("body").first()).not.toBeEmpty();

0 commit comments

Comments
 (0)