Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a92c60f
fix(electron): probe the PATH's ffmpeg once when it has none
kdy1 Nov 29, 2026
a2ce261
docs(electron): give the order the engine finds ffmpeg in
kdy1 Nov 29, 2026
06ccb28
fix(electron): download the Electron binary once when two runs start …
kdy1 Nov 29, 2026
a9ff846
fix(electron): say when a run waits on the Electron install lock, and…
kdy1 Nov 29, 2026
31d02dd
fix(electron): hold the install lock until a cancelled download's ins…
kdy1 Nov 29, 2026
5217b25
fix(electron): report a failed ffmpeg download as ELECTRON_INSTALL_FA…
kdy1 Nov 29, 2026
040d2c3
fix(electron): read an app's package.json that starts with a byte ord…
kdy1 Nov 29, 2026
e277c19
fix(electron): put back a fresh install lock another run took while t…
kdy1 Nov 29, 2026
081d0a7
test(electron): check the install lock's path with the platform's sep…
kdy1 Nov 29, 2026
6844b68
chore(electron): add a changeset for the install lock and ffmpeg fixes
kdy1 Nov 29, 2026
9ffff0e
docs(electron): leave the order the engine finds ffmpeg in to the ref…
kdy1 Nov 29, 2026
663c7f4
fix(electron): remove a stale install lock under a takeover lock inst…
kdy1 Nov 29, 2026
50702ff
fix(electron): remove only the install lock this run took when its do…
kdy1 Nov 29, 2026
ffe4ffd
test(electron): cancel the download once the fixture's install.js lis…
kdy1 Nov 29, 2026
c11e499
docs(electron): say a failed ffmpeg download fails the recording in t…
kdy1 Nov 29, 2026
de353b8
revert(electron): remove the install lock by path again when the down…
kdy1 Nov 29, 2026
5bfd9e1
fix(electron): leave the Electron download lock to #2470
kdy1 Nov 29, 2026
03aea09
chore(electron): describe only the ffmpeg and package.json fixes in a…
kdy1 Nov 29, 2026
05604a8
test(electron): check that a machine with no ffmpeg is probed once an…
kdy1 Nov 29, 2026
b5fbb8b
chore(electron): say the PATH's ffmpeg is checked once per process in…
kdy1 Nov 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/electron-ffmpeg-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@e2e-dev/electron': patch
---

A failed download of ffmpeg for video fails with `ELECTRON_INSTALL_FAILED`, as a failed Electron download does, instead of `ENGINE_FAILURE`. A machine with no ffmpeg on its `PATH` is checked once per process, not once per recording, and an app's `package.json` that starts with a byte order mark passes the `app.appPath` check.
4 changes: 2 additions & 2 deletions docs/electron.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ The video follows the window `screen` reads, through `app.restart()` too, and
is saved as one `.webm` with the test's results. To record part of a test,
call `app.startRecording()` and `app.stopRecording()`.

Encoding needs ffmpeg. The engine uses the one on your `PATH`, or downloads
one on the first recording. Set `E2E_FFMPEG_PATH` to use your own.
Encoding needs ffmpeg: the engine finds one, or downloads it on the first
recording. Set `E2E_FFMPEG_PATH` to use your own.

## Test a packaged app

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/electron.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ These hold on an Electron target and differ from a web target.
| Long press | Holds for 800 ms by default, compared to 500 ms on the web. |
| Upload | `setInputFiles` attaches files by path, resolved from the project root, or from memory. It works on a file `<input>` and on a button that opens a file chooser, and `[]` clears an input. A path that names no file is `INVALID_ARGUMENT`, and so are several files for a chooser that takes one. |
| Crashed renderers | A crashed window fails reads with `APP_NOT_OPEN` until you reload it with `electron.evaluate()` or restart the app. |
| Video | The recording follows the active window, through `app.restart()` too, and is saved as one `.webm`. Encoding needs ffmpeg with VP9: the one `E2E_FFMPEG_PATH` names, else the one on your `PATH`, else one the engine downloads on the first recording and keeps in the e2e cache. On a platform with no build to download, recording fails with `UNSUPPORTED_CAPABILITY` until you set `E2E_FFMPEG_PATH`. |
| Video | The recording follows the active window, through `app.restart()` too, and is saved as one `.webm`. Encoding needs ffmpeg with VP9: the one `E2E_FFMPEG_PATH` names, else the one the engine downloaded before and keeps in the e2e cache, else the one on your `PATH`, else one the engine downloads on the first recording. A failed download fails the recording with `ELECTRON_INSTALL_FAILED`. On a platform with no build to download, recording fails with `UNSUPPORTED_CAPABILITY` until you set `E2E_FFMPEG_PATH`. |
| Headless mode | Electron always opens windows unless your app hides them, and `--headed` has no effect. On Linux CI, run under `xvfb-run`. |

