@e2e-dev/electron 0.0.1-nightly-20261130030410 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist/.build.json +1 -1
- package/dist/app-process.d.ts +3 -1
- package/dist/app-process.js +68 -18
- package/dist/dialogs.d.ts +3 -1
- package/dist/dialogs.js +10 -3
- package/dist/errors.js +4 -3
- package/dist/executable.js +65 -14
- package/dist/ffmpeg.js +2 -1
- package/dist/fields.js +80 -7
- package/dist/in-page/node-ops.js +8 -7
- package/dist/install-lock.d.ts +15 -0
- package/dist/install-lock.js +165 -0
- package/dist/install-process.d.ts +7 -0
- package/dist/install-process.js +37 -0
- package/dist/launcher.d.ts +2 -2
- package/dist/launcher.js +14 -2
- package/dist/snapshot.d.ts +69 -4
- package/dist/snapshot.js +214 -18
- package/dist/surface.js +71 -19
- package/dist/video.d.ts +13 -0
- package/dist/video.js +75 -22
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -7,10 +7,16 @@ DevTools protocol and driven with trusted input, through the same
|
|
|
7
7
|
implement. A test written against `screen`, `expect`, `app`, and `agent` runs
|
|
8
8
|
on an Electron target unchanged.
|
|
9
9
|
|
|
10
|
+
> [!NOTE]
|
|
11
|
+
> **Electron support is experimental.** The `electron()` options, the `electron`
|
|
12
|
+
> fixture, and how the engine behaves can change in any release, including a
|
|
13
|
+
> patch, until it's stable. Pin `@e2e-dev/electron` to an exact version in
|
|
14
|
+
> `package.json`, with no `^`, and read the
|
|
15
|
+
> [release notes](https://github.com/e2e-inc/e2e/releases) before you upgrade.
|
|
16
|
+
|
|
10
17
|
It is also the reference for an engine built outside this repository: it
|
|
11
18
|
imports only `@e2e-dev/core/engine` and speaks the DevTools protocol itself,
|
|
12
|
-
with no automation library and never another engine.
|
|
13
|
-
building it changed in the contract.
|
|
19
|
+
with no automation library and never another engine.
|
|
14
20
|
|
|
15
21
|
## Install
|
|
16
22
|
|
package/dist/.build.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.0
|
|
1
|
+
{"version":"0.1.0"}
|
package/dist/app-process.d.ts
CHANGED
|
@@ -45,6 +45,8 @@ export declare class AppProcess {
|
|
|
45
45
|
private readonly dialogs;
|
|
46
46
|
private app;
|
|
47
47
|
private exit;
|
|
48
|
+
/** The exit of an app a failed launch killed, which the next quit waits for. */
|
|
49
|
+
private exiting;
|
|
48
50
|
private directory;
|
|
49
51
|
private queue;
|
|
50
52
|
constructor(options: ResolvedElectronOptions, windows: Windows, dialogs: DialogRouter);
|
|
@@ -63,7 +65,7 @@ export declare class AppProcess {
|
|
|
63
65
|
/** Quits the running app, if any: a graceful quit within `graceMs` and the budget, then its process tree killed. */
|
|
64
66
|
quit(budget: {
|
|
65
67
|
readonly timeoutMs: number;
|
|
66
|
-
}, graceMs: number): Promise<void>;
|
|
68
|
+
}, graceMs: number, exitWaitMs?: number): Promise<void>;
|
|
67
69
|
/**
|
|
68
70
|
* Launches the app on the attempt's user-data directory and waits for its
|
|
69
71
|
* first window to load, all within one budget: `budget` when the operation
|
package/dist/app-process.js
CHANGED
|
@@ -24,6 +24,14 @@ export const RESTART_CLOSE_MS = 5_000;
|
|
|
24
24
|
const ANSWER_MS = 500;
|
|
25
25
|
/** How long a killed app gets to exit, and let go of its files, before its data is deleted. */
|
|
26
26
|
const EXIT_WAIT_MS = 2_000;
|
|
27
|
+
/** How long a failed launch waits for each answer it asks the app for, to say why it failed. */
|
|
28
|
+
const FAILURE_ANSWER_MS = 250;
|
|
29
|
+
/**
|
|
30
|
+
* What a failed launch keeps of its time to say why and end the app: the main
|
|
31
|
+
* process and its ready state asked, then the app killed and its exit waited
|
|
32
|
+
* for as long again.
|
|
33
|
+
*/
|
|
34
|
+
const FAILURE_REPORT_MS = 3 * FAILURE_ANSWER_MS;
|
|
27
35
|
/** How long setting the downloads directory may take of a launch's budget. */
|
|
28
36
|
const DOWNLOADS_SETUP_MS = 2_000;
|
|
29
37
|
/** How long reading a window's OS title may take. */
|
|
@@ -38,12 +46,16 @@ const INSPECTOR_CONNECT_MS = 5_000;
|
|
|
38
46
|
const INSPECTOR_GRACE_MS = 500;
|
|
39
47
|
/** How many of the app's last stderr lines a failed launch quotes. */
|
|
40
48
|
const QUOTED_STDERR_LINES = 10;
|
|
49
|
+
/** The longest stderr line a launch failure quotes, in characters. */
|
|
50
|
+
const QUOTED_LINE_CHARS = 500;
|
|
41
51
|
export class AppProcess {
|
|
42
52
|
options;
|
|
43
53
|
windows;
|
|
44
54
|
dialogs;
|
|
45
55
|
app;
|
|
46
56
|
exit;
|
|
57
|
+
/** The exit of an app a failed launch killed, which the next quit waits for. */
|
|
58
|
+
exiting;
|
|
47
59
|
directory;
|
|
48
60
|
queue = Promise.resolve();
|
|
49
61
|
constructor(options, windows, dialogs) {
|
|
@@ -75,7 +87,13 @@ export class AppProcess {
|
|
|
75
87
|
return run;
|
|
76
88
|
}
|
|
77
89
|
/** Quits the running app, if any: a graceful quit within `graceMs` and the budget, then its process tree killed. */
|
|
78
|
-
async quit(budget, graceMs) {
|
|
90
|
+
async quit(budget, graceMs, exitWaitMs = EXIT_WAIT_MS) {
|
|
91
|
+
// A failed launch waited only briefly for the app it killed: its files in the user-data directory, removed after
|
|
92
|
+
// this quit, are let go of first.
|
|
93
|
+
const exiting = this.exiting;
|
|
94
|
+
this.exiting = undefined;
|
|
95
|
+
if (exiting !== undefined)
|
|
96
|
+
await answerWithin(exiting, EXIT_WAIT_MS);
|
|
79
97
|
const app = this.app;
|
|
80
98
|
this.app = undefined;
|
|
81
99
|
this.exit = undefined;
|
|
@@ -83,7 +101,9 @@ export class AppProcess {
|
|
|
83
101
|
this.windows.clear();
|
|
84
102
|
if (app === undefined)
|
|
85
103
|
return;
|
|
86
|
-
await stop(app, Math.min(budget.timeoutMs, graceMs));
|
|
104
|
+
await stop(app, Math.min(budget.timeoutMs, graceMs), exitWaitMs);
|
|
105
|
+
if (app.process.ended === undefined && exitWaitMs < EXIT_WAIT_MS)
|
|
106
|
+
this.exiting = app.process.exited;
|
|
87
107
|
}
|
|
88
108
|
/**
|
|
89
109
|
* Launches the app on the attempt's user-data directory and waits for its
|
|
@@ -95,9 +115,11 @@ export class AppProcess {
|
|
|
95
115
|
// rather than the operation timing out; each phase gets what the ones before it left.
|
|
96
116
|
// An operation cancelled, or out of time after the quit before it, starts no app.
|
|
97
117
|
budget.check();
|
|
98
|
-
|
|
118
|
+
// A failed launch then asks the app why and quits it: that is left out of the launch's own time, up to half of it.
|
|
119
|
+
// With under 1.5 s left, half is less than the report can take, so a very short launch can still end in TEST_TIMEOUT.
|
|
120
|
+
const available = budget.waits.remaining();
|
|
121
|
+
const timeout = Math.max(1, available - Math.min(FAILURE_REPORT_MS, available / 2));
|
|
99
122
|
const deadline = new Deadline(timeout);
|
|
100
|
-
const left = () => Math.max(1, deadline.remaining());
|
|
101
123
|
let app;
|
|
102
124
|
let opened = false;
|
|
103
125
|
try {
|
|
@@ -119,7 +141,10 @@ export class AppProcess {
|
|
|
119
141
|
const window = () => raceAbort(() => Promise.race([loaded(open, deadline, operation.signal), quitEarly]), operation.signal, 'waiting for the first window to load');
|
|
120
142
|
let first = await window();
|
|
121
143
|
opened = true;
|
|
122
|
-
// Still inside the launch: an app that quits here, or a caller that stopped waiting, fails it.
|
|
144
|
+
// Still inside the launch: an app that quits here, or a caller that stopped waiting, fails it. A window that loaded
|
|
145
|
+
// as the wait for one ran out still gets the operation's time to connect its main process and place its downloads:
|
|
146
|
+
// with none left, an app with an inspector would be taken for one with none, and save downloads where it likes.
|
|
147
|
+
const left = () => Math.max(1, budget.waits.remaining());
|
|
123
148
|
const reported = await raceAbort(() => Promise.race([this.setUp(app, setup, left), quitEarly]), operation.signal, 'setting up the app');
|
|
124
149
|
// A splash screen can close while the app is set up: the launch ends on a window that is there.
|
|
125
150
|
while (first.isClosed())
|
|
@@ -133,11 +158,13 @@ export class AppProcess {
|
|
|
133
158
|
catch (cause) {
|
|
134
159
|
// Read before the engine's own quit, which ends the process too.
|
|
135
160
|
const exited = app.process.ended;
|
|
136
|
-
const main = exited === undefined ? await answerWithin(app.main,
|
|
161
|
+
const main = exited === undefined ? await answerWithin(app.main, FAILURE_ANSWER_MS) : undefined;
|
|
137
162
|
// Electron can stall before its ready event on a loaded machine; say so rather than blame the app's window.
|
|
138
|
-
const ready = main === undefined ? undefined : await answerWithin(main.evaluate(({ app: electronApp }) => electronApp.isReady(), undefined),
|
|
163
|
+
const ready = main === undefined ? undefined : await answerWithin(main.evaluate(({ app: electronApp }) => electronApp.isReady(), undefined), FAILURE_ANSWER_MS);
|
|
139
164
|
const stuck = [...app.pages.values()].filter((page) => !this.windows.has(page)).length;
|
|
140
|
-
|
|
165
|
+
// Killed, with no graceful quit and only a moment's wait for its exit: an app that failed to launch has nothing to
|
|
166
|
+
// save, and the time is the report's. The next quit waits for the rest.
|
|
167
|
+
await this.quit({ timeoutMs: 0 }, 0, FAILURE_ANSWER_MS);
|
|
141
168
|
if (cause instanceof EngineError)
|
|
142
169
|
throw cause;
|
|
143
170
|
throw launchError(setup, app.process, { exited, ready, stuck, timeout, opened }, cause);
|
|
@@ -411,12 +438,30 @@ export class AppProcess {
|
|
|
411
438
|
await gone;
|
|
412
439
|
}
|
|
413
440
|
}
|
|
414
|
-
|
|
441
|
+
/**
|
|
442
|
+
* A stderr line as a failed launch quotes it: whole up to `QUOTED_LINE_CHARS`
|
|
443
|
+
* characters, and only its length past that. Any cut, at white space too,
|
|
444
|
+
* could keep the start of a secret, which the run's redaction, matching whole
|
|
445
|
+
* values only, would let through.
|
|
446
|
+
*/
|
|
447
|
+
function quotedLine(line) {
|
|
448
|
+
return line.length <= QUOTED_LINE_CHARS ? line : `(a line of ${line.length} characters)`;
|
|
449
|
+
}
|
|
450
|
+
const NO_INSPECTOR = 'the app\'s main process opened no inspector, so electron.evaluate and electron.waitForDownload cannot run in it and windows are known by their document titles only: a packaged app built with the EnableNodeCliInspectArguments fuse off ignores --inspect';
|
|
415
451
|
/** Ends an app: a graceful quit within `graceMs`, then its process tree killed and waited for. */
|
|
416
|
-
async function stop(app, graceMs) {
|
|
452
|
+
async function stop(app, graceMs, exitWaitMs) {
|
|
417
453
|
const { process } = app;
|
|
418
454
|
if (process.ended !== undefined)
|
|
419
455
|
return;
|
|
456
|
+
if (graceMs > 0 && (await quitGracefully(app, graceMs)))
|
|
457
|
+
return;
|
|
458
|
+
process.killNow();
|
|
459
|
+
// Its files in the user-data directory are deleted next: wait, briefly, until it has let go of them.
|
|
460
|
+
await answerWithin(process.exited, exitWaitMs);
|
|
461
|
+
}
|
|
462
|
+
/** Asks the app to quit, and whether it exited within `graceMs`. */
|
|
463
|
+
async function quitGracefully(app, graceMs) {
|
|
464
|
+
const { process } = app;
|
|
420
465
|
const main = await answerWithin(app.main, ANSWER_MS);
|
|
421
466
|
if (main === undefined) {
|
|
422
467
|
void process.browser.root.send('Browser.close').catch(() => undefined);
|
|
@@ -430,11 +475,7 @@ async function stop(app, graceMs) {
|
|
|
430
475
|
}, undefined), Math.min(graceMs, ANSWER_MS));
|
|
431
476
|
void main.evaluate(({ app: electronApp }) => electronApp.quit(), undefined).catch(() => undefined);
|
|
432
477
|
}
|
|
433
|
-
|
|
434
|
-
return;
|
|
435
|
-
process.killNow();
|
|
436
|
-
// Its files in the user-data directory are deleted next: wait, briefly, until it has let go of them.
|
|
437
|
-
await answerWithin(process.exited, EXIT_WAIT_MS);
|
|
478
|
+
return (await answerWithin(process.exited, graceMs)) !== undefined;
|
|
438
479
|
}
|
|
439
480
|
/** The first of the app's open windows, in the order they opened, to have a parsed document: a window is read from then on. */
|
|
440
481
|
async function loaded(pages, deadline, signal) {
|
|
@@ -491,7 +532,8 @@ function launchError(setup, process, seen, cause) {
|
|
|
491
532
|
}
|
|
492
533
|
/** What the app wrote to stderr, for a failure's message; empty when it wrote nothing. */
|
|
493
534
|
function stderrQuote(process) {
|
|
494
|
-
|
|
535
|
+
// A longer line is left out: a minified stack or a data: URL in one would fill the report.
|
|
536
|
+
const lines = process.stderrTail(QUOTED_STDERR_LINES).map(quotedLine);
|
|
495
537
|
return lines.length === 0 ? '' : `. The app wrote to stderr:\n${lines.join('\n')}`;
|
|
496
538
|
}
|
|
497
539
|
/** Electron has no headless mode: on a machine with no display it exits at once, and its own message is easy to miss. */
|
|
@@ -532,11 +574,15 @@ async function placeDownloads(main, directory, withinMs) {
|
|
|
532
574
|
electronApp.setPath('downloads', downloads);
|
|
533
575
|
// Compared without case: two names that differ only in case are one file on macOS and Windows.
|
|
534
576
|
const taken = new Set(earlier.map((name) => name.toLowerCase()));
|
|
577
|
+
// A file the app wrote there itself since launch is taken too; an Electron before getBuiltinModule knows only the list.
|
|
578
|
+
const files = process.getBuiltinModule?.('node:fs');
|
|
579
|
+
// A file's folder, its separators either way round: an app on Windows may write either.
|
|
580
|
+
const folderOf = (file) => file.replace(/[\\/][^\\/]*$/, '').replaceAll('\\', '/').toLowerCase();
|
|
535
581
|
const unique = (name) => {
|
|
536
582
|
const dot = name.lastIndexOf('.');
|
|
537
583
|
const [stem, extension] = dot > 0 ? [name.slice(0, dot), name.slice(dot)] : [name, ''];
|
|
538
584
|
let candidate = name;
|
|
539
|
-
for (let count = 1; taken.has(candidate.toLowerCase()); count += 1)
|
|
585
|
+
for (let count = 1; taken.has(candidate.toLowerCase()) || files?.existsSync(`${downloads}/${candidate}`) === true; count += 1)
|
|
540
586
|
candidate = `${stem} (${count})${extension}`;
|
|
541
587
|
taken.add(candidate.toLowerCase());
|
|
542
588
|
return candidate;
|
|
@@ -549,8 +595,12 @@ async function placeDownloads(main, directory, withinMs) {
|
|
|
549
595
|
return;
|
|
550
596
|
placed.add(target);
|
|
551
597
|
target.on('will-download', (_event, item) => {
|
|
552
|
-
|
|
598
|
+
const chosen = item.getSavePath();
|
|
599
|
+
if (chosen === '')
|
|
553
600
|
item.setSavePath(`${downloads}/${unique(item.getFilename())}`);
|
|
601
|
+
// A path the app chose in the downloads folder is taken, so a later download is not given it.
|
|
602
|
+
else if (folderOf(chosen) === folderOf(`${downloads}/-`))
|
|
603
|
+
taken.add((chosen.split(/[\\/]/).pop() ?? '').toLowerCase());
|
|
554
604
|
// What `electron.waitForDownload` reads: each download the app started, and how it ended.
|
|
555
605
|
const entry = { filename: item.getFilename(), path: item.getSavePath(), state: 'progressing' };
|
|
556
606
|
const log = (globalThis.e2eDownloads ??= []);
|
package/dist/dialogs.d.ts
CHANGED
|
@@ -23,7 +23,9 @@ export interface OpenDialog {
|
|
|
23
23
|
export declare class DialogRouter {
|
|
24
24
|
private registrations;
|
|
25
25
|
private pending;
|
|
26
|
-
private
|
|
26
|
+
private running;
|
|
27
|
+
/** Bumped by `reset`: a handler of an earlier attempt that is still running reports into none of the next one's state. */
|
|
28
|
+
private generation;
|
|
27
29
|
/** Registers a handler, the newest winning, and returns what removes it. */
|
|
28
30
|
add(handler: DialogHandler): () => void;
|
|
29
31
|
/** Forgets the attempt's handlers and whatever it left unreported. */
|
package/dist/dialogs.js
CHANGED
|
@@ -12,6 +12,8 @@ export class DialogRouter {
|
|
|
12
12
|
registrations = [];
|
|
13
13
|
pending;
|
|
14
14
|
running = new Set();
|
|
15
|
+
/** Bumped by `reset`: a handler of an earlier attempt that is still running reports into none of the next one's state. */
|
|
16
|
+
generation = 0;
|
|
15
17
|
/** Registers a handler, the newest winning, and returns what removes it. */
|
|
16
18
|
add(handler) {
|
|
17
19
|
const registration = { handler };
|
|
@@ -24,6 +26,8 @@ export class DialogRouter {
|
|
|
24
26
|
reset() {
|
|
25
27
|
this.registrations = [];
|
|
26
28
|
this.pending = undefined;
|
|
29
|
+
this.running = new Set();
|
|
30
|
+
this.generation += 1;
|
|
27
31
|
}
|
|
28
32
|
/** The failure a dialog left for the next step, once. */
|
|
29
33
|
take() {
|
|
@@ -38,15 +42,18 @@ export class DialogRouter {
|
|
|
38
42
|
/** Answers one dialog through the newest handler. */
|
|
39
43
|
dispatch(dialog) {
|
|
40
44
|
const work = this.route(dialog).catch(() => undefined);
|
|
41
|
-
this
|
|
42
|
-
|
|
45
|
+
const { running } = this;
|
|
46
|
+
running.add(work);
|
|
47
|
+
void work.then(() => running.delete(work));
|
|
43
48
|
}
|
|
44
49
|
async route(dialog) {
|
|
45
50
|
const handler = this.registrations.at(-1)?.handler;
|
|
46
51
|
const { type, message } = dialog;
|
|
52
|
+
const { generation } = this;
|
|
47
53
|
// The first failure is the one to report: the app's later dialogs follow from it.
|
|
48
54
|
const fail = (error) => {
|
|
49
|
-
this.
|
|
55
|
+
if (this.generation === generation)
|
|
56
|
+
this.pending ??= error;
|
|
50
57
|
};
|
|
51
58
|
if (handler === undefined) {
|
|
52
59
|
fail(new EngineError('INVALID_STATE', `unhandled ${type} dialog: ${message}; answer it with electron.onDialog('accept'), 'dismiss', or a handler`, { retryable: false }));
|
package/dist/errors.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** The engine errors this surface raises, and the translation of a protocol failure into them. */
|
|
2
|
-
import { ConfigurationError, EngineError, TestError } from '@e2e-dev/core/engine';
|
|
2
|
+
import { ConfigurationError, EngineError, InfrastructureError, TestError } from '@e2e-dev/core/engine';
|
|
3
3
|
export function stale(message, cause) {
|
|
4
4
|
return new EngineError('NODE_STALE', message, { retryable: true, ...(cause === undefined ? {} : { cause }) });
|
|
5
5
|
}
|
|
@@ -29,8 +29,9 @@ export function closedWindow(cause) {
|
|
|
29
29
|
* is `ACTION_MAY_HAVE_COMMITTED`, never something the harness retries.
|
|
30
30
|
*/
|
|
31
31
|
export function translate(cause, label, committed) {
|
|
32
|
-
// A refusal by policy (a screenshot it cannot mask)
|
|
33
|
-
|
|
32
|
+
// A refusal by policy (a screenshot it cannot mask), of the test's own input, or of the machine (a download of ffmpeg
|
|
33
|
+
// that failed) is the harness's to report as it is.
|
|
34
|
+
if (cause instanceof ConfigurationError || cause instanceof TestError || cause instanceof InfrastructureError)
|
|
34
35
|
return cause;
|
|
35
36
|
if (cause instanceof EngineError) {
|
|
36
37
|
if (committed && (cause.code === 'OPERATION_TIMEOUT' || cause.code === 'CANCELLED' || cause.retryable)) {
|
package/dist/executable.js
CHANGED
|
@@ -6,14 +6,48 @@
|
|
|
6
6
|
* before the run's clock starts, and a worker only checks it is there.
|
|
7
7
|
*/
|
|
8
8
|
import { spawn } from 'node:child_process';
|
|
9
|
-
import { accessSync, closeSync, constants, existsSync, openSync, readdirSync, readFileSync, readSync, statSync } from 'node:fs';
|
|
9
|
+
import { accessSync, closeSync, constants, existsSync, openSync, readdirSync, readFileSync, readSync, realpathSync, statSync } from 'node:fs';
|
|
10
10
|
import { createRequire } from 'node:module';
|
|
11
11
|
import path from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
12
13
|
import { ConfigurationError, InfrastructureError } from '@e2e-dev/core/engine';
|
|
14
|
+
import { INCOMPLETE_INSTALL } from './install-lock.js';
|
|
13
15
|
/** How much of a failed download's output its error quotes, in characters. */
|
|
14
16
|
const INSTALL_OUTPUT_TAIL = 2000;
|
|
17
|
+
/** What the package's `path.txt` names, empty when there is none: a download removes one left by an earlier download, and writes its own last. */
|
|
18
|
+
function namedBinary(directory) {
|
|
19
|
+
try {
|
|
20
|
+
return readFileSync(path.join(directory, 'path.txt'), 'utf8').trim();
|
|
21
|
+
}
|
|
22
|
+
catch (cause) {
|
|
23
|
+
if (cause.code === 'ENOENT')
|
|
24
|
+
return '';
|
|
25
|
+
throw cause;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Where a dist directory keeps the binary on `platform`: what the package's `install.js` writes to `path.txt`. */
|
|
29
|
+
function platformBinary(platform) {
|
|
30
|
+
if (platform === 'darwin')
|
|
31
|
+
return path.join('Electron.app', 'Contents', 'MacOS', 'Electron');
|
|
32
|
+
return platform === 'win32' ? 'electron.exe' : 'electron';
|
|
33
|
+
}
|
|
34
|
+
/** Whether this override points back into the package distribution an install has started writing: the directory is that one, or the binary found in it is really a file inside it. */
|
|
35
|
+
function usesIncompleteDistribution(directory, override, binary) {
|
|
36
|
+
if (!existsSync(path.join(directory, INCOMPLETE_INSTALL)))
|
|
37
|
+
return false;
|
|
38
|
+
const dist = path.join(directory, 'dist');
|
|
39
|
+
if (path.resolve(override) === dist)
|
|
40
|
+
return true;
|
|
41
|
+
try {
|
|
42
|
+
const written = realpathSync(dist);
|
|
43
|
+
return realpathSync(override) === written || (binary !== undefined && realpathSync(binary).startsWith(written + path.sep));
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
15
49
|
/** The project's `electron` package, or undefined when the project has none. */
|
|
16
|
-
function electronPackage(projectRoot, env) {
|
|
50
|
+
function electronPackage(projectRoot, env, platform) {
|
|
17
51
|
let manifest;
|
|
18
52
|
try {
|
|
19
53
|
manifest = createRequire(path.join(projectRoot, 'package.json')).resolve('electron/package.json');
|
|
@@ -24,13 +58,19 @@ function electronPackage(projectRoot, env) {
|
|
|
24
58
|
const directory = path.dirname(manifest);
|
|
25
59
|
const parsed = JSON.parse(readFileSync(manifest, 'utf8'));
|
|
26
60
|
const version = typeof parsed === 'object' && parsed !== null && 'version' in parsed && typeof parsed.version === 'string' ? parsed.version : 'unknown';
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
// Electron's own index.js takes the binary from ELECTRON_OVERRIDE_DIST_PATH when it is set (a build of your own, Nix).
|
|
61
|
+
const relative = namedBinary(directory);
|
|
62
|
+
// Electron's own index.js takes the binary from ELECTRON_OVERRIDE_DIST_PATH when it is set (a build of your own, Nix), under the name in `path.txt`, else `electron`. A download removes `path.txt` while it writes, so with none the platform's own name is looked for too.
|
|
30
63
|
const override = env['ELECTRON_OVERRIDE_DIST_PATH'];
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
64
|
+
if (override) {
|
|
65
|
+
const names = relative === '' ? ['electron', platformBinary(platform)] : [relative];
|
|
66
|
+
const binary = names.map((name) => path.join(override, name)).find((file) => existsSync(file));
|
|
67
|
+
// Check after looking for the binary: extraction can start between reading path.txt and finding the new file.
|
|
68
|
+
if (!usesIncompleteDistribution(directory, override, binary))
|
|
69
|
+
return { directory, binary, version, override: binary ?? path.join(override, relative || 'electron') };
|
|
70
|
+
}
|
|
71
|
+
const binary = relative === '' ? undefined : path.join(directory, 'dist', relative);
|
|
72
|
+
const ready = binary !== undefined && existsSync(binary) && namedBinary(directory) === relative;
|
|
73
|
+
return { directory, binary: ready ? binary : undefined, version };
|
|
34
74
|
}
|
|
35
75
|
/**
|
|
36
76
|
* Whether a path names a regular file this process may execute: a directory
|
|
@@ -136,7 +176,7 @@ function locateExecutable(projectRoot, executablePath, env, platform) {
|
|
|
136
176
|
}
|
|
137
177
|
return { kind: 'named', file: resolved };
|
|
138
178
|
}
|
|
139
|
-
const installed = electronPackage(projectRoot, env);
|
|
179
|
+
const installed = electronPackage(projectRoot, env, platform);
|
|
140
180
|
if (installed === undefined) {
|
|
141
181
|
return {
|
|
142
182
|
kind: 'misconfigured',
|
|
@@ -176,11 +216,20 @@ export async function ensureElectronBinary(projectRoot, executablePath, env, log
|
|
|
176
216
|
if (found.kind !== 'undownloaded')
|
|
177
217
|
return;
|
|
178
218
|
await download(found.package, env, log, signal);
|
|
179
|
-
if (electronPackage(projectRoot, env)?.binary === undefined) {
|
|
219
|
+
if (electronPackage(projectRoot, env, process.platform)?.binary === undefined) {
|
|
180
220
|
throw new InfrastructureError('ELECTRON_INSTALL_FAILED', `electron ${found.package.version}'s install.js finished, but its binary is still missing at ${found.package.directory}`);
|
|
181
221
|
}
|
|
182
222
|
}
|
|
183
|
-
/**
|
|
223
|
+
/** The engine's script that runs `install.js` under the package's install lock: `.js` in a build, `.ts` from source. */
|
|
224
|
+
function installProcess() {
|
|
225
|
+
const built = fileURLToPath(new URL('./install-process.js', import.meta.url));
|
|
226
|
+
return existsSync(built) ? built : fileURLToPath(new URL('./install-process.ts', import.meta.url));
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Runs the package's own `install.js` (what its first `require` would run)
|
|
230
|
+
* in a process that holds the package's install lock, its output sent to
|
|
231
|
+
* `log`.
|
|
232
|
+
*/
|
|
184
233
|
async function download(installed, env, log, signal) {
|
|
185
234
|
const script = path.join(installed.directory, 'install.js');
|
|
186
235
|
if (!existsSync(script)) {
|
|
@@ -188,7 +237,8 @@ async function download(installed, env, log, signal) {
|
|
|
188
237
|
}
|
|
189
238
|
log(`downloading the Electron ${installed.version} binary`);
|
|
190
239
|
const failure = await new Promise((resolve) => {
|
|
191
|
-
|
|
240
|
+
// Started without ELECTRON_OVERRIDE_DIST_PATH: after extraction `install.js` would look for an `electron.d.ts` in the override directory and move it into the package.
|
|
241
|
+
const child = spawn(process.execPath, [installProcess(), script], { cwd: installed.directory, env: { ...env, ELECTRON_OVERRIDE_DIST_PATH: undefined }, stdio: ['ignore', 'pipe', 'pipe'], signal });
|
|
192
242
|
let tail = '';
|
|
193
243
|
const read = (chunk) => {
|
|
194
244
|
const text = chunk.toString('utf8');
|
|
@@ -200,7 +250,7 @@ async function download(installed, env, log, signal) {
|
|
|
200
250
|
child.stdout.on('data', read);
|
|
201
251
|
child.stderr.on('data', read);
|
|
202
252
|
child.on('error', (cause) => resolve(cause.message));
|
|
203
|
-
child.on('close', (code) => resolve(code === 0 ? undefined : `install.js exited with ${code}: ${tail.trim()}`));
|
|
253
|
+
child.on('close', (code, killSignal) => resolve(code === 0 ? undefined : `install.js ${killSignal === null ? `exited with ${String(code)}` : `was killed (${killSignal})`}${tail.trim() === '' ? '' : `: ${tail.trim()}`}`));
|
|
204
254
|
});
|
|
205
255
|
if (failure !== undefined)
|
|
206
256
|
throw new InfrastructureError('ELECTRON_INSTALL_FAILED', `downloading the Electron ${installed.version} binary failed: ${failure}`);
|
|
@@ -234,7 +284,8 @@ export function appPathProblem(projectRoot, appPath) {
|
|
|
234
284
|
let main = 'index.js';
|
|
235
285
|
if (existsSync(manifest)) {
|
|
236
286
|
try {
|
|
237
|
-
|
|
287
|
+
// A byte order mark at the start, which an editor on Windows may write, Electron reads past, as Node does.
|
|
288
|
+
const parsed = JSON.parse(readFileSync(manifest, 'utf8').replace(/^\uFEFF/, ''));
|
|
238
289
|
if (typeof parsed === 'object' && parsed !== null && 'main' in parsed && typeof parsed.main === 'string' && parsed.main !== '')
|
|
239
290
|
main = parsed.main;
|
|
240
291
|
}
|
package/dist/ffmpeg.js
CHANGED
|
@@ -52,7 +52,8 @@ export async function ensureFfmpeg(env, signal) {
|
|
|
52
52
|
const cached = cachedFfmpeg(env);
|
|
53
53
|
if (existsSync(cached))
|
|
54
54
|
return cached;
|
|
55
|
-
systemFfmpeg
|
|
55
|
+
if (systemFfmpeg === undefined)
|
|
56
|
+
systemFfmpeg = encodesVp9('ffmpeg') ? 'ffmpeg' : null;
|
|
56
57
|
if (systemFfmpeg !== null)
|
|
57
58
|
return systemFfmpeg;
|
|
58
59
|
// Windows on Arm runs the x64 build.
|
package/dist/fields.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* gave it one) and its DOM facts. An element the accessibility tree leaves
|
|
5
5
|
* out reads by the same rules with no accessibility node.
|
|
6
6
|
*/
|
|
7
|
-
import { isSecureField } from './snapshot.js';
|
|
7
|
+
import { explicitRoleOf, isSecureField } from './snapshot.js';
|
|
8
8
|
/**
|
|
9
9
|
* Chromium's own role names mapped to the roles of the engine contract's
|
|
10
10
|
* vocabulary, where an image is `image` (`getByRole('img')` is that role's
|
|
@@ -144,6 +144,18 @@ function rangeValueOf(node, facts, role) {
|
|
|
144
144
|
const native = (facts?.nodeName === 'PROGRESS' || facts?.nodeName === 'METER') && 'value' in attributes ? stringOf(node?.value) : undefined;
|
|
145
145
|
return native ?? (role === 'slider' || role === 'spinbutton' ? '' : undefined);
|
|
146
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* The value of an editing host the tree leaves out, as the web reads it from
|
|
149
|
+
* `innerText`: a host with no box reads as its text content, one that is
|
|
150
|
+
* invisible as nothing. The zero-width no-break space an editor pads an empty
|
|
151
|
+
* line with is no text, and a lone newline is an empty editor.
|
|
152
|
+
*/
|
|
153
|
+
function hiddenEditorValue(facts) {
|
|
154
|
+
if (facts.invisible)
|
|
155
|
+
return '';
|
|
156
|
+
const text = (facts.editorText ?? '').replaceAll('\uFEFF', '');
|
|
157
|
+
return text === '\n' ? '' : text;
|
|
158
|
+
}
|
|
147
159
|
function valueOf(node, facts, role, policy) {
|
|
148
160
|
// A select's value is what its chosen option submits, as `select.value` reads it; its options name the labels.
|
|
149
161
|
if (facts?.nodeName === 'SELECT')
|
|
@@ -158,9 +170,15 @@ function valueOf(node, facts, role, policy) {
|
|
|
158
170
|
return (facts.nodeName === 'INPUT' ? facts.inputValue : facts.textValue) ?? '';
|
|
159
171
|
if (RANGE_ROLES.has(role))
|
|
160
172
|
return rangeValueOf(node, facts, role);
|
|
161
|
-
// An
|
|
162
|
-
|
|
163
|
-
|
|
173
|
+
// An option submits its value attribute, else its text, as option.value reads it.
|
|
174
|
+
if (facts?.nodeName === 'OPTION')
|
|
175
|
+
return facts.optionValue ?? '';
|
|
176
|
+
// An editing host or an ARIA widget has no DOM value: its value is the one Chromium computes, for an editing host
|
|
177
|
+
// with no role as for one with a textbox role. A combobox that only shows its choice (a div) has none, as on the
|
|
178
|
+
// web; Chromium would echo its text.
|
|
179
|
+
if (isEditingHost(facts))
|
|
180
|
+
return node === undefined ? hiddenEditorValue(facts) : (stringOf(node.value) ?? '');
|
|
181
|
+
if (VALUE_ROLES.has(role) && role !== 'combobox')
|
|
164
182
|
return stringOf(node?.value) ?? '';
|
|
165
183
|
return undefined;
|
|
166
184
|
}
|
|
@@ -214,8 +232,51 @@ function shownAttributes(facts, policy, baseUrl) {
|
|
|
214
232
|
}
|
|
215
233
|
return shown;
|
|
216
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* The roles an `aria-checked` gives a checked state, read from the DOM for an
|
|
237
|
+
* element the tree leaves out. The same list as `CHECKED_ROLES` in
|
|
238
|
+
* `in-page/node-ops.ts` and in `@e2e-dev/core`'s `internal/roles.ts`, which
|
|
239
|
+
* `@e2e-dev/core/engine` does not export: a change belongs in all three.
|
|
240
|
+
*/
|
|
241
|
+
const ARIA_CHECKABLE = new Set(['checkbox', 'switch', 'radio', 'menuitemcheckbox', 'menuitemradio', 'option', 'treeitem']);
|
|
217
242
|
/** The elements a `disabled` attribute disables. */
|
|
218
243
|
const NATIVE_CONTROLS = new Set(['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA', 'OPTION', 'OPTGROUP', 'FIELDSET']);
|
|
244
|
+
/**
|
|
245
|
+
* The roles an `aria-disabled` above an element reaches, as WAI-ARIA 1.2 and
|
|
246
|
+
* Playwright's `toBeDisabled` list them. The web engine's in-page copy is
|
|
247
|
+
* `ARIA_DISABLED_ROLES` in `packages/web/src/in-page/read-semantics.ts`.
|
|
248
|
+
*/
|
|
249
|
+
const ARIA_DISABLED_ROLES = new Set([
|
|
250
|
+
'application', 'button', 'composite', 'gridcell', 'group', 'input', 'link', 'menuitem', 'scrollbar',
|
|
251
|
+
'separator', 'tab', 'checkbox', 'columnheader', 'combobox', 'grid', 'listbox', 'menu', 'menubar',
|
|
252
|
+
'menuitemcheckbox', 'menuitemradio', 'option', 'radio', 'radiogroup', 'row', 'rowheader', 'searchbox',
|
|
253
|
+
'select', 'slider', 'spinbutton', 'switch', 'tablist', 'textbox', 'toolbar', 'tree', 'treegrid', 'treeitem',
|
|
254
|
+
]);
|
|
255
|
+
/**
|
|
256
|
+
* The tags outside `NATIVE_CONTROLS` and table cells whose role, as the web
|
|
257
|
+
* engine's `tagRole` reads it, is one `ARIA_DISABLED_ROLES` holds. A link
|
|
258
|
+
* needs an `href`.
|
|
259
|
+
*/
|
|
260
|
+
const TAG_WIDGET_ROLES = { A: 'link', TR: 'row', HR: 'separator', DETAILS: 'group', ADDRESS: 'group' };
|
|
261
|
+
/**
|
|
262
|
+
* The role of an element the tree leaves out, as far as an inherited
|
|
263
|
+
* `aria-disabled` needs it: the first token of its `role` that names a
|
|
264
|
+
* WAI-ARIA role, else an editing host's textbox, else its tag's (a table
|
|
265
|
+
* cell's from its table). The tree's role for such an element is `generic`,
|
|
266
|
+
* which says nothing.
|
|
267
|
+
*/
|
|
268
|
+
function domRoleOf(facts) {
|
|
269
|
+
const explicit = explicitRoleOf(facts.attributes);
|
|
270
|
+
if (explicit !== undefined)
|
|
271
|
+
return explicit;
|
|
272
|
+
if (isEditingHost(facts))
|
|
273
|
+
return 'textbox';
|
|
274
|
+
if (facts.nodeName === 'TD' || facts.nodeName === 'TH')
|
|
275
|
+
return facts.cellRole?.();
|
|
276
|
+
if (facts.nodeName === 'A' && !('href' in facts.attributes))
|
|
277
|
+
return undefined;
|
|
278
|
+
return TAG_WIDGET_ROLES[facts.nodeName];
|
|
279
|
+
}
|
|
219
280
|
function statesOf(node, facts, role) {
|
|
220
281
|
const states = {};
|
|
221
282
|
if (isSecure(facts))
|
|
@@ -227,10 +288,22 @@ function statesOf(node, facts, role) {
|
|
|
227
288
|
// An element the accessibility tree leaves out (a control with `hidden`) still has the state its own DOM gives it.
|
|
228
289
|
if (node === undefined && facts !== undefined) {
|
|
229
290
|
if (NATIVE_CONTROLS.has(facts.nodeName))
|
|
230
|
-
states['disabled'] = 'disabled' in facts.attributes;
|
|
231
|
-
|
|
232
|
-
|
|
291
|
+
states['disabled'] = 'disabled' in facts.attributes || facts.inheritsDisabled || facts.ariaDisabled;
|
|
292
|
+
// Anything else has only the state aria-disabled gives it, as the web reads it: its own, whatever it is, and one
|
|
293
|
+
// above it for a role it applies to (role="button", a link, a table row), not a heading or a plain container.
|
|
294
|
+
else if (facts.attributes['aria-disabled']?.toLowerCase() === 'true' || (ARIA_DISABLED_ROLES.has(domRoleOf(facts) ?? '') && facts.ariaDisabled))
|
|
295
|
+
states['disabled'] = true;
|
|
296
|
+
// A native option is selected by its own state, which the tree would have read had it kept the option.
|
|
297
|
+
if (facts.nodeName === 'OPTION')
|
|
298
|
+
states['selected'] = facts.selected;
|
|
299
|
+
const checked = facts.attributes['aria-checked']?.toLowerCase();
|
|
300
|
+
if (ARIA_CHECKABLE.has(facts.attributes['role']?.toLowerCase() ?? '') && checked !== undefined)
|
|
301
|
+
states['checked'] = checked === 'true';
|
|
233
302
|
}
|
|
303
|
+
// A native checkbox or radio is checked by its own checked state, as check() and web() read it: Chromium's tree says
|
|
304
|
+
// mixed for an indeterminate one, checked or not.
|
|
305
|
+
if (facts !== undefined && isCheckable(facts))
|
|
306
|
+
states['checked'] = facts.checked;
|
|
234
307
|
const readOnly = readOnlyOf(node, facts, role);
|
|
235
308
|
if (readOnly !== undefined)
|
|
236
309
|
states['readonly'] = readOnly;
|
package/dist/in-page/node-ops.js
CHANGED
|
@@ -26,14 +26,15 @@ export function nodeOp(node, name, args) {
|
|
|
26
26
|
};
|
|
27
27
|
/** An input's type as the browser reads it (an unknown type is `text`); another element's type attribute. */
|
|
28
28
|
const typeOf = (target) => (target instanceof HTMLInputElement ? target.type : (target.getAttribute('type') ?? '').toLowerCase());
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* The nearest element matching `selector`, from `target` up the tree it is
|
|
31
|
+
* drawn in, as Chromium's tree reads it: a slotted element's slot, and the
|
|
32
|
+
* host of each shadow root (`closest` stops at a root and skips the slot).
|
|
33
|
+
*/
|
|
30
34
|
const above = (target, selector) => {
|
|
31
|
-
for (let at = target; at !== null;) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return found;
|
|
35
|
-
const root = at.getRootNode();
|
|
36
|
-
at = root instanceof ShadowRoot ? root.host : null;
|
|
35
|
+
for (let at = target; at !== null; at = at.assignedSlot ?? at.parentElement ?? at.getRootNode().host ?? null) {
|
|
36
|
+
if (at.matches(selector))
|
|
37
|
+
return at;
|
|
37
38
|
}
|
|
38
39
|
return null;
|
|
39
40
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lock a process holds while it writes a project's Electron binary, so
|
|
3
|
+
* two never extract into one `electron` package at once. A file that names
|
|
4
|
+
* its holder, as `e2e` keeps for its login store (`internal/file-lock.ts`),
|
|
5
|
+
* which an engine cannot import.
|
|
6
|
+
*/
|
|
7
|
+
/** Where the lock of the `electron` package at `directory` is: beside its `install.js`, so projects that link to one package share one lock. */
|
|
8
|
+
export declare function installLockPath(directory: string): string;
|
|
9
|
+
/** Beside install.js while its dist is incomplete, including after an interrupted extraction. */
|
|
10
|
+
export declare const INCOMPLETE_INSTALL = ".e2e-install.incomplete";
|
|
11
|
+
/**
|
|
12
|
+
* Waits for the lock at `lockPath` and returns its release. `onWait` is
|
|
13
|
+
* called once, when another process holds it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function holdInstallLock(lockPath: string, onWait: () => void): Promise<() => void>;
|