Skip to content

5.3 Electron E2E Tests

coding man edited this page Nov 4, 2026 · 1 revision

Electron E2E Tests

Relevant source files

The following files were used as context for generating this wiki page:

Purpose and Scope

This page documents the implementation and architecture of the Electron end-to-end (E2E) test suite located in tests/e2e/electron.spec.js. The test suite validates the desktop-specific behaviors of VariantScope, including application startup, window lifecycle, security isolation, strict Content Security Policy (CSP) enforcement, host allowlisting, IPC bridge exposure, menu interactions, offline mode, and folder hierarchy management.

Sources: tests/e2e/electron.spec.js:1-173


Test Environment and Launch Lifecycle

The E2E tests are executed using Playwright’s Electron integration (@playwright/test) tests/e2e/electron.spec.js:4. To ensure isolation, each test run initializes a throwaway user-data directory using mkdtempSync and runs the application in background mode (VARIANTSCOPE_BACKGROUND: '1') tests/e2e/electron.spec.js:1-2, tests/e2e/electron.spec.js:13, tests/e2e/electron.spec.js:28.

On Linux CI runners lacking a dedicated GPU, the test harness automatically injects software WebGL flags (--use-angle=swiftshader, --enable-unsafe-swiftshader, and --ignore-gpu-blocklist) tests/e2e/electron.spec.js:19-23.

graph TD
  A["Test Suite Setup"] --> B["mkdtempSync(vs-e2e-ud-)"]
  B --> C["electron.launch()"]
  C --> D["VARIANTSCOPE_BACKGROUND=1"]
  C --> E["SOFTWARE_WEBGL Flags"]
  D --> F["First Window & Load State"]
  E --> F
  F --> G["app.firstWindow()"]

  style A fill:none,stroke:#000,stroke-width:1px
  style G fill:none,stroke:#000,stroke-width:1px
Loading

Sources: tests/e2e/electron.spec.js:1-30


Security Architecture Assertions

The test suite enforces rigorous security guarantees at the Chromium and Electron layers, validating BrowserWindow web preferences, preloaded bridge APIs, CSP rules, and navigation restrictions.

WebPreferences & Preload Bridge

The test asserts that context isolation is enabled, node integration is disabled, sandboxing is active, and web security is fully enforced tests/e2e/electron.spec.js:85-100. Furthermore, it verifies that Node globals are undefined inside the renderer process (require, process, module, Buffer), and that exactly six API methods are exposed on window.api tests/e2e/electron.spec.js:101-111.

graph TD
  subgraph "Renderer Process"
    A["window.api"] --> B["deleteCache"]
    A --> C["fetchJson"]
    A --> D["getAppInfo"]
    A --> E["listCache"]
    A --> F["openExternal"]
    A --> G["saveFile"]
  end
  subgraph "WebPreferences"
    H["contextIsolation: true"]
    I["nodeIntegration: false"]
    J["sandbox: true"]
    K["webSecurity: true"]
  end

  style A fill:none,stroke:#000,stroke-width:1px
  style H fill:none,stroke:#000,stroke-width:1px
Loading

Sources: tests/e2e/electron.spec.js:85-112

CSP and Network Isolation

The test suite evaluates CSP restrictions by injecting dynamic inline scripts, string-based setTimeout evaluators, and unauthorized network fetch requests to external origins like https://rest.uniprot.org/ tests/e2e/electron.spec.js:114-138. All attempts are blocked by the policy tests/e2e/electron.spec.js:139. External navigations and window.open calls to arbitrary domains are intercepted and cancelled by the main process tests/e2e/electron.spec.js:142-154.

Sources: tests/e2e/electron.spec.js:114-160


Host Allowlist and IPC Validation

The application main process implements strict host allowlisting via allowlist.js 4.2. The E2E tests confirm that unauthorized hosts, HTTP protocols (instead of HTTPS), and malformed arguments passed to window.api.fetchJson() are rejected with descriptive error messages tests/e2e/electron.spec.js:162-173.

Sources: tests/e2e/electron.spec.js:162-173


Menu Interaction and Desktop Integration

Application menus are tested via the clickMenu helper function, which evaluates the application menu tree inside the main process via app.evaluate() and triggers registered click handlers by item label search tests/e2e/electron.spec.js:33-47.

Sources: tests/e2e/electron.spec.js:33-47


Clone this wiki locally