@e2e-dev/electron 0.0.0-stage → 0.0.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.
Files changed (75) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +91 -2
  4. package/dist/.build.json +1 -0
  5. package/dist/actionability.d.ts +41 -0
  6. package/dist/actionability.js +121 -0
  7. package/dist/actions.d.ts +52 -0
  8. package/dist/actions.js +418 -0
  9. package/dist/app-process.d.ts +114 -0
  10. package/dist/app-process.js +610 -0
  11. package/dist/budget.d.ts +33 -0
  12. package/dist/budget.js +64 -0
  13. package/dist/capture.d.ts +21 -0
  14. package/dist/capture.js +137 -0
  15. package/dist/cdp/connection.d.ts +68 -0
  16. package/dist/cdp/connection.js +232 -0
  17. package/dist/cdp/input.d.ts +67 -0
  18. package/dist/cdp/input.js +195 -0
  19. package/dist/cdp/keys.d.ts +21 -0
  20. package/dist/cdp/keys.js +114 -0
  21. package/dist/console-text.d.ts +4 -0
  22. package/dist/console-text.js +27 -0
  23. package/dist/devtools.d.ts +36 -0
  24. package/dist/devtools.js +111 -0
  25. package/dist/dialogs.d.ts +38 -0
  26. package/dist/dialogs.js +81 -0
  27. package/dist/electron.d.ts +9 -0
  28. package/dist/electron.js +174 -0
  29. package/dist/engine-entry.d.ts +13 -0
  30. package/dist/engine-entry.js +9 -0
  31. package/dist/engine.d.ts +27 -0
  32. package/dist/engine.js +98 -0
  33. package/dist/errors.d.ts +17 -0
  34. package/dist/errors.js +54 -0
  35. package/dist/evaluate.d.ts +40 -0
  36. package/dist/evaluate.js +115 -0
  37. package/dist/executable.d.ts +29 -0
  38. package/dist/executable.js +249 -0
  39. package/dist/ffmpeg.d.ts +12 -0
  40. package/dist/ffmpeg.js +100 -0
  41. package/dist/fields.d.ts +93 -0
  42. package/dist/fields.js +254 -0
  43. package/dist/file-bound.d.ts +31 -0
  44. package/dist/file-bound.js +104 -0
  45. package/dist/fixtures.d.ts +168 -0
  46. package/dist/fixtures.js +6 -0
  47. package/dist/in-page/masks.d.ts +25 -0
  48. package/dist/in-page/masks.js +140 -0
  49. package/dist/in-page/node-ops.d.ts +96 -0
  50. package/dist/in-page/node-ops.js +406 -0
  51. package/dist/index.d.ts +18 -0
  52. package/dist/index.js +18 -0
  53. package/dist/launcher.d.ts +45 -0
  54. package/dist/launcher.js +167 -0
  55. package/dist/locate.d.ts +46 -0
  56. package/dist/locate.js +103 -0
  57. package/dist/main-process.d.ts +25 -0
  58. package/dist/main-process.js +60 -0
  59. package/dist/options.d.ts +65 -0
  60. package/dist/options.js +120 -0
  61. package/dist/page.d.ts +100 -0
  62. package/dist/page.js +229 -0
  63. package/dist/runner-test.d.ts +15 -0
  64. package/dist/runner-test.js +45 -0
  65. package/dist/snapshot.d.ts +143 -0
  66. package/dist/snapshot.js +260 -0
  67. package/dist/surface.d.ts +158 -0
  68. package/dist/surface.js +602 -0
  69. package/dist/tree.d.ts +51 -0
  70. package/dist/tree.js +406 -0
  71. package/dist/video.d.ts +42 -0
  72. package/dist/video.js +253 -0
  73. package/dist/windows.d.ts +81 -0
  74. package/dist/windows.js +200 -0
  75. package/package.json +72 -3
