mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-14 10:34:06 +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
|
||||
|
||||
# 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 type { Page, Route } from "@playwright/test";
|
||||
import path from "node:path";
|
||||
import { DATABASE_CONFIGS } from "@app/services/indexedDBManager";
|
||||
|
||||
/** 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) =>
|
||||
route.fulfill({ json: serverFiles }),
|
||||
);
|
||||
await page.addInitScript((records) => {
|
||||
const open = window.indexedDB.open("stirling-pdf-files", 4);
|
||||
await page.addInitScript(
|
||||
({ records, dbVersion }) => {
|
||||
const open = window.indexedDB.open("stirling-pdf-files", dbVersion);
|
||||
open.onupgradeneeded = (event) => {
|
||||
const db = (event.target as IDBOpenDBRequest).result;
|
||||
// Create both `files` and `folders` stores on this DB.
|
||||
@@ -57,6 +59,9 @@ async function seedFiles(page: Page, files: SeedFile[]): Promise<void> {
|
||||
};
|
||||
open.onsuccess = () => {
|
||||
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 store = tx.objectStore("files");
|
||||
const now = Date.now();
|
||||
@@ -88,8 +93,11 @@ async function seedFiles(page: Page, files: SeedFile[]): Promise<void> {
|
||||
remoteShareToken: null,
|
||||
});
|
||||
}
|
||||
tx.oncomplete = () => db.close();
|
||||
};
|
||||
}, files);
|
||||
},
|
||||
{ records: files, dbVersion: DATABASE_CONFIGS.FILES.version },
|
||||
);
|
||||
}
|
||||
|
||||
async function stubStorageApis(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { test, expect } from "@app/tests/helpers/stub-test-base";
|
||||
import type { Page, Route } from "@playwright/test";
|
||||
import { DATABASE_CONFIGS } from "@app/services/indexedDBManager";
|
||||
|
||||
/** 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) =>
|
||||
route.fulfill({ json: serverFiles }),
|
||||
);
|
||||
await page.addInitScript((records) => {
|
||||
const open = window.indexedDB.open("stirling-pdf-files", 4);
|
||||
await page.addInitScript(
|
||||
({ records, dbVersion }) => {
|
||||
const open = window.indexedDB.open("stirling-pdf-files", dbVersion);
|
||||
open.onupgradeneeded = (event) => {
|
||||
const db = (event.target as IDBOpenDBRequest).result;
|
||||
// Create both `files` and `folders` stores on this DB.
|
||||
@@ -57,6 +59,9 @@ async function seedFiles(page: Page, files: SeedFile[]): Promise<void> {
|
||||
};
|
||||
open.onsuccess = () => {
|
||||
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 store = tx.objectStore("files");
|
||||
const now = Date.now();
|
||||
@@ -89,8 +94,11 @@ async function seedFiles(page: Page, files: SeedFile[]): Promise<void> {
|
||||
remoteShareToken: null,
|
||||
});
|
||||
}
|
||||
tx.oncomplete = () => db.close();
|
||||
};
|
||||
}, files);
|
||||
},
|
||||
{ records: files, dbVersion: DATABASE_CONFIGS.FILES.version },
|
||||
);
|
||||
}
|
||||
|
||||
/** Stub the storage + config endpoints hit on mount. */
|
||||
|
||||
Reference in New Issue
Block a user