@e2e-dev/electron 0.0.0 → 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 +12 -4
- package/dist/.build.json +1 -1
- package/dist/app-process.d.ts +10 -1
- package/dist/app-process.js +89 -22
- package/dist/dialogs.d.ts +3 -1
- package/dist/dialogs.js +10 -3
- package/dist/electron.js +5 -1
- package/dist/engine-entry.d.ts +1 -1
- package/dist/errors.js +4 -3
- package/dist/executable.js +65 -14
- package/dist/expectation.d.ts +30 -0
- package/dist/expectation.js +167 -0
- package/dist/ffmpeg.js +2 -1
- package/dist/fields.js +80 -7
- package/dist/fixtures.d.ts +29 -3
- 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/options.js +4 -4
- package/dist/snapshot.d.ts +69 -4
- package/dist/snapshot.js +214 -18
- package/dist/surface.d.ts +13 -1
- package/dist/surface.js +125 -19
- package/dist/video.d.ts +13 -0
- package/dist/video.js +75 -22
- package/package.json +3 -3
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `expect(electron)` and `electron.waitForURL`: conditions of the active
|
|
3
|
+
* window polled against the assertion timeout, as `expect(browser)` polls a
|
|
4
|
+
* tab's on the web. Each failure reports the last read.
|
|
5
|
+
*/
|
|
6
|
+
import { Deadline, describePattern, EngineError, matchesText, pollCondition, rejectUnknownOptions, stepTimeout, TestError, toTextPattern, urlMatches, withTimeout, } from '@e2e-dev/core/engine';
|
|
7
|
+
export class WindowConditions {
|
|
8
|
+
surface;
|
|
9
|
+
context;
|
|
10
|
+
constructor(surface, context) {
|
|
11
|
+
this.surface = surface;
|
|
12
|
+
this.context = context;
|
|
13
|
+
}
|
|
14
|
+
/** Polls `read` until it matches, or fails with the last read once the assertion timeout (or `timeout`) is over. */
|
|
15
|
+
async poll(call, label, read, timeout) {
|
|
16
|
+
const { context } = this;
|
|
17
|
+
const deadline = new Deadline(context.operation(stepTimeout(timeout, call.api) ?? context.timeouts.assertion).timeoutMs);
|
|
18
|
+
let last;
|
|
19
|
+
await pollCondition({
|
|
20
|
+
deadline,
|
|
21
|
+
signal: context.signal,
|
|
22
|
+
negated: call.negated,
|
|
23
|
+
evaluate: async () => {
|
|
24
|
+
// A dialog nothing answered fails this step, as it fails any other: one that opens under the wait, too.
|
|
25
|
+
this.surface.failOnDialog();
|
|
26
|
+
try {
|
|
27
|
+
last = await read(deadline);
|
|
28
|
+
}
|
|
29
|
+
catch (cause) {
|
|
30
|
+
if (!this.passing(cause))
|
|
31
|
+
throw cause;
|
|
32
|
+
// What the read before it saw stays what the failure reports: this one saw nothing.
|
|
33
|
+
last = { matches: undefined, observed: last?.observed ?? 'nothing: the window was loading or closing' };
|
|
34
|
+
}
|
|
35
|
+
// One that opened while the read ran is this step's too. Outside the catch: it is no read to wait through.
|
|
36
|
+
this.surface.failOnDialog();
|
|
37
|
+
return last.matches;
|
|
38
|
+
},
|
|
39
|
+
onTimeout: (cause) => new TestError('ASSERTION_FAILED', `${call.name} failed\nexpected: ${call.negated ? 'not ' : ''}${label}\nobserved: ${last?.observed ?? 'nothing'}`, cause === undefined ? undefined : { cause }),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Whether a failed read is one a wait goes on through: the document went
|
|
44
|
+
* away under it (a navigation), or the window is closed or not there yet
|
|
45
|
+
* while the app still runs. A read that hangs is the poll's own to judge.
|
|
46
|
+
*/
|
|
47
|
+
passing(cause) {
|
|
48
|
+
if (!(cause instanceof EngineError))
|
|
49
|
+
return false;
|
|
50
|
+
return cause.retryable || (cause.code === 'INVALID_STATE' && this.surface.appRunning && !this.surface.shownCrashed);
|
|
51
|
+
}
|
|
52
|
+
url(call, expected, options) {
|
|
53
|
+
const ignoreCase = options?.ignoreCase;
|
|
54
|
+
if (ignoreCase !== undefined && typeof ignoreCase !== 'boolean')
|
|
55
|
+
throw new TestError('INVALID_ARGUMENT', `${call.name} option ignoreCase must be a boolean`);
|
|
56
|
+
const pattern = toTextPattern(expected);
|
|
57
|
+
// An Electron target has no base URL, and the window's own moves with the wait: a relative string has nothing to resolve against.
|
|
58
|
+
if (pattern.kind !== 'regexp' && !URL.canParse(pattern.value)) {
|
|
59
|
+
throw new TestError('INVALID_ARGUMENT', `${call.name} takes an absolute URL or a RegExp, not ${JSON.stringify(pattern.value)}: an Electron app has no base URL to resolve it against`);
|
|
60
|
+
}
|
|
61
|
+
// Parsed once, on its own: `https:page` would resolve against a base of the same scheme, and the window's moves.
|
|
62
|
+
const wanted = pattern.kind === 'regexp' ? expected : new URL(pattern.value).href;
|
|
63
|
+
return this.poll(call, `URL ${String(wanted)}${ignoreCase === true ? ' (ignoring case)' : ''}`, () => {
|
|
64
|
+
const url = this.surface.shownWindow().page.url();
|
|
65
|
+
return Promise.resolve({ matches: urlMatches(url, wanted, String(wanted), ignoreCase), observed: `URL ${url}` });
|
|
66
|
+
}, options?.timeout);
|
|
67
|
+
}
|
|
68
|
+
/** `electron.waitForURL()`: the poll `expect(electron).toHaveURL` runs. */
|
|
69
|
+
waitForURL(expected, options) {
|
|
70
|
+
rejectUnknownOptions('electron.waitForURL', options, ['timeout']);
|
|
71
|
+
return this.url({ api: 'electron.waitForURL', name: 'electron.waitForURL', negated: false }, expected, options);
|
|
72
|
+
}
|
|
73
|
+
/** The `expect(electron)` matchers, or their negations. */
|
|
74
|
+
expectation(negated = false) {
|
|
75
|
+
const call = (api) => ({ api, name: `expect.${negated ? 'not.' : ''}${api}`, negated });
|
|
76
|
+
const timeoutOf = (api, options) => {
|
|
77
|
+
rejectUnknownOptions(`expect.${negated ? 'not.' : ''}${api}`, options, ['timeout']);
|
|
78
|
+
return options?.timeout;
|
|
79
|
+
};
|
|
80
|
+
const negate = () => this.expectation(!negated);
|
|
81
|
+
return {
|
|
82
|
+
get not() {
|
|
83
|
+
return negate();
|
|
84
|
+
},
|
|
85
|
+
toHaveURL: (expected, options) => {
|
|
86
|
+
rejectUnknownOptions(`expect.${negated ? 'not.' : ''}toHaveURL`, options, ['ignoreCase', 'timeout']);
|
|
87
|
+
return this.url(call('toHaveURL'), expected, options);
|
|
88
|
+
},
|
|
89
|
+
toHaveTitle: (expected, options) => {
|
|
90
|
+
const pattern = toTextPattern(expected, { exact: true });
|
|
91
|
+
return this.poll(call('toHaveTitle'), `title ${describePattern(pattern)}`, async (deadline) => {
|
|
92
|
+
const window = this.surface.shownWindow();
|
|
93
|
+
const switched = whenInactive(this.surface, window);
|
|
94
|
+
let title;
|
|
95
|
+
try {
|
|
96
|
+
// A slow read of a window that is no longer the active one is not waited for: the next poll reads the one that is.
|
|
97
|
+
title = await Promise.race([this.surface.currentTitle(window, this.context.operation(deadline.remaining())), switched.changed]);
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
switched.stop();
|
|
101
|
+
}
|
|
102
|
+
// Another window became the active one while this one answered: its title is not the one asked about.
|
|
103
|
+
if (title === undefined || !this.surface.isActiveWindow(window))
|
|
104
|
+
return { matches: undefined, observed: 'nothing: the active window changed' };
|
|
105
|
+
return { matches: matchesText(title, pattern), observed: `title ${JSON.stringify(title)}` };
|
|
106
|
+
}, timeoutOf('toHaveTitle', options));
|
|
107
|
+
},
|
|
108
|
+
toHaveClass: (target, expected, options) => {
|
|
109
|
+
const pattern = toTextPattern(expected, { exact: true });
|
|
110
|
+
return this.poll(call('toHaveClass'), `class ${describePattern(pattern)}`, async (deadline) => {
|
|
111
|
+
let value;
|
|
112
|
+
try {
|
|
113
|
+
// A locator read takes the action timeout; the poll's deadline is the tighter bound.
|
|
114
|
+
value = await withTimeout(readClass(target), deadline.remaining(), () => new EngineError('OPERATION_TIMEOUT', 'class read timed out', { retryable: false }));
|
|
115
|
+
}
|
|
116
|
+
catch (cause) {
|
|
117
|
+
if (cause.code === 'LOCATOR_NOT_FOUND')
|
|
118
|
+
return { matches: undefined, observed: 'no node' };
|
|
119
|
+
throw cause;
|
|
120
|
+
}
|
|
121
|
+
if (value === undefined)
|
|
122
|
+
return { matches: undefined, observed: 'no node' };
|
|
123
|
+
// An absent attribute is no class list at all, which '' does not match, as on the web.
|
|
124
|
+
if (value === null)
|
|
125
|
+
return { matches: false, observed: 'no class attribute' };
|
|
126
|
+
return { matches: matchesText(value.trim().split(/\s+/).join(' '), pattern), observed: `class ${JSON.stringify(value)}` };
|
|
127
|
+
}, timeoutOf('toHaveClass', options));
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** How often a read of one window checks that the window is still the active one. */
|
|
133
|
+
const ACTIVE_CHECK_MS = 50;
|
|
134
|
+
/**
|
|
135
|
+
* Resolves with undefined once `window` is no longer the active one, checked
|
|
136
|
+
* every `ACTIVE_CHECK_MS` until `stop` is called. Nothing tells the surface
|
|
137
|
+
* of the switch but its own reads, so it is sampled.
|
|
138
|
+
*/
|
|
139
|
+
function whenInactive(surface, window) {
|
|
140
|
+
let timer;
|
|
141
|
+
const changed = new Promise((resolve) => {
|
|
142
|
+
timer = setInterval(() => {
|
|
143
|
+
if (!surface.isActiveWindow(window))
|
|
144
|
+
resolve(undefined);
|
|
145
|
+
}, ACTIVE_CHECK_MS);
|
|
146
|
+
});
|
|
147
|
+
return { changed, stop: () => clearInterval(timer) };
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* The class attribute of one match, undefined while nothing matches. A read
|
|
151
|
+
* waits for its match until the action timeout, so the poll samples absence
|
|
152
|
+
* first: a node that never arrives stays an assertion failure.
|
|
153
|
+
*/
|
|
154
|
+
async function readClass(target) {
|
|
155
|
+
if ((await target.count()) === 0)
|
|
156
|
+
return undefined;
|
|
157
|
+
return target.getAttribute('class');
|
|
158
|
+
}
|
|
159
|
+
/** How the harness records each matcher: an assertion that owns its deadline. */
|
|
160
|
+
export const EXPECTATION_OPERATIONS = {
|
|
161
|
+
toHaveURL: { kind: 'assertion', timeout: false, label: (expected) => String(expected) },
|
|
162
|
+
toHaveTitle: { kind: 'assertion', timeout: false, label: (expected) => String(expected) },
|
|
163
|
+
toHaveClass: { kind: 'assertion', timeout: false, label: (_target, expected) => String(expected) },
|
|
164
|
+
get not() {
|
|
165
|
+
return EXPECTATION_OPERATIONS;
|
|
166
|
+
},
|
|
167
|
+
};
|
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/fixtures.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* what the package's public entries declare, apart from the engine's own
|
|
4
4
|
* modules.
|
|
5
5
|
*/
|
|
6
|
-
import type { Locator } from '@e2e-dev/core/engine';
|
|
6
|
+
import type { Expectable, Locator, TextMatch } from '@e2e-dev/core/engine';
|
|
7
7
|
import type { DialogHandler } from './dialogs.ts';
|
|
8
8
|
/**
|
|
9
9
|
* One window of the running app: a `BrowserWindow`, a `WebContentsView`, or a
|
|
@@ -48,7 +48,7 @@ export type ElectronMainModule = typeof import('electron');
|
|
|
48
48
|
/** What `electron.launch` adds to the target's own launch arguments and the engine's `env`. */
|
|
49
49
|
export interface ElectronLaunchOptions {
|
|
50
50
|
/** Arguments after the target's `app.launchArguments`: the app's own switches and Chromium's. */
|
|
51
|
-
readonly
|
|
51
|
+
readonly launchArguments?: readonly string[] | undefined;
|
|
52
52
|
/** Variables over the engine's `env`. Never `ELECTRON_RUN_AS_NODE` or `NODE_OPTIONS`. */
|
|
53
53
|
readonly env?: Readonly<Record<string, string>> | undefined;
|
|
54
54
|
/** The directory the app's process starts in, over the engine's `cwd`: absolute, or relative to the project root. */
|
|
@@ -86,8 +86,26 @@ export interface ElectronMouse {
|
|
|
86
86
|
/** Scrolls by a wheel turn where the pointer is. */
|
|
87
87
|
wheel(deltaX: number, deltaY: number): Promise<void>;
|
|
88
88
|
}
|
|
89
|
+
/** What `expect(electron)` asserts of the active window, each polled until the assertion timeout or `timeout`. */
|
|
90
|
+
export interface ElectronExpectation {
|
|
91
|
+
/** The same matchers, negated. */
|
|
92
|
+
readonly not: ElectronExpectation;
|
|
93
|
+
/** The window's URL: a string is an absolute URL, compared as one; a `RegExp` is tested against it. */
|
|
94
|
+
toHaveURL(expected: string | RegExp, options?: {
|
|
95
|
+
readonly ignoreCase?: boolean;
|
|
96
|
+
readonly timeout?: number;
|
|
97
|
+
}): Promise<void>;
|
|
98
|
+
/** The window's title, the document's or else the OS window's. */
|
|
99
|
+
toHaveTitle(expected: TextMatch, options?: {
|
|
100
|
+
readonly timeout?: number;
|
|
101
|
+
}): Promise<void>;
|
|
102
|
+
/** The `class` attribute of the one node `target` matches: a string is the whole class list, a `RegExp` is tested against it. */
|
|
103
|
+
toHaveClass(target: Locator, expected: TextMatch, options?: {
|
|
104
|
+
readonly timeout?: number;
|
|
105
|
+
}): Promise<void>;
|
|
106
|
+
}
|
|
89
107
|
/** Deterministic Electron app management exposed to tests as `electron`. */
|
|
90
|
-
export interface Electron {
|
|
108
|
+
export interface Electron extends Expectable<ElectronExpectation> {
|
|
91
109
|
/**
|
|
92
110
|
* The directory the app keeps its data in for this test, empty until the
|
|
93
111
|
* app writes to it. It exists before the app is launched, so a test can
|
|
@@ -104,6 +122,14 @@ export interface Electron {
|
|
|
104
122
|
launch(options?: ElectronLaunchOptions): Promise<void>;
|
|
105
123
|
/** The active window, the one `screen`, `expect`, and the agent act on. Throws `INVALID_STATE` when the app has no open window. */
|
|
106
124
|
activeWindow(): ElectronWindow;
|
|
125
|
+
/**
|
|
126
|
+
* Waits for the active window's URL to match: a string is an absolute URL,
|
|
127
|
+
* never a glob or a path; a `RegExp` is tested against it. Rejects with `ASSERTION_FAILED` after
|
|
128
|
+
* `timeout` milliseconds, or else the assertion timeout.
|
|
129
|
+
*/
|
|
130
|
+
waitForURL(url: string | RegExp, options?: {
|
|
131
|
+
readonly timeout?: number;
|
|
132
|
+
}): Promise<void>;
|
|
107
133
|
/** Keyboard input to the active window. */
|
|
108
134
|
readonly keyboard: ElectronKeyboard;
|
|
109
135
|
/** Pointer input to the active window. */
|
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>;
|
|
@@ -0,0 +1,165 @@
|
|
|
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
|
+
import { randomUUID } from 'node:crypto';
|
|
8
|
+
import { closeSync, openSync, readFileSync, readlinkSync, rmSync, statSync, utimesSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { hostname } from 'node:os';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { sleep } from '@e2e-dev/core/engine';
|
|
12
|
+
/** Where the lock of the `electron` package at `directory` is: beside its `install.js`, so projects that link to one package share one lock. */
|
|
13
|
+
export function installLockPath(directory) {
|
|
14
|
+
return path.join(directory, '.e2e-install.lock');
|
|
15
|
+
}
|
|
16
|
+
/** Beside install.js while its dist is incomplete, including after an interrupted extraction. */
|
|
17
|
+
export const INCOMPLETE_INSTALL = '.e2e-install.incomplete';
|
|
18
|
+
const RETRY_MS = 50;
|
|
19
|
+
/** How long a waiter watches a lock go untouched before it takes it over, whoever it names. */
|
|
20
|
+
const STALE_MS = 10_000;
|
|
21
|
+
/** What a waiter has seen of the file at `file` after one more look. */
|
|
22
|
+
function watch(seen, file) {
|
|
23
|
+
const state = lockState(file);
|
|
24
|
+
return { state, polls: state === seen.state ? seen.polls + 1 : 0 };
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* True when the file's holder ran on this host and has exited, or the waiter
|
|
28
|
+
* has watched the file go unchanged for the stale bound. The bound is counted
|
|
29
|
+
* in the waiter's own polls, never read off a clock: a laptop can sleep
|
|
30
|
+
* through a download, and hosts that share a directory need not agree on the
|
|
31
|
+
* time.
|
|
32
|
+
*/
|
|
33
|
+
function abandoned(seen) {
|
|
34
|
+
return holderExited(seen.state) || seen.polls * RETRY_MS >= STALE_MS;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Waits for the lock at `lockPath` and returns its release. `onWait` is
|
|
38
|
+
* called once, when another process holds it.
|
|
39
|
+
*/
|
|
40
|
+
export async function holdInstallLock(lockPath, onWait) {
|
|
41
|
+
const token = `${holderHost()} ${process.pid} ${randomUUID()}`;
|
|
42
|
+
let lock = { state: '', polls: 0 };
|
|
43
|
+
let turn = { state: '', polls: 0 };
|
|
44
|
+
let waited = false;
|
|
45
|
+
for (;;) {
|
|
46
|
+
if (claim(lockPath, token)) {
|
|
47
|
+
const heartbeat = setInterval(() => {
|
|
48
|
+
if (readLock(lockPath) === token)
|
|
49
|
+
touch(lockPath);
|
|
50
|
+
}, STALE_MS / 4);
|
|
51
|
+
heartbeat.unref();
|
|
52
|
+
return () => {
|
|
53
|
+
clearInterval(heartbeat);
|
|
54
|
+
if (readLock(lockPath) === token)
|
|
55
|
+
rmSync(lockPath, { force: true });
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
lock = watch(lock, lockPath);
|
|
59
|
+
turn = watch(turn, `${lockPath}.break`);
|
|
60
|
+
if (abandoned(lock) && breakAbandoned(lockPath, lock, turn))
|
|
61
|
+
continue;
|
|
62
|
+
if (!waited)
|
|
63
|
+
onWait();
|
|
64
|
+
waited = true;
|
|
65
|
+
await sleep(RETRY_MS);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** Creates `lockPath` holding `token`, false when it exists; a lock whose write failed is removed. */
|
|
69
|
+
function claim(lockPath, token) {
|
|
70
|
+
let fd;
|
|
71
|
+
try {
|
|
72
|
+
fd = openSync(lockPath, 'wx', 0o600);
|
|
73
|
+
}
|
|
74
|
+
catch (cause) {
|
|
75
|
+
if (cause.code === 'EEXIST')
|
|
76
|
+
return false;
|
|
77
|
+
throw cause;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
writeFileSync(fd, token);
|
|
81
|
+
}
|
|
82
|
+
catch (cause) {
|
|
83
|
+
rmSync(lockPath, { force: true });
|
|
84
|
+
throw cause;
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
closeSync(fd);
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
/** This host and, where the system has them, its pid namespace: a container on the same host sees none of the pids outside it. */
|
|
92
|
+
function holderHost() {
|
|
93
|
+
try {
|
|
94
|
+
return `${hostname()}/${readlinkSync('/proc/self/ns/pid')}`;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return hostname();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Marks the lock as held now. */
|
|
101
|
+
function touch(lockPath) {
|
|
102
|
+
const now = new Date();
|
|
103
|
+
try {
|
|
104
|
+
utimesSync(lockPath, now, now);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// Released meanwhile.
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** The lock's holder token, undefined when there is no lock. */
|
|
111
|
+
function readLock(lockPath) {
|
|
112
|
+
try {
|
|
113
|
+
return readFileSync(lockPath, 'utf8');
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/** The lock's holder token and when the holder last touched it, empty when there is no lock. */
|
|
120
|
+
function lockState(lockPath) {
|
|
121
|
+
try {
|
|
122
|
+
return `${readLock(lockPath) ?? ''} ${statSync(lockPath).mtimeMs}`;
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return '';
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/** True when the holder a lock names ran on this host and pid namespace and has exited. */
|
|
129
|
+
function holderExited(state) {
|
|
130
|
+
const [host, pid] = state.split(' ');
|
|
131
|
+
return host === holderHost() && pid !== undefined && /^\d+$/.test(pid) && !running(Number(pid));
|
|
132
|
+
}
|
|
133
|
+
/** True while `pid` exists, whoever owns it. */
|
|
134
|
+
function running(pid) {
|
|
135
|
+
try {
|
|
136
|
+
process.kill(pid, 0);
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
catch (cause) {
|
|
140
|
+
// EPERM: the process exists but belongs to another user.
|
|
141
|
+
return cause.code === 'EPERM';
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Removes the lock a waiter found abandoned, false when another waiter is
|
|
146
|
+
* removing one. Waiters take turns through a second file, and a waiter
|
|
147
|
+
* removes the lock only if it is still the one it watched. A turn lasts
|
|
148
|
+
* microseconds, so one left behind is abandoned by the lock's own rule.
|
|
149
|
+
*/
|
|
150
|
+
function breakAbandoned(lockPath, lock, turn) {
|
|
151
|
+
const breaker = `${lockPath}.break`;
|
|
152
|
+
if (!claim(breaker, `${holderHost()} ${process.pid} ${randomUUID()}`)) {
|
|
153
|
+
if (abandoned(turn) && lockState(breaker) === turn.state)
|
|
154
|
+
rmSync(breaker, { force: true });
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
if (lockState(lockPath) === lock.state)
|
|
159
|
+
rmSync(lockPath, { force: true });
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
rmSync(breaker, { force: true });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the `electron` package's `install.js`, named in argv[2], while it
|
|
3
|
+
* holds that package's install lock. The writer holds the lock, so a run
|
|
4
|
+
* that is killed leaves no unlocked writer behind. `install.js` leaves at
|
|
5
|
+
* once when the binary is in place: the check a process that waited needs.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runs the `electron` package's `install.js`, named in argv[2], while it
|
|
3
|
+
* holds that package's install lock. The writer holds the lock, so a run
|
|
4
|
+
* that is killed leaves no unlocked writer behind. `install.js` leaves at
|
|
5
|
+
* once when the binary is in place: the check a process that waited needs.
|
|
6
|
+
*/
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import { createRequire } from 'node:module';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import { holdInstallLock, INCOMPLETE_INSTALL, installLockPath } from './install-lock.js';
|
|
11
|
+
const [script] = process.argv.slice(2);
|
|
12
|
+
const directory = path.dirname(script);
|
|
13
|
+
const release = await holdInstallLock(installLockPath(directory), () => {
|
|
14
|
+
console.log('waiting for another run that is downloading the Electron binary');
|
|
15
|
+
});
|
|
16
|
+
// No signal handler: a cancelled run's signal ends this process at once, and its lock is taken over only once it is gone.
|
|
17
|
+
const incomplete = path.join(directory, INCOMPLETE_INSTALL);
|
|
18
|
+
const pathFile = path.join(directory, 'path.txt');
|
|
19
|
+
process.on('exit', (code) => {
|
|
20
|
+
try {
|
|
21
|
+
if (code === 0 && existsSync(pathFile))
|
|
22
|
+
rmSync(incomplete, { force: true });
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
release();
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
// `install.js` writes `path.txt` last. One left by an earlier download would call this one's binary ready while it is still being written.
|
|
29
|
+
const name = existsSync(pathFile) ? readFileSync(pathFile, 'utf8').trim() : '';
|
|
30
|
+
const dist = path.join(directory, 'dist');
|
|
31
|
+
if (!name || !existsSync(path.join(dist, name))) {
|
|
32
|
+
// Linked overrides can resolve the destination while install.js is still fetching the archive.
|
|
33
|
+
mkdirSync(dist, { recursive: true });
|
|
34
|
+
writeFileSync(incomplete, '');
|
|
35
|
+
rmSync(pathFile, { force: true });
|
|
36
|
+
}
|
|
37
|
+
createRequire(script)(script);
|
package/dist/launcher.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ export interface ProcessExit {
|
|
|
15
15
|
readonly code: number | null;
|
|
16
16
|
readonly signal: NodeJS.Signals | null;
|
|
17
17
|
}
|
|
18
|
-
/** The
|
|
19
|
-
export declare function
|
|
18
|
+
/** The command line an app starts with: the engine's switches, the caller's own (the app path first), then the engine's for the OS. */
|
|
19
|
+
export declare function processArguments(args: readonly string[], platform?: NodeJS.Platform): string[];
|
|
20
20
|
export declare class ElectronProcess {
|
|
21
21
|
/** The DevTools protocol of the app's browser process, over the pipe. */
|
|
22
22
|
readonly browser: Connection;
|
package/dist/launcher.js
CHANGED
|
@@ -16,8 +16,20 @@ const INSPECTOR_LISTENING = /^Debugger listening on (ws:\/\/\S+)/;
|
|
|
16
16
|
const INSPECTOR_NOISE = /^(Debugger listening on |For help, see: https:\/\/nodejs\.org\/|Debugger attached\.|Waiting for the debugger to disconnect)/;
|
|
17
17
|
/** Printed when the process is done and only the inspector's client keeps it alive. */
|
|
18
18
|
const INSPECTOR_WAITING = /Waiting for the debugger to disconnect/;
|
|
19
|
+
/** The command line an app starts with: the engine's switches, the caller's own (the app path first), then the engine's for the OS. */
|
|
20
|
+
export function processArguments(args, platform = process.platform) {
|
|
21
|
+
return [
|
|
22
|
+
...engineArguments(args, platform),
|
|
23
|
+
...args,
|
|
24
|
+
// macOS asks, in a modal alert before the app is ready, whether to reopen the windows of an app that quit uncleanly,
|
|
25
|
+
// as the engine's kills leave it: the launch would wait out its timeout. After the app's own arguments, since Electron
|
|
26
|
+
// takes the first one that is no switch as the app's path. Two arguments, both left in the app's argv, the YES no switch: macOS
|
|
27
|
+
// reads no one-argument form (`-ApplePersistenceIgnoreState=YES` sets nothing on Electron 45).
|
|
28
|
+
...(platform === 'darwin' ? ['-ApplePersistenceIgnoreState', 'YES'] : []),
|
|
29
|
+
];
|
|
30
|
+
}
|
|
19
31
|
/** The switches the engine starts every app with, before the caller's own. */
|
|
20
|
-
|
|
32
|
+
function engineArguments(args, platform) {
|
|
21
33
|
return [
|
|
22
34
|
// The main process's inspector, on a port of its own choosing, for electron.evaluate.
|
|
23
35
|
'--inspect=0',
|
|
@@ -64,7 +76,7 @@ export class ElectronProcess {
|
|
|
64
76
|
waitingHandlers = [];
|
|
65
77
|
constructor(command) {
|
|
66
78
|
killAtExit();
|
|
67
|
-
this.child = spawn(command.executable,
|
|
79
|
+
this.child = spawn(command.executable, processArguments(command.args), {
|
|
68
80
|
cwd: command.cwd,
|
|
69
81
|
env: command.env,
|
|
70
82
|
// fd 3 carries the engine's commands and fd 4 the browser's answers. stdout is not read: an unread pipe would stall the app.
|