### Not supported yet
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/errors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ These appear in terminal output and in the report as plain string codes.
| `SERVICE_START_FAILED` | A [service's](/services) `start` function threw, finished without yielding, isn't an async generator, or didn't yield within its `startupTimeout`. Any services already started are stopped | infrastructure | 3 |
| `SERVICE_STOP_FAILED` | A [service's](/services) code after `yield` threw, yielded a second time, or didn't finish within the service's `shutdownTimeout`. Recorded as a cleanup error | infrastructure | 3 |
| `BROWSER_INSTALL_FAILED` | Browser provisioning failed | infrastructure | 3 |
| `ELECTRON_INSTALL_FAILED` | `@e2e-dev/electron` could not download the Electron binary of the project's `electron` package, or a worker started without it (a host that skipped the engine's prepare step) | infrastructure | 3 |
| `ELECTRON_INSTALL_FAILED` | `@e2e-dev/electron` could not download the Electron binary of the project's `electron` package, or a worker started without it (a host that skipped the engine's prepare step); or it could not download the ffmpeg a video recording needs | infrastructure | 3 |
| `WORKER_INIT_FAILED` | Workers for a target failed to start twice since the last one became ready. A start fails when the worker exits, or reports an uncaught exception or unhandled rejection, before it is ready. The target's remaining tests are skipped | infrastructure | 3 |
| `WORKER_EXIT` | A worker exited unexpectedly while running a file. The test in flight fails with `WORKER_CRASH`, and the file's other tests are skipped. Attempts that finished before the exit stay in the report. When an unhandled rejection ends the worker (see `UNHANDLED_REJECTION`), the rejection is the run error, not this one | infrastructure | 3 |
| `WORKER_CRASH` | A worker exited during a specific test | infrastructure | 3 |
Expand Down
7 changes: 4 additions & 3 deletions packages/electron/src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** The engine errors this surface raises, and the translation of a protocol failure into them. */

import { ConfigurationError, EngineError, TestError } from '@e2e-dev/core/engine';
import { ConfigurationError, EngineError, InfrastructureError, TestError } from '@e2e-dev/core/engine';