package/dist/fields.js ADDED
@@ -0,0 +1,254 @@
1
+ /**
2
+ * What one element reads as: its role, states, level, value, and attributes,
3
+ * each a pure function of the element's accessibility node (when Chromium
4
+ * gave it one) and its DOM facts. An element the accessibility tree leaves
5
+ * out reads by the same rules with no accessibility node.
6
+ */
7
+ import { isSecureField } from './snapshot.js';
8
+ /**
9
+ * Chromium's own role names mapped to the roles of the engine contract's
10
+ * vocabulary, where an image is `image` (`getByRole('img')` is that role's
11
+ * alias, resolved before it reaches the tree). A role missing here and spelled
12
+ * with a capital is Chromium-internal and reads as a generic container.
13
+ */
14
+ const CHROMIUM_ROLES = {
15
+ image: 'image',
16
+ MenuListPopup: 'listbox',
17
+ MenuListOption: 'option',
18
+ Iframe: 'iframe',
19
+ IframePresentational: 'iframe',
20
+ DisclosureTriangle: 'button',
21
+ // Date, time, and color inputs, which the web reads as text fields.
22
+ Date: 'textbox',
23
+ DateTime: 'textbox',
24
+ InputTime: 'textbox',
25
+ ColorWell: 'textbox',
26
+ Canvas: 'image',
27
+ Video: 'generic',
28
+ Audio: 'generic',
29
+ };
30
+ /** Containers that say nothing on their own: kept only with a name, a test id, or for a locator's `selector`. */
31
+ const GENERIC_ROLES = new Set(['generic', 'none', 'presentation', 'LabelText', 'Section', 'Pre', 'Ruby', 'Abbr', 'Mark', 'Legend', 'Unknown']);
32
+ /** Reasons Chromium leaves a node out that also hide it from a person: its subtree never reaches the tree. */
33
+ const HIDING_REASONS = new Set(['ariaHiddenElement', 'ariaHiddenSubtree', 'notRendered', 'inertElement', 'inertSubtree', 'notVisible']);
34
+ /** Roles whose value is what a person typed or picked. */
35
+ const VALUE_ROLES = new Set(['textbox', 'searchbox', 'combobox', 'spinbutton', 'slider']);
36
+ /** ARIA range roles: an element's value is its `aria-valuetext`, else its `aria-valuenow`, as written, as the web reads it. */
37
+ const RANGE_ROLES = new Set(['slider', 'spinbutton', 'progressbar', 'meter', 'scrollbar']);
38
+ /** Roles whose read-only state is their `aria-readonly`, as the web reads it. */
39
+ const ARIA_READONLY_ROLES = new Set([
40
+ 'checkbox', 'combobox', 'grid', 'gridcell', 'listbox', 'radiogroup', 'slider', 'spinbutton', 'textbox',
41
+ 'searchbox', 'columnheader', 'rowheader', 'switch', 'treegrid',
42
+ ]);
43
+ /** Roles whose level is their `aria-level`, as the web reads it; a heading element's comes from its tag. */
44
+ const LEVEL_ROLES = new Set(['heading', 'listitem', 'row', 'treeitem']);
45
+ /** The states read straight from Chromium's properties. */
46
+ const AX_STATES = new Set(['checked', 'pressed', 'disabled', 'expanded', 'selected', 'focused']);
47
+ export function stringOf(value) {
48
+ const raw = value?.value;
49
+ if (raw === undefined || raw === null)
50
+ return undefined;
51
+ return typeof raw === 'string' ? raw : String(raw);
52
+ }
53
+ function property(node, name) {
54
+ return node?.properties?.find((entry) => entry.name === name)?.value.value;
55
+ }
56
+ /** Whether Chromium hides the node from a person, and its subtree with it. */
57
+ export function isHiddenSubtree(node) {
58
+ return node.ignored && node.ignoredReasons?.some((reason) => HIDING_REASONS.has(reason.name)) === true;
59
+ }
60
+ /** A focusable element with no role (a span with a tabindex) is a control of the app's own. */
61
+ export function isFocusable(node) {
62
+ return !node.ignored && property(node, 'focusable') === true;
63
+ }
64
+ function isEditingHost(facts) {
65
+ const editable = facts?.attributes['contenteditable'];
66
+ return editable !== undefined && editable.toLowerCase() !== 'false';
67
+ }
68
+ /** An input or textarea: its value is the element's own, and its inner editor is not read as text. */
69
+ export function isTextField(facts) {
70
+ return facts?.nodeName === 'INPUT' || facts?.nodeName === 'TEXTAREA';
71
+ }
72
+ /** An input drawn as a button: the value it shows is its text, as the web reads it. */
73
+ export function isButtonInput(facts) {
74
+ return facts?.nodeName === 'INPUT' && ['submit', 'button'].includes(facts.attributes['type']?.toLowerCase() ?? '');
75
+ }
76
+ export function isSecure(facts) {
77
+ return facts !== undefined && isSecureField(facts.nodeName, facts.attributes);
78
+ }
79
+ export function isCheckable(facts) {
80
+ return facts?.nodeName === 'INPUT' && ['checkbox', 'radio'].includes(facts.attributes['type']?.toLowerCase() ?? '');
81
+ }
82
+ export function roleOf(node, facts, policy) {
83
+ const chromium = stringOf(node.role) ?? '';
84
+ const mapped = CHROMIUM_ROLES[chromium] ?? (/^[A-Z]/.test(chromium) ? 'generic' : chromium);
85
+ const generic = mapped === 'generic' || GENERIC_ROLES.has(chromium);
86
+ const role = policy.editingHostRole && generic && isEditingHost(facts) ? 'textbox' : mapped;
87
+ return { role, silent: node.ignored || (role !== 'textbox' && generic) };
88
+ }
89
+ function inputPurposeOf(facts) {
90
+ const autocomplete = facts.attributes['autocomplete']?.toLowerCase();
91
+ if (isSecure(facts) || autocomplete === 'current-password' || autocomplete === 'new-password')
92
+ return 'password';
93
+ return autocomplete === 'username' || autocomplete === 'one-time-code' ? autocomplete : undefined;
94
+ }
95
+ /**
96
+ * A heading element's level is its tag's, whatever its aria-level; an ARIA
97
+ * role's is its aria-level, as the web reads them (Chromium computes one for
98
+ * every treeitem, and a default for a role="heading" with none).
99
+ */
100
+ function levelOf(role, facts) {
101
+ const tagLevel = /^H([1-6])$/.exec(facts?.nodeName ?? '')?.[1];
102
+ if (role === 'heading' && tagLevel !== undefined)
103
+ return Number(tagLevel);
104
+ const ariaLevel = Number.parseInt(facts?.attributes['aria-level'] ?? '', 10);
105
+ return LEVEL_ROLES.has(role) && ariaLevel >= 1 ? ariaLevel : undefined;
106
+ }
107
+ /**
108
+ * Whether the element is read-only, as the web reads it: a native field by
109
+ * its `readonly` attribute, whatever Chromium reports for it (nothing for a
110
+ * select); then what Chromium reports; then a role that takes `aria-readonly`
111
+ * by that attribute. An editing host, and an element inside one, takes text:
112
+ * Chromium marks it `editable` and gives no read-only state. Undefined for
113
+ * anything else, which has no read-only state.
114
+ */
115
+ function readOnlyOf(node, facts, role) {
116
+ if (isTextField(facts) || facts?.nodeName === 'SELECT')
117
+ return 'readonly' in facts.attributes;
118
+ // What the element says of itself comes first: Chromium reports an editing host as not read-only whatever it says.
119
+ const said = ARIA_READONLY_ROLES.has(role) ? facts?.attributes['aria-readonly']?.toLowerCase() : undefined;
120
+ if (said !== undefined)
121
+ return said === 'true';
122
+ const reported = property(node, 'readonly');
123
+ if (reported !== undefined)
124
+ return reported === true || reported === 'true';
125
+ if (ARIA_READONLY_ROLES.has(role))
126
+ return false;
127
+ return node?.properties?.some((entry) => entry.name === 'editable') === true ? false : undefined;
128
+ }
129
+ /**
130
+ * A range widget's value as the web reads it. An ARIA value reads as written,
131
+ * since Chromium clamps aria-valuenow, drops aria-valuetext, and makes up a
132
+ * midpoint; a blank one is none. Without one, a native progress or meter
133
+ * element with a value attribute reads its `.value`, clamped to its range,
134
+ * which is what Chromium reports for it. A slider or spinbutton with no value
135
+ * reads as empty; any other range widget, an indeterminate progress element
136
+ * among them, has none.
137
+ */
138
+ function rangeValueOf(node, facts, role) {
139
+ const filled = (value) => (value === undefined || value.trim() === '' ? undefined : value);
140
+ const attributes = facts?.attributes ?? {};
141
+ const aria = filled(attributes['aria-valuetext']) ?? filled(attributes['aria-valuenow']);
142
+ if (aria !== undefined)
143
+ return aria;
144
+ const native = (facts?.nodeName === 'PROGRESS' || facts?.nodeName === 'METER') && 'value' in attributes ? stringOf(node?.value) : undefined;
145
+ return native ?? (role === 'slider' || role === 'spinbutton' ? '' : undefined);
146
+ }
147
+ function valueOf(node, facts, role, policy) {
148
+ // A select's value is what its chosen option submits, as `select.value` reads it; its options name the labels.
149
+ if (facts?.nodeName === 'SELECT')
150
+ return facts.selectValue ?? '';
151
+ // A checkbox or radio submits its value attribute, `on` without one, whatever its state.
152
+ if (isCheckable(facts))
153
+ return policy.checkableValue ? (facts.attributes['value'] ?? 'on') : undefined;
154
+ if (isSecure(facts))
155
+ return undefined;
156
+ // A field's value is the element's own, whatever role Chromium gives it (a date input is no textbox).
157
+ if (isTextField(facts))
158
+ return (facts.nodeName === 'INPUT' ? facts.inputValue : facts.textValue) ?? '';
159
+ if (RANGE_ROLES.has(role))
160
+ return rangeValueOf(node, facts, role);
161
+ // An editing host or an ARIA widget has no DOM value: its value is the one Chromium computes. A combobox that only
162
+ // shows its choice (a div) has none, as on the web; Chromium would echo its text.
163
+ if (VALUE_ROLES.has(role) && (role !== 'combobox' || isEditingHost(facts)))
164
+ return stringOf(node?.value) ?? '';
165
+ return undefined;
166
+ }
167
+ /**
168
+ * A link as an observation shows it, as the web engine reduces it: origin and
169
+ * path, a query and a fragment only as `?…` and `#…` (they routinely carry
170
+ * tokens), and a scheme with no origin (`data:`, `javascript:`), whose path
171
+ * is a whole file or script, as `scheme:…`. A relative link resolves against
172
+ * the document's URL. The web engine's own copy is `originAndPath` in
173
+ * `packages/web/src/in-page/read-semantics.ts`: a change to what either hides
174
+ * belongs in both. They differ in one place on purpose: this one shows a
175
+ * `file:` path, since an Electron app's own pages are local files.
176
+ */
177
+ function originAndPath(value, base) {
178
+ const elided = (query, fragment) => `${query ? '?…' : ''}${fragment ? '#…' : ''}`;
179
+ try {
180
+ const url = new URL(value, base);
181
+ const rest = `${url.pathname}${elided(url.search !== '', url.hash !== '')}`;
182
+ if (url.protocol === 'blob:') {
183
+ const inner = URL.canParse(url.pathname) ? new URL(url.pathname) : null;
184
+ return inner === null || inner.origin === 'null' ? 'blob:…' : `blob:${inner.origin}${inner.pathname}${elided(url.search !== '', url.hash !== '')}`;
185
+ }
186
+ if (url.origin !== 'null')
187
+ return `${url.origin}${rest}`;
188
+ // A local page's links are files beside it: the path says where one goes, as the web shows it.
189
+ if (url.protocol === 'mailto:' || url.protocol === 'tel:' || url.protocol === 'file:')
190
+ return `${url.protocol}${url.protocol === 'file:' ? '//' : ''}${rest}`;
191
+ return `${url.protocol}…`;
192
+ }
193
+ catch {
194
+ const [beforeFragment = '', ...fragment] = value.split('#');
195
+ const [path = '', ...query] = beforeFragment.split('?');
196
+ return `${path}${elided(query.join('?') !== '', fragment.join('#') !== '')}`;
197
+ }
198
+ }
199
+ /**
200
+ * The attributes a read shows. Whole, as the web engine keeps them: the
201
+ * harness redacts an attribute by whole values only, so a cut here could
202
+ * leave the start of a secret behind; it bounds what it renders after
203
+ * redaction.
204
+ */
205
+ function shownAttributes(facts, policy, baseUrl) {
206
+ const shown = {};
207
+ const secure = isSecure(facts);
208
+ for (const [key, value] of Object.entries(facts.attributes)) {
209
+ if (secure && key === 'value')
210
+ continue;
211
+ if (policy.attributes !== null && !policy.attributes.has(key) && !key.startsWith('aria-'))
212
+ continue;
213
+ shown[key] = policy.redactHref && key === 'href' ? originAndPath(value, baseUrl) : value;
214
+ }
215
+ return shown;
216
+ }
217
+ /** The elements a `disabled` attribute disables. */
218
+ const NATIVE_CONTROLS = new Set(['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA', 'OPTION', 'OPTGROUP', 'FIELDSET']);
219
+ function statesOf(node, facts, role) {
220
+ const states = {};
221
+ if (isSecure(facts))
222
+ states['secure'] = true;
223
+ for (const { name, value } of node?.properties ?? []) {
224
+ if (AX_STATES.has(name))
225
+ states[name] = value.value === true || value.value === 'true';
226
+ }
227
+ // An element the accessibility tree leaves out (a control with `hidden`) still has the state its own DOM gives it.
228
+ if (node === undefined && facts !== undefined) {
229
+ if (NATIVE_CONTROLS.has(facts.nodeName))
230
+ states['disabled'] = 'disabled' in facts.attributes;
231
+ if (isCheckable(facts))
232
+ states['checked'] = facts.checked;
233
+ }
234
+ const readOnly = readOnlyOf(node, facts, role);
235
+ if (readOnly !== undefined)
236
+ states['readonly'] = readOnly;
237
+ return states;
238
+ }
239
+ /** Reads an element's fields. `node` is undefined for an element the accessibility tree leaves out. */
240
+ export function elementFields(node, facts, role, context) {
241
+ const testId = facts?.attributes[context.testIdAttribute.toLowerCase()];
242
+ const inputPurpose = facts === undefined ? undefined : inputPurposeOf(facts);
243
+ const level = levelOf(role, facts);
244
+ const value = valueOf(node, facts, role, context.policy);
245
+ const attributes = facts === undefined ? {} : shownAttributes(facts, context.policy, context.baseUrl);
246
+ return {
247
+ states: statesOf(node, facts, role),
248
+ ...(testId === undefined ? {} : { testId }),
249
+ ...(inputPurpose === undefined ? {} : { inputPurpose }),
250
+ ...(level === undefined ? {} : { level }),
251
+ ...(value === undefined ? {} : { value }),
252
+ ...(Object.keys(attributes).length === 0 ? {} : { attributes }),
253
+ };
254
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The bound on local files: an Electron app loads its own `file:` pages, and
3
+ * a link or a script in one can take a window to any file the user can read.
4
+ * A window that left the app's own directory is not observed, traced, or
5
+ * captured.
6
+ */
7
+ /** What is known of where the app's files are. */
8
+ export interface AppFiles {
9
+ /** `app.getAppPath()`, when the main process answered: the app's directory, or its `.asar` archive. */
10
+ readonly reported: string | undefined;
11
+ /** The target's `app.appPath`, resolved: a directory or the main script. */
12
+ readonly declared: string | undefined;
13
+ /** The first document the app showed. */
14
+ readonly firstDocument: string;
15
+ /** The project's root: a main script's package is looked for no higher. */
16
+ readonly projectRoot: string;
17
+ }
18
+ /**
19
+ * The directory the app's own pages are in, or undefined when nothing says:
20
+ * for a declared main script, the package it belongs to; else what the main
21
+ * process reports, else the declared app path, else the archive or directory
22
+ * of the first local page the app showed.
23
+ */
24
+ export declare function appDirectory({ reported, declared, firstDocument, projectRoot }: AppFiles): string | undefined;
25
+ /**
26
+ * Why a window at `location` is not one to observe or capture, or undefined
27
+ * when it is: a `file:` location outside the app's directory. With no
28
+ * directory known, every `file:` location is outside: the rule fails closed.
29
+ * Any other location passes.
30
+ */
31
+ export declare function outsideApp(location: string, directory: string | undefined): string | undefined;
@@ -0,0 +1,104 @@
1
+ /**
2
+ * The bound on local files: an Electron app loads its own `file:` pages, and
3
+ * a link or a script in one can take a window to any file the user can read.
4
+ * A window that left the app's own directory is not observed, traced, or
5
+ * captured.
6
+ */
7
+ import { existsSync, readFileSync, realpathSync, statSync } from 'node:fs';
8
+ import path from 'node:path';
9
+ import { fileURLToPath } from 'node:url';
10
+ /**
11
+ * The directory the app's own pages are in, or undefined when nothing says:
12
+ * for a declared main script, the package it belongs to; else what the main
13
+ * process reports, else the declared app path, else the archive or directory
14
+ * of the first local page the app showed.
15
+ */
16
+ export function appDirectory({ reported, declared, firstDocument, projectRoot }) {
17
+ // Electron reports a main script's own directory, and a build can put the pages beside it (`out/main/index.js`
18
+ // and `out/renderer/`): the app is the package the script is in, as it is for an app path that names the directory.
19
+ // An `.asar` archive is a file too, and the app itself, as Electron reports it: its bound is the archive.
20
+ if (declared !== undefined && !/\.asar$/i.test(declared) && statSync(declared, { throwIfNoEntry: false })?.isFile() === true)
21
+ return canonical(packageOf(declared, projectRoot) ?? path.dirname(declared));
22
+ if (reported !== undefined && reported !== '')
23
+ return canonical(reported);
24
+ if (declared !== undefined)
25
+ return canonical(statSync(declared, { throwIfNoEntry: false })?.isDirectory() === true ? declared : path.dirname(declared));
26
+ const file = localFile(firstDocument);
27
+ if (file === undefined)
28
+ return undefined;
29
+ const archive = /^(.*?\.asar)(?:[\\/]|$)/.exec(file)?.[1];
30
+ return canonical(archive ?? path.dirname(file));
31
+ }
32
+ /**
33
+ * Why a window at `location` is not one to observe or capture, or undefined
34
+ * when it is: a `file:` location outside the app's directory. With no
35
+ * directory known, every `file:` location is outside: the rule fails closed.
36
+ * Any other location passes.
37
+ */
38
+ export function outsideApp(location, directory) {
39
+ if (!URL.canParse(location) || new URL(location).protocol !== 'file:')
40
+ return undefined;
41
+ const file = localFile(location);
42
+ const shown = `file://${new URL(location).pathname}`;
43
+ if (file === undefined || directory === undefined)
44
+ return `the window shows a local file, ${shown}, and the app's own directory is not known, so it is not read`;
45
+ const relative = path.relative(directory, canonical(file));
46
+ const inside = relative !== '..' && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
47
+ return inside ? undefined : `the window left the app's directory for ${shown}, a local file outside it, so it is not read`;
48
+ }
49
+ /**
50
+ * The nearest directory above `file`, up to the project's root, with a
51
+ * `package.json` that names a package, or undefined when none has one: a
52
+ * manifest above the project (a home directory's, a monorepo's) is no package
53
+ * of this app's. A manifest that only sets the module type
54
+ * (`{"type":"commonjs"}`, which build tools write into their output) marks
55
+ * how Node loads the files there, not a package of its own.
56
+ */
57
+ function packageOf(file, projectRoot) {
58
+ const top = path.resolve(projectRoot);
59
+ for (let directory = path.dirname(path.resolve(file));; directory = path.dirname(directory)) {
60
+ const relative = path.relative(top, directory);
61
+ if (relative === '..' || relative.startsWith(`..${path.sep}`) || path.isAbsolute(relative))
62
+ return undefined;
63
+ const manifest = path.join(directory, 'package.json');
64
+ if (existsSync(manifest) && !onlyModuleType(manifest))
65
+ return directory;
66
+ if (relative === '')
67
+ return undefined;
68
+ }
69
+ }
70
+ function onlyModuleType(manifest) {
71
+ try {
72
+ const parsed = JSON.parse(readFileSync(manifest, 'utf8'));
73
+ return typeof parsed === 'object' && parsed !== null && Object.keys(parsed).join() === 'type';
74
+ }
75
+ catch {
76
+ // A manifest that cannot be read is no proof the package is elsewhere: the nearer directory is the narrower bound.
77
+ return false;
78
+ }
79
+ }
80
+ function localFile(location) {
81
+ try {
82
+ return fileURLToPath(location);
83
+ }
84
+ catch {
85
+ return undefined;
86
+ }
87
+ }
88
+ /** A path with its links resolved, as far as it exists: a page inside an `.asar` archive is no file on disk. */
89
+ function canonical(file) {
90
+ const rest = [];
91
+ let at = path.resolve(file);
92
+ for (;;) {
93
+ try {
94
+ return path.join(realpathSync(at), ...rest);
95
+ }
96
+ catch {
97
+ const parent = path.dirname(at);
98
+ if (parent === at)
99
+ return path.resolve(file);
100
+ rest.unshift(path.basename(at));
101
+ at = parent;
102
+ }
103
+ }
104
+ }
@@ -0,0 +1,168 @@
1
+ /**
2
+ * The `electron` fixture an `electron()` target contributes, as types only:
3
+ * what the package's public entries declare, apart from the engine's own
4
+ * modules.
5
+ */
6
+ import type { Locator } from '@e2e-dev/core/engine';
7
+ import type { DialogHandler } from './dialogs.ts';
8
+ /**
9
+ * One window of the running app: a `BrowserWindow`, a `WebContentsView`, or a
10
+ * `<webview>` guest. The same window is the same object for as long as the
11
+ * app runs.
12
+ */
13
+ export interface ElectronWindow {
14
+ /** The document's current title, or the OS window's when the document has none. */
15
+ title(): Promise<string>;
16
+ /** The page's current URL. */
17
+ url(): Promise<string>;
18
+ /** Whether this is the active window, the one `screen`, `expect`, and the agent act on. */
19
+ isActive(): boolean;
20
+ /** Whether the window has closed. */
21
+ isClosed(): boolean;
22
+ /** Makes this the active window. Rejects with `ACTION_FAILED` when it has closed. */
23
+ activate(): Promise<void>;
24
+ /**
25
+ * Runs `fn` in the window's page, with the app's own globals, and returns
26
+ * what it returns, which must be JSON. `fn` is sent as source text: it
27
+ * cannot close over the test's variables, so pass them as `arg`.
28
+ */
29
+ evaluate<R>(fn: () => R | Promise<R>): Promise<R>;
30
+ /** Runs `fn` in the window's page with `arg`, which must be JSON. */
31
+ evaluate<R, A>(fn: (arg: A) => R | Promise<R>, arg: A): Promise<R>;
32
+ /** Reloads the window's document and resolves once it has loaded again. */
33
+ reload(): Promise<void>;
34
+ /** Closes the window, past any `beforeunload` guard. When it was the active window, the window that opened it is active again, else the one active before it. */
35
+ close(): Promise<void>;
36
+ }
37
+ /** Which window `electron.window` finds: the first whose title (the document's or the OS window's) and URL match, a string exactly or a RegExp. */
38
+ export interface WindowMatcher {
39
+ readonly title?: string | RegExp;
40
+ readonly url?: string | RegExp;
41
+ }
42
+ /**
43
+ * The main process's `electron` module, as a function passed to `evaluate`
44
+ * receives it: typed by the project's own `electron` package, a peer of
45
+ * this one.
46
+ */
47
+ export type ElectronMainModule = typeof import('electron');
48
+ /** What `electron.launch` adds to the target's own launch arguments and the engine's `env`. */
49
+ export interface ElectronLaunchOptions {
50
+ /** Arguments after the target's `app.launchArguments`: the app's own switches and Chromium's. */
51
+ readonly args?: readonly string[] | undefined;
52
+ /** Variables over the engine's `env`. Never `ELECTRON_RUN_AS_NODE` or `NODE_OPTIONS`. */
53
+ readonly env?: Readonly<Record<string, string>> | undefined;
54
+ /** The directory the app's process starts in, over the engine's `cwd`: absolute, or relative to the project root. */
55
+ readonly cwd?: string | undefined;
56
+ /** How long the launch may take, in milliseconds. Default: the test's `timeout`. */
57
+ readonly timeout?: number | undefined;
58
+ }
59
+ /** Keyboard input to the active window, for whatever holds focus there. */
60
+ export interface ElectronKeyboard {
61
+ /** Presses one key, with its modifiers: `'Escape'`, `'ControlOrMeta+A'`, `'Shift+Tab'`. */
62
+ press(key: string): Promise<void>;
63
+ /** Holds one key until `up`; a held modifier applies to the keys and mouse events after it. */
64
+ down(key: string): Promise<void>;
65
+ /** Releases a held key. */
66
+ up(key: string): Promise<void>;
67
+ /** Types plain text key by key, `delay` milliseconds apart. Never a secret: fill one with `locator.fill`. */
68
+ type(text: string, options?: {
69
+ readonly delay?: number;
70
+ }): Promise<void>;
71
+ /** Inserts text as an input method's commit would: input events and no key events. */
72
+ insertText(text: string): Promise<void>;
73
+ }
74
+ /** Pointer input to the active window, in viewport CSS pixels. */
75
+ export interface ElectronMouse {
76
+ /** Moves the pointer to a point of the viewport. */
77
+ move(x: number, y: number): Promise<void>;
78
+ /** Presses a button where the pointer is; the left one by default. */
79
+ down(options?: {
80
+ readonly button?: 'left' | 'right' | 'middle';
81
+ }): Promise<void>;
82
+ /** Releases a button where the pointer is; the left one by default. */
83
+ up(options?: {
84
+ readonly button?: 'left' | 'right' | 'middle';
85
+ }): Promise<void>;
86
+ /** Scrolls by a wheel turn where the pointer is. */
87
+ wheel(deltaX: number, deltaY: number): Promise<void>;
88
+ }
89
+ /** Deterministic Electron app management exposed to tests as `electron`. */
90
+ export interface Electron {
91
+ /**
92
+ * The directory the app keeps its data in for this test, empty until the
93
+ * app writes to it. It exists before the app is launched, so a test can
94
+ * put data in it first, or pass it on with `launch({ env })`.
95
+ */
96
+ readonly userDataDir: string;
97
+ /**
98
+ * Launches the app fresh, as `app.open()` does, with arguments and
99
+ * variables of this test's own added to the target's. They stay for the
100
+ * rest of the test: `app.open()`, `app.restart()`, and `app.clearState()`
101
+ * launch with them too. Another `launch()` replaces them; it does not add
102
+ * to them.
103
+ */
104
+ launch(options?: ElectronLaunchOptions): Promise<void>;
105
+ /** The active window, the one `screen`, `expect`, and the agent act on. Throws `INVALID_STATE` when the app has no open window. */
106
+ activeWindow(): ElectronWindow;
107
+ /** Keyboard input to the active window. */
108
+ readonly keyboard: ElectronKeyboard;
109
+ /** Pointer input to the active window. */
110
+ readonly mouse: ElectronMouse;
111
+ /**
112
+ * Runs `fn` in the app's main process and returns what it returns, which
113
+ * must be serializable. `fn` is sent as source text: it cannot close over
114
+ * the test's variables, so pass them as `arg`. Code with the main
115
+ * process's full authority, as trusted as the test itself.
116
+ */
117
+ evaluate<R>(fn: (electron: ElectronMainModule) => R | Promise<R>): Promise<R>;
118
+ /** Runs `fn` in the main process with `arg`, which a function that takes one must be given. */
119
+ evaluate<R, A>(fn: (electron: ElectronMainModule, arg: A) => R | Promise<R>, arg: A): Promise<R>;
120
+ /** The app's open windows, in the order they opened. */
121
+ windows(): readonly ElectronWindow[];
122
+ /**
123
+ * Runs a trigger and waits for the window it opens, then resolves with that
124
+ * window once it is the active one. Rejects with `ACTION_FAILED` when no
125
+ * window opens within `timeout` milliseconds, or else the action timeout.
126
+ */
127
+ waitForWindow(trigger: () => Promise<void>, options?: {
128
+ readonly timeout?: number;
129
+ }): Promise<ElectronWindow>;
130
+ /**
131
+ * The first open window whose title or URL matches, waiting for it to open
132
+ * up to `timeout` milliseconds or else the action timeout: for a window
133
+ * the app opens on its own. It does not become active; call `activate()`.
134
+ */
135
+ window(which: WindowMatcher, options?: {
136
+ readonly timeout?: number;
137
+ }): Promise<ElectronWindow>;
138
+ /**
139
+ * Runs `trigger` and waits for the download it starts to finish, up to
140
+ * `timeout` milliseconds or else the action timeout. The file is copied
141
+ * into the attempt's artifacts: `path` is relative to them.
142
+ */
143
+ waitForDownload(trigger: () => Promise<void>, options?: {
144
+ readonly timeout?: number;
145
+ }): Promise<{
146
+ readonly path: string;
147
+ readonly absolutePath: string;
148
+ readonly suggestedFilename: string;
149
+ }>;
150
+ /**
151
+ * Answers the `alert` and `confirm` dialogs the app opens from now on:
152
+ * `'accept'`, `'dismiss'`, or a function that must call `accept` or
153
+ * `dismiss`. The newest handler wins. Resolves with what removes it. A
154
+ * dialog no handler takes is dismissed and fails the test's next step.
155
+ */
156
+ onDialog(handler: DialogHandler): Promise<() => Promise<void>>;
157
+ /**
158
+ * A locator for a CSS selector in the window `screen` reads, for an element
159
+ * no role, label, text, or test id names. It matches in the window's
160
+ * document and in each open shadow root, one root at a time, and never
161
+ * enters a frame.
162
+ */
163
+ locator(selector: string): Locator;
164
+ }
165
+ /** What a session on an `electron()` target holds beside `screen` and `app`: the `electron` fixture. */
166
+ export interface ElectronFixtures {
167
+ readonly electron: Electron;
168
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The `electron` fixture an `electron()` target contributes, as types only:
3
+ * what the package's public entries declare, apart from the engine's own
4
+ * modules.
5
+ */
6
+ export {};
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Page-side halves of a masked screenshot: a black box painted over every
3
+ * element a selector matches, with the caret hidden and animations stopped,
4
+ * and the cleanup that takes it all away again. Sent as source text: each
5
+ * function is self-contained.
6
+ */
7
+ /** What the masks cover: how many elements, and where each one is. */
8
+ export interface MaskState {
9
+ readonly count: number;
10
+ /** The masked elements' boxes in the viewport, as one comparable string. */
11
+ readonly boxes: string;
12
+ /** Whether the masks were in place, whole, on top, and over every element: false once their document is gone, or the page took one away. */
13
+ readonly placed: boolean;
14
+ }
15
+ /**
16
+ * Paints a black box over every element `selector` matches in the document
17
+ * and in each open shadow root, hides the text caret, and stops animations:
18
+ * a finite one jumps to its end, an endless one to its start, so a field an
19
+ * animation moves stays under the box measured for it.
20
+ */
21
+ export declare function placeMasks(selector: string): MaskState;
22
+ /** Takes the masks away, and says what `selector` matches now: an element that appeared or moved since was not under one. */
23
+ export declare function removeMasks(selector: string): MaskState;
24
+ /** How many device pixels one CSS pixel covers. */
25
+ export declare function pixelRatio(): number;