Skip to content

Build your personal knowledge base with Trilium Notes

test(e2e): let the tab-order test see the request it waits on

Elian Doran8340695d2b3f
diff --git a/packages/trilium-e2e/src/layout/tab_bar.spec.ts b/packages/trilium-e2e/src/layout/tab_bar.spec.ts
index 31fa4755f5..9e80524746 100644
--- a/packages/trilium-e2e/src/layout/tab_bar.spec.ts
+++ b/packages/trilium-e2e/src/layout/tab_bar.spec.ts
@@ -64,6 +64,9 @@ test("Can drag tab to new window", async ({ page, context }, testInfo) => {
test("Tabs are restored in right order", async ({ page, context }) => {
const app = new App(page, context);
await app.goto();
+ // The barrier below waits on the recent-notes request itself, which the standalone build
+ // would otherwise answer without issuing one.
+ await app.observeApiRequests();
// Open three tabs.
await app.closeAllTabs();
diff --git a/packages/trilium-e2e/src/support/app.ts b/packages/trilium-e2e/src/support/app.ts
index 74789b4dd3..519fb0b825 100644
--- a/packages/trilium-e2e/src/support/app.ts
+++ b/packages/trilium-e2e/src/support/app.ts
@@ -97,6 +97,22 @@ export default class App {
}
}
+ /**
+ * Sends this tab's API calls through the service worker, where Playwright can see them.
+ *
+ * Standalone's leader tab answers its own calls from the in-page SQLite worker
+ * (`standaloneApi.localFetch`), so they never reach the network stack and
+ * `page.waitForResponse()` never fires. Call this in a test that waits on a request rather than
+ * on what the request changes. Does nothing on the server build, which has no `standaloneApi`,
+ * and lasts until the next navigation re-runs standalone's bootstrap.
+ */
+ async observeApiRequests() {
+ await this.page.evaluate(() => {
+ const standaloneApi = (window as unknown as { standaloneApi?: { localFetch?: unknown } }).standaloneApi;
+ delete standaloneApi?.localFetch;
+ });
+ }
+
async goToNoteInNewTab(noteTitle: string) {
const autocomplete = this.currentNoteSplit.locator(".note-autocomplete");
await expect(autocomplete).toBeVisible();