From f44a1f690a0ef03944f4a21f1ec66f6db865eb27 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 19 Apr 2026 18:24:25 +0300 Subject: [PATCH] e2e(standalone): use different mechanism for handling integration test --- apps/client-standalone/playwright.config.ts | 3 --- .../src/lightweight/platform_provider.ts | 7 ++++++- apps/client-standalone/src/local-bridge.ts | 20 +------------------ .../src/local-server-worker.ts | 12 ++++++----- apps/client-standalone/vite.config.mts | 1 + packages/trilium-e2e/src/support/app.ts | 19 +----------------- 6 files changed, 16 insertions(+), 46 deletions(-) diff --git a/apps/client-standalone/playwright.config.ts b/apps/client-standalone/playwright.config.ts index 8c12b4ef04..c93c99df9d 100644 --- a/apps/client-standalone/playwright.config.ts +++ b/apps/client-standalone/playwright.config.ts @@ -3,9 +3,6 @@ import { createBaseConfig } from "../../packages/trilium-e2e/src/base-config"; const port = process.env["TRILIUM_PORT"] ?? "8082"; const baseURL = process.env["BASE_URL"] || `http://127.0.0.1:${port}`; -// Standalone needs the integrationTest query param to load the test fixture DB -process.env["TRILIUM_E2E_QUERY_PARAMS"] = "integrationTest=memory"; - export default createBaseConfig({ appDir: __dirname, projectName: "standalone", diff --git a/apps/client-standalone/src/lightweight/platform_provider.ts b/apps/client-standalone/src/lightweight/platform_provider.ts index 6da914e806..9c5e2f1186 100644 --- a/apps/client-standalone/src/lightweight/platform_provider.ts +++ b/apps/client-standalone/src/lightweight/platform_provider.ts @@ -1,10 +1,12 @@ import type { PlatformProvider } from "@triliumnext/core"; +// Build-time constant injected by Vite (see `define` in vite.config.mts). +declare const __TRILIUM_INTEGRATION_TEST__: string; + /** Maps URL query parameter names to TRILIUM_ environment variable names. */ const QUERY_TO_ENV: Record = { "safeMode": "TRILIUM_SAFE_MODE", "startNoteId": "TRILIUM_START_NOTE_ID", - "integrationTest": "TRILIUM_INTEGRATION_TEST", }; export default class StandalonePlatformProvider implements PlatformProvider { @@ -21,6 +23,9 @@ export default class StandalonePlatformProvider implements PlatformProvider { this.envMap[envKey] = params.get(queryKey) || "true"; } } + if (__TRILIUM_INTEGRATION_TEST__) { + this.envMap["TRILIUM_INTEGRATION_TEST"] = __TRILIUM_INTEGRATION_TEST__; + } } crash(message: string): void { diff --git a/apps/client-standalone/src/local-bridge.ts b/apps/client-standalone/src/local-bridge.ts index df57db2e84..dbd7e326d2 100644 --- a/apps/client-standalone/src/local-bridge.ts +++ b/apps/client-standalone/src/local-bridge.ts @@ -6,28 +6,10 @@ function showFatalErrorDialog(message: string) { alert(message); } -/** - * Collects query params from both `location.search` and the hash's "?..." - * suffix. The SPA uses hash-based routing, so flags like `?integrationTest=memory` - * often end up after the `#` (e.g. `/#root/foo?integrationTest=memory`) and - * are invisible to `location.search`. - */ -function collectQueryString(): string { - const params = new URLSearchParams(location.search); - const hashQueryIndex = location.hash.indexOf("?"); - if (hashQueryIndex >= 0) { - const hashParams = new URLSearchParams(location.hash.substring(hashQueryIndex + 1)); - for (const [key, value] of hashParams) { - if (!params.has(key)) params.set(key, value); - } - } - return params.toString(); -} - export function startLocalServerWorker() { if (localWorker) return localWorker; localWorker = new LocalServerWorker(); - localWorker.postMessage({ type: "INIT", queryString: collectQueryString() }); + localWorker.postMessage({ type: "INIT", queryString: location.search }); // Handle worker errors during initialization localWorker.onerror = (event) => { diff --git a/apps/client-standalone/src/local-server-worker.ts b/apps/client-standalone/src/local-server-worker.ts index 5ea83dcbec..420cb46a7f 100644 --- a/apps/client-standalone/src/local-server-worker.ts +++ b/apps/client-standalone/src/local-server-worker.ts @@ -48,6 +48,9 @@ console.log("[Worker] Error handlers installed, loading modules..."); // ============================================================================= import type { BrowserRouter } from './lightweight/browser_router'; +// Build-time constant injected by Vite (see `define` in vite.config.mts). +declare const __TRILIUM_INTEGRATION_TEST__: string; + // ============================================================================= // MODULE STATE (populated by dynamic imports) // ============================================================================= @@ -169,11 +172,10 @@ async function initialize(): Promise { console.log("[Worker] Initializing SQLite WASM..."); await sqlProvider!.initWasm(); - // Check if we're in integration test mode (loaded via ?integrationTest=memory) - const params = new URLSearchParams(queryString); - const integrationTestMode = params.get("integrationTest"); - - console.log("Starting with integration test mode ", integrationTestMode); + // Integration test mode is baked in at build time via the + // __TRILIUM_INTEGRATION_TEST__ Vite define (derived from the + // TRILIUM_INTEGRATION_TEST env var when the bundle was built). + const integrationTestMode = __TRILIUM_INTEGRATION_TEST__; if (integrationTestMode === "memory") { // Wipe OPFS so e2e runs start from a clean slate (stale DB, logs, diff --git a/apps/client-standalone/vite.config.mts b/apps/client-standalone/vite.config.mts index af90d334a8..0fa1dfbe96 100644 --- a/apps/client-standalone/vite.config.mts +++ b/apps/client-standalone/vite.config.mts @@ -298,5 +298,6 @@ export default defineConfig(() => ({ }, define: { "process.env.IS_PREACT": JSON.stringify("true"), + __TRILIUM_INTEGRATION_TEST__: JSON.stringify(process.env.TRILIUM_INTEGRATION_TEST ?? ""), } })); \ No newline at end of file diff --git a/packages/trilium-e2e/src/support/app.ts b/packages/trilium-e2e/src/support/app.ts index 8a09db7cdc..230721a3ab 100644 --- a/packages/trilium-e2e/src/support/app.ts +++ b/packages/trilium-e2e/src/support/app.ts @@ -7,14 +7,6 @@ export interface GotoOpts { preserveTabs?: boolean; } -/** - * Extra query parameters to append to all navigations (e.g. "integrationTest=memory"). - * Set via the TRILIUM_E2E_QUERY_PARAMS environment variable. - */ -function getDefaultQueryParams(): string { - return process.env["TRILIUM_E2E_QUERY_PARAMS"] ?? ""; -} - export function getBaseUrl(): string { const port = process.env["TRILIUM_PORT"] ?? "8082"; return process.env["BASE_URL"] || `http://127.0.0.1:${port}`; @@ -69,19 +61,10 @@ export default class App { url = "/"; } - // Append default query params (e.g. ?integrationTest=memory for standalone) - const extraParams = getDefaultQueryParams(); - if (extraParams) { - const separator = url.includes("?") ? "&" : "?"; - url = `${url}${separator}${extraParams}`; - } - - const isRoot = url === "/" || url.startsWith("/?"); - await this.page.goto(url, { waitUntil: "networkidle", timeout: 30_000 }); // Wait for the page to load. - if (isRoot) { + if (url === "/") { await expect(this.page.locator(".tree", { hasText: "Trilium Integration Test" })).toBeVisible(); if (!preserveTabs) { await this.closeAllTabs();