desktop-testing-electron
Electron Testing Patterns
Quick Guide: Use Playwright's
_electron.launch()for E2E tests -- it controls the full app via CDP. Unit test main process code (IPC handlers, business logic) with your test runner by mocking theelectronmodule. Test preload scripts by mockingcontextBridgeandipcRenderer. Spectron is dead since Electron 24 -- Playwright and WebDriverIO are the replacements. Run Electron tests on headless Linux CI withxvfb-runor thexvfb-maybewrapper.
<critical_requirements>
CRITICAL: Before Using This Skill
All code must follow project conventions in CLAUDE.md (kebab-case, named exports, import ordering,
import type, named constants)
(You MUST await electronApp.close() in test teardown -- leaked Electron processes break CI and consume resources)
(You MUST mock the electron module in unit tests -- Electron APIs are only available inside the Electron runtime)
(You MUST use xvfb-run or xvfb-maybe for headless Linux CI -- Electron requires a display server)
(You MUST stub native dialogs in E2E tests -- showOpenDialog/showSaveDialog block the process and cannot be interacted with by Playwright)