mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +02:00
Fix intermittently failing Playwright tests in main (#6541)
# Description of Changes [#6474](https://github.com/Stirling-Tools/Stirling-PDF/pull/6474) updated the IndexedDB schema number to v9, but a couple of Playwright tests were explicitly creating a DB in v4 schema, which then caused inconsistently failing tests because the DB upgrade process is asynchronous and sometimes was too slow to upgrade, causing the test to get into an invalid state. Also fixes the screenshots directory exclusion since the frontend folder was restructured.
This commit is contained in:
+1
-1
@@ -279,4 +279,4 @@ docs/type3/signatures/
|
|||||||
*.playwright-mcp.png
|
*.playwright-mcp.png
|
||||||
|
|
||||||
# Local screenshot artifacts from *-screenshots.spec.ts
|
# Local screenshot artifacts from *-screenshots.spec.ts
|
||||||
frontend/screenshots/
|
frontend/editor/screenshots/
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { test, expect } from "@app/tests/helpers/stub-test-base";
|
import { test, expect } from "@app/tests/helpers/stub-test-base";
|
||||||
import type { Page, Route } from "@playwright/test";
|
import type { Page, Route } from "@playwright/test";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
|
import { DATABASE_CONFIGS } from "@app/services/indexedDBManager";
|
||||||
|
|
||||||
/** Screenshot review of /files surfaces; dumps PNGs to screenshots/files-page. */
|
/** Screenshot review of /files surfaces; dumps PNGs to screenshots/files-page. */
|
||||||
|
|
||||||
@@ -34,8 +35,9 @@ async function seedFiles(page: Page, files: SeedFile[]): Promise<void> {
|
|||||||
await page.route("**/api/v1/storage/files", (route: Route) =>
|
await page.route("**/api/v1/storage/files", (route: Route) =>
|
||||||
route.fulfill({ json: serverFiles }),
|
route.fulfill({ json: serverFiles }),
|
||||||
);
|
);
|
||||||
await page.addInitScript((records) => {
|
await page.addInitScript(
|
||||||
const open = window.indexedDB.open("stirling-pdf-files", 4);
|
({ records, dbVersion }) => {
|
||||||
|
const open = window.indexedDB.open("stirling-pdf-files", dbVersion);
|
||||||
open.onupgradeneeded = (event) => {
|
open.onupgradeneeded = (event) => {
|
||||||
const db = (event.target as IDBOpenDBRequest).result;
|
const db = (event.target as IDBOpenDBRequest).result;
|
||||||
// Create both `files` and `folders` stores on this DB.
|
// Create both `files` and `folders` stores on this DB.
|
||||||
@@ -57,6 +59,9 @@ async function seedFiles(page: Page, files: SeedFile[]): Promise<void> {
|
|||||||
};
|
};
|
||||||
open.onsuccess = () => {
|
open.onsuccess = () => {
|
||||||
const db = open.result;
|
const db = open.result;
|
||||||
|
// Yield the connection if the app ever needs to upgrade, and drop it
|
||||||
|
// once the writes commit, so the seed never blocks the app's open.
|
||||||
|
db.onversionchange = () => db.close();
|
||||||
const tx = db.transaction("files", "readwrite");
|
const tx = db.transaction("files", "readwrite");
|
||||||
const store = tx.objectStore("files");
|
const store = tx.objectStore("files");
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
@@ -88,8 +93,11 @@ async function seedFiles(page: Page, files: SeedFile[]): Promise<void> {
|
|||||||
remoteShareToken: null,
|
remoteShareToken: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
tx.oncomplete = () => db.close();
|
||||||
};
|
};
|
||||||
}, files);
|
},
|
||||||
|
{ records: files, dbVersion: DATABASE_CONFIGS.FILES.version },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function stubStorageApis(
|
async function stubStorageApis(
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { test, expect } from "@app/tests/helpers/stub-test-base";
|
import { test, expect } from "@app/tests/helpers/stub-test-base";
|
||||||
import type { Page, Route } from "@playwright/test";
|
import type { Page, Route } from "@playwright/test";
|
||||||
|
import { DATABASE_CONFIGS } from "@app/services/indexedDBManager";
|
||||||
|
|
||||||
/** Stubbed coverage for the /files page UI invariants. */
|
/** Stubbed coverage for the /files page UI invariants. */
|
||||||
|
|
||||||
@@ -34,8 +35,9 @@ async function seedFiles(page: Page, files: SeedFile[]): Promise<void> {
|
|||||||
await page.route("**/api/v1/storage/files", (route: Route) =>
|
await page.route("**/api/v1/storage/files", (route: Route) =>
|
||||||
route.fulfill({ json: serverFiles }),
|
route.fulfill({ json: serverFiles }),
|
||||||
);
|
);
|
||||||
await page.addInitScript((records) => {
|
await page.addInitScript(
|
||||||
const open = window.indexedDB.open("stirling-pdf-files", 4);
|
({ records, dbVersion }) => {
|
||||||
|
const open = window.indexedDB.open("stirling-pdf-files", dbVersion);
|
||||||
open.onupgradeneeded = (event) => {
|
open.onupgradeneeded = (event) => {
|
||||||
const db = (event.target as IDBOpenDBRequest).result;
|
const db = (event.target as IDBOpenDBRequest).result;
|
||||||
// Create both `files` and `folders` stores on this DB.
|
// Create both `files` and `folders` stores on this DB.
|
||||||
@@ -57,6 +59,9 @@ async function seedFiles(page: Page, files: SeedFile[]): Promise<void> {
|
|||||||
};
|
};
|
||||||
open.onsuccess = () => {
|
open.onsuccess = () => {
|
||||||
const db = open.result;
|
const db = open.result;
|
||||||
|
// Yield the connection if the app ever needs to upgrade, and drop it
|
||||||
|
// once the writes commit, so the seed never blocks the app's open.
|
||||||
|
db.onversionchange = () => db.close();
|
||||||
const tx = db.transaction("files", "readwrite");
|
const tx = db.transaction("files", "readwrite");
|
||||||
const store = tx.objectStore("files");
|
const store = tx.objectStore("files");
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
@@ -89,8 +94,11 @@ async function seedFiles(page: Page, files: SeedFile[]): Promise<void> {
|
|||||||
remoteShareToken: null,
|
remoteShareToken: null,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
tx.oncomplete = () => db.close();
|
||||||
};
|
};
|
||||||
}, files);
|
},
|
||||||
|
{ records: files, dbVersion: DATABASE_CONFIGS.FILES.version },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Stub the storage + config endpoints hit on mount. */
|
/** Stub the storage + config endpoints hit on mount. */
|
||||||
|
|||||||
Reference in New Issue
Block a user