feat(examples): add with-electron (ENG-1585)

Merged
KA
19h ago
+575-17

What

examples/with-electron: the greeting app every example shares, built as a plain Electron app (no bundler) and tested with @e2e-dev/electron. It has three locator tests and two agent tests. npx e2e init my-app --example with-electron copies it, e2e.com/examples lists it, and the examples nightly runs it on Linux.

Electron example app with the greeting "hello, Ada!"

Why

Electron is the one engine with no example to start from. Every other platform has a with-* app.

How it works

  1. The app: examples/with-electron/main.js opens one window on src/index.html. src/renderer.js does the greeting with plain DOM, and the markup, styles, and copy match with-vite. e2e.config.ts sets engine: electron() with app: { appPath: '.' }. The tests are the with-vite tests, importing test from @e2e-dev/electron and calling app.open() with no path.
  2. Versions: the example pins the versions the pending changesets will publish, e2e ^0.26.0 and @e2e-dev/electron 0.0.1. npm has only a placeholder @e2e-dev/electron 0.0.0, so this should merge with or after that release. Until then, npm install in the example fails.
  3. The registry and init: an entry in examples/examples.json with an Electron icon in examples/icons/ and docs/images/examples/. The icon is the Simple Icons mark, recolored to the light cyan of Electron's logo so it shows on the dark site. A with-electron preset in packages/e2e/src/cli/init/examples.ts and a changeset for it.
  4. The nightly: .github/workflows/examples.yml packs @e2e-dev/electron, and .github/actions/example-packages swaps it in like the other engines. A new desktop job installs Chromium's system packages (Xvfb included) with the playwright-core version @e2e-dev/web pins, downloads the Electron binary with the electron package's install.js before the model key is in the environment, then runs the suite under xvfb-run. scripts/examples-nightly/ knows the desktop platform for the Slack summary.
  5. Docs: a card on docs/example-projects.mdx, the new name in the init --example list in docs/reference/cli.mdx, and a pointer to the example from the setup section of docs/electron.mdx. The CLI reference used to say only @e2e-dev/web and @e2e-dev/mobile get init's ranges; it now says the @e2e-dev/* packages, since adaptManifest rewrites every recorded sibling.

Verified

Ran it locally: yes

  • Built @e2e-dev/core, e2e, and @e2e-dev/electron from this branch, packed them, and installed the example in a scratch copy with the tarballs swapped in, the way the nightly does. macOS 26, Node 24, Electron 45.5.0.
  • npx tsc --noEmit passes. npx e2e run downloaded the Electron binary and passed the three locator tests. With AI_GATEWAY_API_KEY set, the two agent tests passed too:
 ✓ |electron| tests/deterministic.e2e.ts > shows the greeting form 2.00s
 ✓ |electron| tests/deterministic.e2e.ts > asks for a name when the field is empty 389ms
 ✓ |electron| tests/deterministic.e2e.ts > greets the name you type 390ms
 ✓ |electron| tests/agentic.e2e.ts > the agent gets a greeting 5.51s ai 17.1k tokens · 61% cached · $0.0019
 ✓ |electron| tests/agentic.e2e.ts > the agent finds the empty-name error 5.02s ai 17.3k tokens · 89% cached · $0.0010
  • The screenshot above is app.screenshot() from that run.
  • The built CLI lists the preset: e2e init x --example --yes names with-electron among the choices. I couldn't try the copy itself, since it downloads the folder from GitHub, where it doesn't exist until this merges.
  • Not run: the new nightly desktop job (it runs only on the schedule or a manual run), Linux, and Windows. No docs screenshots: the site renders from another repository. pnpm check and pnpm docs:check pass.

Summary by CodeRabbit

  • New Features
    • Added a cross-platform Electron desktop example featuring a greeting form and end-to-end tests.
    • Added with-electron to project initialization examples, with guidance for creating a new project and running tests.
  • Documentation
    • Updated the examples catalog and platform support information to include Electron, including its experimental status.
  • Chores
    • Added the Electron example to nightly testing and reporting, including desktop test results.