feat(e2e): add an Electron engine to e2e init

Merged
OK
1d ago
+123-26

What

e2e init has an Electron engine: npx e2e init --yes --engine electron, or pick it at the prompt.

export default {
  // appPath is your app's directory or main script.
  targets: [{ name: 'electron', engine: electron(), app: { appPath: '.' } }],
} satisfies E2EConfig;

It also writes an example test and adds @e2e-dev/electron to the dev dependencies. A CI pipeline init writes leaves the Electron target out and says why.

Why

The Electron guide and the Playwright migration guide both told users to write the config by hand, because init only knew web and mobile.

How it works

  1. Preset. A third entry in getEnginePresets with the target, the example test, and the dependency (packages/e2e/src/cli/init/engines.ts:109). The --engine help and its validation read the presets, so both list electron with no other change.
  2. Version. write-sibling-versions.ts records @e2e-dev/electron, so a released runner pins the engine version it shipped with, as it does for web and mobile.
  3. CI. An Electron app needs a display, and no job init writes has one. ciJobs leaves a target of platform electron out of every job, and names the web job's targets with --target once it leaves one out (packages/e2e/src/cli/init/ci.ts:235). writePipeline warns with the docs link for xvfb-run (packages/e2e/src/cli/init.ts:777).
  4. No pipeline for Electron alone. A new config with only the Electron engine is not asked about CI, and --ci there gets the existing "the project has none" warning (init.ts:465).
  5. A config that does not load. The fallback that runs every target in one web job no longer applies when the project also depends on @e2e-dev/electron, since that job would start the Electron target with no display (init.ts:770).

Decision a reviewer may ask about: no Electron CI job yet. It means an xvfb-run step in each of the pipeline templates, which is a follow-up.

Release order, owner's call: @e2e-dev/electron is at 0.0.0 and not on npm yet. If its first publish fails while e2e publishes, init --engine electron writes a dependency that does not install. Merge this after the engine's first release, or keep an eye on that publish.

Issue

None.

Verified

Ran it locally: yes

Surface: the built CLI in a scratch project.

$ e2e init --yes --engine web,electron --gateway none --ci github-actions
●  Add dev dependencies: e2e@^0.25.0, @e2e-dev/web@^0.17.0, @e2e-dev/electron@^0.0.0, @e2e-dev/core@^0.25.0
◆  Created e2e.config.ts
◆  Created tests/web.e2e.ts
◆  Created tests/electron.e2e.ts
▲  No CI job runs electron: an Electron app needs a display, so run it under xvfb-run on Linux; see https://e2e.com/docs/electron#run-in-ci-on-linux
◆  Created .github/workflows/e2e.yml (GitHub Actions)

.github/workflows/e2e.yml:  run: npx e2e run --target web --reporter list,junit

The example test init --engine electron writes passes against the Electron testbed app:

✓ |electron| tests/example.e2e.ts > app opens 351ms
packages/e2e  cli-init, init-ci, cli    Tests  353 passed (353)
packages/e2e  integration cli-init      Tests  23 passed (23)
pnpm check                              exit 0 (run with this change and #2439 together)

^0.0.0 in the output above is the unreleased version in this checkout; a released runner writes the version it shipped with.

Summary by CodeRabbit

  • New Features
    • e2e init supports Electron projects, generating an Electron configuration and example test.
    • Electron is available as a selectable engine and does not require an APP_URL to get started.
  • Bug Fixes
    • CI setup excludes Electron targets from generated jobs. Mixed projects retain jobs for supported targets, while Electron-only setups receive a notice that no pipeline was generated.
  • Documentation
    • Updated setup, migration, CLI, and telemetry guidance, including app-path configuration, Linux display requirements, and per-engine example tests.