From 215094ea142e7681b33306c5104cf37fccdfae84 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Wed, 10 Jun 2026 17:23:01 -0700 Subject: [PATCH] Expose E2E store via build mode --- .env.e2e | 3 --- src/preload/e2e-config.ts | 12 ++++++++++-- tests/e2e/AGENTS.md | 2 +- tests/e2e/global-setup.ts | 6 +++--- 4 files changed, 14 insertions(+), 9 deletions(-) delete mode 100644 .env.e2e diff --git a/.env.e2e b/.env.e2e deleted file mode 100644 index 99829ff6c..000000000 --- a/.env.e2e +++ /dev/null @@ -1,3 +0,0 @@ -# Why: enables window.__store in the renderer build so E2E tests can read -# Zustand state directly instead of fragile DOM scraping. -VITE_EXPOSE_STORE=true diff --git a/src/preload/e2e-config.ts b/src/preload/e2e-config.ts index 29b6f09c4..079bdceb1 100644 --- a/src/preload/e2e-config.ts +++ b/src/preload/e2e-config.ts @@ -2,15 +2,23 @@ import { createE2EConfig } from '../shared/e2e-config' const preloadEnv = ( import.meta as ImportMeta & { - env?: { VITE_EXPOSE_STORE?: boolean } + env?: { MODE?: string; VITE_EXPOSE_STORE?: boolean | string } } ).env +function isEnvFlagEnabled(value: boolean | string | undefined): boolean { + return value === true || value === 'true' +} + +// Why: `--mode e2e` must be enough for manual rebuilds used with SKIP_BUILD=1; +// keeping this out of a root .env file makes the test-only toggle less visible. +const exposeStore = preloadEnv?.MODE === 'e2e' || isEnvFlagEnabled(preloadEnv?.VITE_EXPOSE_STORE) + // Why: preload is the renderer's audited bridge into Electron startup state. // Renderer code should consume a typed config object from this bridge instead // of reading test-only env vars directly. export const preloadE2EConfig = createE2EConfig({ headless: process.env.ORCA_E2E_HEADLESS === '1', - exposeStore: preloadEnv?.VITE_EXPOSE_STORE, + exposeStore, userDataDir: process.env.ORCA_E2E_USER_DATA_DIR ?? null }) diff --git a/tests/e2e/AGENTS.md b/tests/e2e/AGENTS.md index dab76872c..f83b31870 100644 --- a/tests/e2e/AGENTS.md +++ b/tests/e2e/AGENTS.md @@ -2,7 +2,7 @@ ## Build the App With `--mode e2e` Before Running Tests -E2E tests read Zustand state via `window.__store`. That global is only assigned when the renderer is built with `VITE_EXPOSE_STORE=true`, which is set by `.env.e2e` and only applied when you pass `--mode e2e` to `electron-vite build`. A plain `pnpm build` or `pnpm build:electron-vite` produces an `out/` tree **without** the store exposed, so reusing it with `SKIP_BUILD=1` makes every spec hang on `waitForFunction(() => Boolean(window.__store))` and time out at 30s. +E2E tests read Zustand state via `window.__store`. That global is only assigned when the preload bundle is built in `e2e` mode, which is applied when you pass `--mode e2e` to `electron-vite build`. A plain `pnpm build` or `pnpm build:electron-vite` produces an `out/` tree **without** the store exposed, so reusing it with `SKIP_BUILD=1` makes every spec hang on `waitForFunction(() => Boolean(window.__store))` and time out at 30s. - Default path: `pnpm run test:e2e` — `globalSetup` runs `electron-vite build --mode e2e` for you. - Fast iteration: `pnpm exec electron-vite build --mode e2e` once, then `SKIP_BUILD=1 pnpm run test:e2e …`. diff --git a/tests/e2e/global-setup.ts b/tests/e2e/global-setup.ts index ef029fa79..5a70a8bc2 100644 --- a/tests/e2e/global-setup.ts +++ b/tests/e2e/global-setup.ts @@ -28,11 +28,11 @@ export default function globalSetup(): void { if (process.env.SKIP_BUILD && existsSync(outMain)) { console.log('[e2e] SKIP_BUILD set and out/main/index.js exists — skipping build') } else { - // Why: --mode e2e loads .env.e2e which sets VITE_EXPOSE_STORE=true. This - // makes window.__store available in the renderer build so tests can read - // Zustand state directly instead of fragile DOM scraping. + // Why: --mode e2e is the build-time signal that exposes window.__store; + // the explicit env var keeps older local overrides working too. console.log('[e2e] Building Electron app with electron-vite build --mode e2e...') execSync('npx electron-vite build --mode e2e', { + env: { ...process.env, VITE_EXPOSE_STORE: 'true' }, cwd: root, stdio: 'inherit', // Why: Windows renderer builds can exceed 120s on local/CI hosts even