export function stale(message: string, cause?: unknown): EngineError {
return new EngineError('NODE_STALE', message, { retryable: true, ...(cause === undefined ? {} : { cause }) });
Expand Down Expand Up @@ -38,8 +38,9 @@ export function closedWindow(cause: unknown): boolean {
* is `ACTION_MAY_HAVE_COMMITTED`, never something the harness retries.
*/
export function translate(cause: unknown, label: string, committed: boolean): Error {
// A refusal by policy (a screenshot it cannot mask) or of the test's own input is the harness's to report as it is.
if (cause instanceof ConfigurationError || cause instanceof TestError) return cause;
// A refusal by policy (a screenshot it cannot mask), of the test's own input, or of the machine (a download of ffmpeg
// that failed) is the harness's to report as it is.
if (cause instanceof ConfigurationError || cause instanceof TestError || cause instanceof InfrastructureError) return cause;
Comment thread
kdy1 marked this conversation as resolved.
Resolved
if (cause instanceof EngineError) {
if (committed && (cause.code === 'OPERATION_TIMEOUT' || cause.code === 'CANCELLED' || cause.retryable)) {
return new EngineError('ACTION_MAY_HAVE_COMMITTED', `${label}: ${cause.message}; its input may have reached the app`, { retryable: false, cause });
Expand Down
3 changes: 2 additions & 1 deletion packages/electron/src/executable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ export function appPathProblem(projectRoot: string, appPath: string): string | u
let main = 'index.js';
if (existsSync(manifest)) {
try {
const parsed: unknown = JSON.parse(readFileSync(manifest, 'utf8'));
// A byte order mark at the start, which an editor on Windows may write, Electron reads past, as Node does.
const parsed: unknown = JSON.parse(readFileSync(manifest, 'utf8').replace(/^\uFEFF/, ''));
if (typeof parsed === 'object' && parsed !== null && 'main' in parsed && typeof parsed.main === 'string' && parsed.main !== '') main = parsed.main;
} catch {
return `app.appPath names ${resolved}, whose package.json is not valid JSON`;
Expand Down
2 changes: 1 addition & 1 deletion packages/electron/src/ffmpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export async function ensureFfmpeg(env: Env, signal: AbortSignal): Promise<strin
if (configured !== undefined && configured !== '') return configured;
const cached = cachedFfmpeg(env);
if (existsSync(cached)) return cached;
systemFfmpeg ??= encodesVp9('ffmpeg') ? 'ffmpeg' : null;
if (systemFfmpeg === undefined) systemFfmpeg = encodesVp9('ffmpeg') ? 'ffmpeg' : null;
if (systemFfmpeg !== null) return systemFfmpeg;
// Windows on Arm runs the x64 build.
const platform = process.platform === 'win32' ? 'win32-x64' : `${process.platform}-${process.arch}`;
Expand Down
5 changes: 4 additions & 1 deletion packages/electron/tests/unit/errors.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConfigurationError, EngineError, TestError } from '@e2e-dev/core/engine';
import { ConfigurationError, EngineError, InfrastructureError, TestError } from '@e2e-dev/core/engine';
import { describe, expect, it } from 'vitest';
import { closedWindow, translate } from '../../src/errors.ts';

Expand All @@ -12,6 +12,9 @@ describe('translate', () => {
const invalid = new TestError('INVALID_ARGUMENT', 'no file');
expect(translate(denied, 'screenshot', true)).toBe(denied);
expect(translate(invalid, 'setInputFiles', true)).toBe(invalid);
// The machine's failure, a download of ffmpeg, keeps its code.
const download = new InfrastructureError('ELECTRON_INSTALL_FAILED', 'downloading ffmpeg failed: HTTP 500');
expect(translate(download, 'video start', false)).toBe(download);
});

it('maps a protocol failure by what went away', () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/electron/tests/unit/executable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ describe('app.appPath', () => {
expect(appPathProblem(root, 'app/main.cjs')).toBeUndefined();
expect(appPathProblem(root, 'missing')).toMatch(/does not exist/);
expect(appPathProblem(root, 'app/no-main')).toMatch(/index\.js does not exist/);
// A package.json that starts with a byte order mark, which Electron reads past.
mkdirSync(path.join(root, 'bom'), { recursive: true });
writeFileSync(path.join(root, 'bom', 'package.json'), `\uFEFF${JSON.stringify({ name: 'bom', main: 'main.js' })}`);
writeFileSync(path.join(root, 'bom', 'main.js'), '');
expect(appPathProblem(root, 'bom')).toBeUndefined();
});
});

Expand Down
40 changes: 40 additions & 0 deletions packages/electron/tests/unit/ffmpeg.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { mkdtempSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { InfrastructureError } from '@e2e-dev/core/engine';
import { afterAll, describe, expect, it, vi } from 'vitest';

// Every probe of the PATH's ffmpeg finds one without VP9, as on a machine with no ffmpeg.
const probes = vi.hoisted(() => ({ count: 0 }));
vi.mock('node:child_process', async (importOriginal) => {
const actual = await importOriginal<typeof import('node:child_process')>();
return {
...actual,
spawnSync: () => {
probes.count += 1;
return { status: 1, stdout: '', stderr: '' };
},
};
});

const { ensureFfmpeg } = await import('../../src/ffmpeg.ts');

const cache = mkdtempSync(path.join(tmpdir(), 'e2e-electron-ffmpeg-'));
afterAll(() => {
vi.unstubAllGlobals();
rmSync(cache, { recursive: true, force: true });
});

describe('ensureFfmpeg', () => {
it('checks the PATH for ffmpeg once, and fails a download that failed with ELECTRON_INSTALL_FAILED', async () => {
vi.stubGlobal('fetch', async () => new Response('', { status: 500 }));
// An empty cache, so each call reaches the PATH, then the download.
const env = { E2E_BROWSERS_PATH: cache };
for (let attempt = 0; attempt < 2; attempt += 1) {
const failure: unknown = await ensureFfmpeg(env, new AbortController().signal).catch((cause: unknown) => cause);
expect(failure).toBeInstanceOf(InfrastructureError);
expect(failure).toMatchObject({ code: 'ELECTRON_INSTALL_FAILED', message: expect.stringContaining('HTTP 500') });
}
expect(probes.count).toBe(1);
});
});
Loading