e2e(standalone): use different mechanism for handling integration test

This commit is contained in:
Elian Doran
2026-04-19 18:24:25 +03:00
parent 2b07e880c7
commit f44a1f690a
6 changed files with 16 additions and 46 deletions

View File

@@ -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",

View File

@@ -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<string, string> = {
"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 {

View File

@@ -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) => {

View File

@@ -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<void> {
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,

View File

@@ -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 ?? ""),
}
}));

View File

@@ -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();