@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.
- package/LICENSE +202 -0
- package/NOTICE +5 -0
- package/README.md +91 -2
- package/dist/.build.json +1 -0
- package/dist/actionability.d.ts +41 -0
- package/dist/actionability.js +121 -0
- package/dist/actions.d.ts +52 -0
- package/dist/actions.js +418 -0
- package/dist/app-process.d.ts +114 -0
- package/dist/app-process.js +610 -0
- package/dist/budget.d.ts +33 -0
- package/dist/budget.js +64 -0
- package/dist/capture.d.ts +21 -0
- package/dist/capture.js +137 -0
- package/dist/cdp/connection.d.ts +68 -0
- package/dist/cdp/connection.js +232 -0
- package/dist/cdp/input.d.ts +67 -0
- package/dist/cdp/input.js +195 -0
- package/dist/cdp/keys.d.ts +21 -0
- package/dist/cdp/keys.js +114 -0
- package/dist/console-text.d.ts +4 -0
- package/dist/console-text.js +27 -0
- package/dist/devtools.d.ts +36 -0
- package/dist/devtools.js +111 -0
- package/dist/dialogs.d.ts +38 -0
- package/dist/dialogs.js +81 -0
- package/dist/electron.d.ts +9 -0
- package/dist/electron.js +174 -0
- package/dist/engine-entry.d.ts +13 -0
- package/dist/engine-entry.js +9 -0
- package/dist/engine.d.ts +27 -0
- package/dist/engine.js +98 -0
- package/dist/errors.d.ts +17 -0
- package/dist/errors.js +54 -0
- package/dist/evaluate.d.ts +40 -0
- package/dist/evaluate.js +115 -0
- package/dist/executable.d.ts +29 -0
- package/dist/executable.js +249 -0
- package/dist/ffmpeg.d.ts +12 -0
- package/dist/ffmpeg.js +100 -0
- package/dist/fields.d.ts +93 -0
- package/dist/fields.js +254 -0
- package/dist/file-bound.d.ts +31 -0
- package/dist/file-bound.js +104 -0
- package/dist/fixtures.d.ts +168 -0
- package/dist/fixtures.js +6 -0
- package/dist/in-page/masks.d.ts +25 -0
- package/dist/in-page/masks.js +140 -0
- package/dist/in-page/node-ops.d.ts +96 -0
- package/dist/in-page/node-ops.js +406 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +18 -0
- package/dist/launcher.d.ts +45 -0
- package/dist/launcher.js +167 -0
- package/dist/locate.d.ts +46 -0
- package/dist/locate.js +103 -0
- package/dist/main-process.d.ts +25 -0
- package/dist/main-process.js +60 -0
- package/dist/options.d.ts +65 -0
- package/dist/options.js +120 -0
- package/dist/page.d.ts +100 -0
- package/dist/page.js +229 -0
- package/dist/runner-test.d.ts +15 -0
- package/dist/runner-test.js +45 -0
- package/dist/snapshot.d.ts +143 -0
- package/dist/snapshot.js +260 -0
- package/dist/surface.d.ts +158 -0
- package/dist/surface.js +602 -0
- package/dist/tree.d.ts +51 -0
- package/dist/tree.js +406 -0
- package/dist/video.d.ts +42 -0
- package/dist/video.js +253 -0
- package/dist/windows.d.ts +81 -0
- package/dist/windows.js +200 -0
- package/package.json +72 -3
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trusted input over `Input.*`: a keyboard and a mouse for one page, each
|
|
3
|
+
* tracking what is held so modifiers apply to the keys and clicks after
|
|
4
|
+
* them.
|
|
5
|
+
*/
|
|
6
|
+
import { KEY_LAYOUT, MAC_EDITING_COMMANDS } from './keys.js';
|
|
7
|
+
const MODIFIERS = ['Alt', 'Control', 'Meta', 'Shift'];
|
|
8
|
+
const KEYPAD_LOCATION = 3;
|
|
9
|
+
const IS_MAC = process.platform === 'darwin';
|
|
10
|
+
function isModifier(key) {
|
|
11
|
+
return MODIFIERS.includes(key);
|
|
12
|
+
}
|
|
13
|
+
/** The `Input.*` modifiers bit mask. */
|
|
14
|
+
function modifiersMask(modifiers) {
|
|
15
|
+
return (modifiers.has('Alt') ? 1 : 0) | (modifiers.has('Control') ? 2 : 0) | (modifiers.has('Meta') ? 4 : 0) | (modifiers.has('Shift') ? 8 : 0);
|
|
16
|
+
}
|
|
17
|
+
/** The `Input.dispatchMouseEvent` buttons bit mask. */
|
|
18
|
+
function buttonsMask(buttons) {
|
|
19
|
+
return (buttons.has('left') ? 1 : 0) | (buttons.has('right') ? 2 : 0) | (buttons.has('middle') ? 4 : 0);
|
|
20
|
+
}
|
|
21
|
+
/** `ControlOrMeta` is Meta on macOS and Control elsewhere. */
|
|
22
|
+
function platformKey(key) {
|
|
23
|
+
return key === 'ControlOrMeta' ? (IS_MAC ? 'Meta' : 'Control') : key;
|
|
24
|
+
}
|
|
25
|
+
/** Whether the keyboard has a key by this name: a key code (`Enter`, `Space`) or a character of the US layout. */
|
|
26
|
+
export function hasKey(key) {
|
|
27
|
+
return KEY_LAYOUT.has(platformKey(key));
|
|
28
|
+
}
|
|
29
|
+
export class Keyboard {
|
|
30
|
+
target;
|
|
31
|
+
heldModifiers = new Set();
|
|
32
|
+
heldKeys = new Set();
|
|
33
|
+
constructor(target) {
|
|
34
|
+
this.target = target;
|
|
35
|
+
}
|
|
36
|
+
/** The modifiers held now. */
|
|
37
|
+
modifiers() {
|
|
38
|
+
return this.heldModifiers;
|
|
39
|
+
}
|
|
40
|
+
/** Whether a modifier is held now, by any name it is pressed by (`ControlOrMeta` too). */
|
|
41
|
+
holds(modifier) {
|
|
42
|
+
const key = platformKey(modifier);
|
|
43
|
+
return isModifier(key) && this.heldModifiers.has(key);
|
|
44
|
+
}
|
|
45
|
+
/** Forgets what is held: the renderer that held it is gone. */
|
|
46
|
+
reset() {
|
|
47
|
+
this.heldModifiers.clear();
|
|
48
|
+
this.heldKeys.clear();
|
|
49
|
+
}
|
|
50
|
+
/** Presses a key down and leaves it held; a held modifier applies to the keys and mouse events after it. */
|
|
51
|
+
async down(key) {
|
|
52
|
+
const description = this.describe(key);
|
|
53
|
+
const autoRepeat = this.heldKeys.has(description.code);
|
|
54
|
+
this.heldKeys.add(description.code);
|
|
55
|
+
if (isModifier(description.key))
|
|
56
|
+
this.heldModifiers.add(description.key);
|
|
57
|
+
await this.target.session.send('Input.dispatchKeyEvent', {
|
|
58
|
+
type: description.text === '' ? 'rawKeyDown' : 'keyDown',
|
|
59
|
+
modifiers: modifiersMask(this.heldModifiers),
|
|
60
|
+
windowsVirtualKeyCode: description.keyCodeWithoutLocation,
|
|
61
|
+
code: description.code,
|
|
62
|
+
commands: this.editingCommands(description.code),
|
|
63
|
+
key: description.key,
|
|
64
|
+
text: description.text,
|
|
65
|
+
unmodifiedText: description.text,
|
|
66
|
+
autoRepeat,
|
|
67
|
+
location: description.location,
|
|
68
|
+
isKeypad: description.location === KEYPAD_LOCATION,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/** Releases a key `down` pressed. */
|
|
72
|
+
async up(key) {
|
|
73
|
+
const description = this.describe(key);
|
|
74
|
+
if (isModifier(description.key))
|
|
75
|
+
this.heldModifiers.delete(description.key);
|
|
76
|
+
this.heldKeys.delete(description.code);
|
|
77
|
+
await this.target.session.send('Input.dispatchKeyEvent', {
|
|
78
|
+
type: 'keyUp',
|
|
79
|
+
modifiers: modifiersMask(this.heldModifiers),
|
|
80
|
+
key: description.key,
|
|
81
|
+
windowsVirtualKeyCode: description.keyCodeWithoutLocation,
|
|
82
|
+
code: description.code,
|
|
83
|
+
location: description.location,
|
|
84
|
+
isKeypad: description.location === KEYPAD_LOCATION,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/** Presses a key down and releases it, under whatever modifiers are held. */
|
|
88
|
+
async press(key) {
|
|
89
|
+
await this.down(key);
|
|
90
|
+
await this.up(key);
|
|
91
|
+
}
|
|
92
|
+
/** Types one character: its key when the layout has one, else the character inserted as text. */
|
|
93
|
+
async type(character) {
|
|
94
|
+
if (KEY_LAYOUT.has(character))
|
|
95
|
+
await this.press(character);
|
|
96
|
+
else
|
|
97
|
+
await this.insertText(character);
|
|
98
|
+
}
|
|
99
|
+
/** Inserts text as an input method's commit would: input events and no key events. */
|
|
100
|
+
async insertText(text) {
|
|
101
|
+
await this.target.session.send('Input.insertText', { text });
|
|
102
|
+
}
|
|
103
|
+
describe(name) {
|
|
104
|
+
const key = platformKey(name);
|
|
105
|
+
let description = KEY_LAYOUT.get(key);
|
|
106
|
+
if (description === undefined)
|
|
107
|
+
throw new Error(`the keyboard has no key ${JSON.stringify(key)}`);
|
|
108
|
+
if (this.heldModifiers.has('Shift') && description.shifted !== undefined)
|
|
109
|
+
description = description.shifted;
|
|
110
|
+
// A key pressed with Control, Alt, or Meta held types nothing.
|
|
111
|
+
const onlyShift = this.heldModifiers.size === 1 && this.heldModifiers.has('Shift');
|
|
112
|
+
return this.heldModifiers.size > 0 && !onlyShift ? { ...description, text: '' } : description;
|
|
113
|
+
}
|
|
114
|
+
/** The editing commands macOS runs for this key with the held modifiers; text insertion is left to the event's `text`. */
|
|
115
|
+
editingCommands(code) {
|
|
116
|
+
if (!IS_MAC)
|
|
117
|
+
return [];
|
|
118
|
+
const chord = [...['Shift', 'Control', 'Alt', 'Meta'].filter((modifier) => this.heldModifiers.has(modifier)), code].join('+');
|
|
119
|
+
return (MAC_EDITING_COMMANDS[chord] ?? []).filter((command) => !command.startsWith('insert'));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The page's mouse, in viewport CSS pixels. A press that moves over a
|
|
124
|
+
* draggable element starts an HTML drag, which Chromium carries through from
|
|
125
|
+
* these events alone: the moves after it are its `dragover`, and the release
|
|
126
|
+
* its `drop`.
|
|
127
|
+
*/
|
|
128
|
+
export class Mouse {
|
|
129
|
+
target;
|
|
130
|
+
keyboard;
|
|
131
|
+
x = 0;
|
|
132
|
+
y = 0;
|
|
133
|
+
lastButton = 'none';
|
|
134
|
+
buttons = new Set();
|
|
135
|
+
constructor(target, keyboard) {
|
|
136
|
+
this.target = target;
|
|
137
|
+
this.keyboard = keyboard;
|
|
138
|
+
}
|
|
139
|
+
/** Forgets the buttons held: the renderer that held them is gone. */
|
|
140
|
+
reset() {
|
|
141
|
+
this.buttons.clear();
|
|
142
|
+
this.lastButton = 'none';
|
|
143
|
+
}
|
|
144
|
+
async move(x, y) {
|
|
145
|
+
this.x = x;
|
|
146
|
+
this.y = y;
|
|
147
|
+
await this.target.session.send('Input.dispatchMouseEvent', {
|
|
148
|
+
type: 'mouseMoved',
|
|
149
|
+
button: this.lastButton,
|
|
150
|
+
buttons: buttonsMask(this.buttons),
|
|
151
|
+
x,
|
|
152
|
+
y,
|
|
153
|
+
modifiers: modifiersMask(this.keyboard.modifiers()),
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/** Presses a button where the pointer is. */
|
|
157
|
+
async down(button = 'left', clickCount = 1) {
|
|
158
|
+
this.lastButton = button;
|
|
159
|
+
this.buttons.add(button);
|
|
160
|
+
await this.target.session.send('Input.dispatchMouseEvent', {
|
|
161
|
+
type: 'mousePressed',
|
|
162
|
+
button,
|
|
163
|
+
buttons: buttonsMask(this.buttons),
|
|
164
|
+
x: this.x,
|
|
165
|
+
y: this.y,
|
|
166
|
+
modifiers: modifiersMask(this.keyboard.modifiers()),
|
|
167
|
+
clickCount,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
/** Releases a button where the pointer is. */
|
|
171
|
+
async up(button = 'left', clickCount = 1) {
|
|
172
|
+
this.lastButton = 'none';
|
|
173
|
+
this.buttons.delete(button);
|
|
174
|
+
await this.target.session.send('Input.dispatchMouseEvent', {
|
|
175
|
+
type: 'mouseReleased',
|
|
176
|
+
button,
|
|
177
|
+
buttons: buttonsMask(this.buttons),
|
|
178
|
+
x: this.x,
|
|
179
|
+
y: this.y,
|
|
180
|
+
modifiers: modifiersMask(this.keyboard.modifiers()),
|
|
181
|
+
clickCount,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/** Moves to a point and clicks `clickCount` times, the events sent back to back as one gesture. */
|
|
185
|
+
async click(x, y, button = 'left', clickCount = 1) {
|
|
186
|
+
const events = [this.move(x, y)];
|
|
187
|
+
for (let count = 1; count <= clickCount; count += 1)
|
|
188
|
+
events.push(this.down(button, count), this.up(button, count));
|
|
189
|
+
await Promise.all(events);
|
|
190
|
+
}
|
|
191
|
+
/** A wheel event where the pointer is. */
|
|
192
|
+
async wheel(deltaX, deltaY) {
|
|
193
|
+
await this.target.session.send('Input.dispatchMouseEvent', { type: 'mouseWheel', x: this.x, y: this.y, modifiers: modifiersMask(this.keyboard.modifiers()), deltaX, deltaY });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keys of a US keyboard as Chromium's `Input.dispatchKeyEvent` takes
|
|
3
|
+
* them, and the editing commands macOS runs only when a key event names
|
|
4
|
+
* them. Characters outside this layout have no key: they are inserted as
|
|
5
|
+
* text.
|
|
6
|
+
*/
|
|
7
|
+
/** One key as a key event describes it. */
|
|
8
|
+
export interface KeyDescription {
|
|
9
|
+
readonly key: string;
|
|
10
|
+
readonly keyCode: number;
|
|
11
|
+
readonly keyCodeWithoutLocation: number;
|
|
12
|
+
readonly code: string;
|
|
13
|
+
readonly text: string;
|
|
14
|
+
readonly location: number;
|
|
15
|
+
/** The same key with Shift held, when Shift changes what it types. */
|
|
16
|
+
readonly shifted?: KeyDescription;
|
|
17
|
+
}
|
|
18
|
+
/** Editing commands macOS Chromium only runs when the key event names them; `insert*` commands are left to `text`. */
|
|
19
|
+
export declare const MAC_EDITING_COMMANDS: Readonly<Record<string, readonly string[]>>;
|
|
20
|
+
/** Every key the keyboard has, by each name it is pressed by. */
|
|
21
|
+
export declare const KEY_LAYOUT: ReadonlyMap<string, KeyDescription>;
|
package/dist/cdp/keys.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The keys of a US keyboard as Chromium's `Input.dispatchKeyEvent` takes
|
|
3
|
+
* them, and the editing commands macOS runs only when a key event names
|
|
4
|
+
* them. Characters outside this layout have no key: they are inserted as
|
|
5
|
+
* text.
|
|
6
|
+
*/
|
|
7
|
+
const US_LAYOUT = {
|
|
8
|
+
Escape: [27, 'Escape'], F1: [112, 'F1'], F2: [113, 'F2'], F3: [114, 'F3'], F4: [115, 'F4'], F5: [116, 'F5'],
|
|
9
|
+
F6: [117, 'F6'], F7: [118, 'F7'], F8: [119, 'F8'], F9: [120, 'F9'], F10: [121, 'F10'], F11: [122, 'F11'], F12: [123, 'F12'],
|
|
10
|
+
Backquote: [192, '`', '~'], Digit1: [49, '1', '!'], Digit2: [50, '2', '@'], Digit3: [51, '3', '#'], Digit4: [52, '4', '$'],
|
|
11
|
+
Digit5: [53, '5', '%'], Digit6: [54, '6', '^'], Digit7: [55, '7', '&'], Digit8: [56, '8', '*'], Digit9: [57, '9', '('],
|
|
12
|
+
Digit0: [48, '0', ')'], Minus: [189, '-', '_'], Equal: [187, '=', '+'], Backslash: [220, '\\', '|'], Backspace: [8, 'Backspace'],
|
|
13
|
+
Tab: [9, 'Tab'], KeyQ: [81, 'q', 'Q'], KeyW: [87, 'w', 'W'], KeyE: [69, 'e', 'E'], KeyR: [82, 'r', 'R'], KeyT: [84, 't', 'T'],
|
|
14
|
+
KeyY: [89, 'y', 'Y'], KeyU: [85, 'u', 'U'], KeyI: [73, 'i', 'I'], KeyO: [79, 'o', 'O'], KeyP: [80, 'p', 'P'],
|
|
15
|
+
BracketLeft: [219, '[', '{'], BracketRight: [221, ']', '}'], CapsLock: [20, 'CapsLock'],
|
|
16
|
+
KeyA: [65, 'a', 'A'], KeyS: [83, 's', 'S'], KeyD: [68, 'd', 'D'], KeyF: [70, 'f', 'F'], KeyG: [71, 'g', 'G'], KeyH: [72, 'h', 'H'],
|
|
17
|
+
KeyJ: [74, 'j', 'J'], KeyK: [75, 'k', 'K'], KeyL: [76, 'l', 'L'], Semicolon: [186, ';', ':'], Quote: [222, '\'', '"'],
|
|
18
|
+
Enter: [13, 'Enter', undefined, undefined, '\r'],
|
|
19
|
+
ShiftLeft: [160, 'Shift', undefined, 1, undefined, 16], KeyZ: [90, 'z', 'Z'], KeyX: [88, 'x', 'X'], KeyC: [67, 'c', 'C'],
|
|
20
|
+
KeyV: [86, 'v', 'V'], KeyB: [66, 'b', 'B'], KeyN: [78, 'n', 'N'], KeyM: [77, 'm', 'M'], Comma: [188, ',', '<'],
|
|
21
|
+
Period: [190, '.', '>'], Slash: [191, '/', '?'], ShiftRight: [161, 'Shift', undefined, 2, undefined, 16],
|
|
22
|
+
ControlLeft: [162, 'Control', undefined, 1, undefined, 17], MetaLeft: [91, 'Meta', undefined, 1],
|
|
23
|
+
AltLeft: [164, 'Alt', undefined, 1, undefined, 18], Space: [32, ' '], AltRight: [165, 'Alt', undefined, 2, undefined, 18],
|
|
24
|
+
AltGraph: [225, 'AltGraph'], MetaRight: [92, 'Meta', undefined, 2], ContextMenu: [93, 'ContextMenu'],
|
|
25
|
+
ControlRight: [163, 'Control', undefined, 2, undefined, 17],
|
|
26
|
+
PrintScreen: [44, 'PrintScreen'], ScrollLock: [145, 'ScrollLock'], Pause: [19, 'Pause'], PageUp: [33, 'PageUp'],
|
|
27
|
+
PageDown: [34, 'PageDown'], Insert: [45, 'Insert'], Delete: [46, 'Delete'], Home: [36, 'Home'], End: [35, 'End'],
|
|
28
|
+
ArrowLeft: [37, 'ArrowLeft'], ArrowUp: [38, 'ArrowUp'], ArrowRight: [39, 'ArrowRight'], ArrowDown: [40, 'ArrowDown'],
|
|
29
|
+
AudioVolumeMute: [173, 'AudioVolumeMute'], AudioVolumeDown: [174, 'AudioVolumeDown'], AudioVolumeUp: [175, 'AudioVolumeUp'],
|
|
30
|
+
MediaTrackNext: [176, 'MediaTrackNext'], MediaTrackPrevious: [177, 'MediaTrackPrevious'], MediaPlayPause: [179, 'MediaPlayPause'],
|
|
31
|
+
NumLock: [144, 'NumLock'], NumpadDivide: [111, '/', undefined, 3], NumpadMultiply: [106, '*', undefined, 3],
|
|
32
|
+
NumpadSubtract: [109, '-', undefined, 3], Numpad7: [36, 'Home', '7', 3, undefined, undefined, 103],
|
|
33
|
+
Numpad8: [38, 'ArrowUp', '8', 3, undefined, undefined, 104], Numpad9: [33, 'PageUp', '9', 3, undefined, undefined, 105],
|
|
34
|
+
Numpad4: [37, 'ArrowLeft', '4', 3, undefined, undefined, 100], Numpad5: [12, 'Clear', '5', 3, undefined, undefined, 101],
|
|
35
|
+
Numpad6: [39, 'ArrowRight', '6', 3, undefined, undefined, 102], NumpadAdd: [107, '+', undefined, 3],
|
|
36
|
+
Numpad1: [35, 'End', '1', 3, undefined, undefined, 97], Numpad2: [40, 'ArrowDown', '2', 3, undefined, undefined, 98],
|
|
37
|
+
Numpad3: [34, 'PageDown', '3', 3, undefined, undefined, 99], Numpad0: [45, 'Insert', '0', 3, undefined, undefined, 96],
|
|
38
|
+
NumpadDecimal: [46, 'Delete', '.', 3, undefined, undefined, 110], NumpadEnter: [13, 'Enter', undefined, 3, '\r'],
|
|
39
|
+
};
|
|
40
|
+
const KEY_ALIASES = {
|
|
41
|
+
ShiftLeft: ['Shift'], ControlLeft: ['Control'], AltLeft: ['Alt'], MetaLeft: ['Meta'], Enter: ['\n', '\r'],
|
|
42
|
+
};
|
|
43
|
+
/** Editing commands macOS Chromium only runs when the key event names them; `insert*` commands are left to `text`. */
|
|
44
|
+
export const MAC_EDITING_COMMANDS = {
|
|
45
|
+
Backspace: ['deleteBackward'], Enter: ['insertNewline'], NumpadEnter: ['insertNewline'], Escape: ['cancelOperation'],
|
|
46
|
+
ArrowUp: ['moveUp'], ArrowDown: ['moveDown'], ArrowLeft: ['moveLeft'], ArrowRight: ['moveRight'], F5: ['complete'],
|
|
47
|
+
Delete: ['deleteForward'], Home: ['scrollToBeginningOfDocument'], End: ['scrollToEndOfDocument'],
|
|
48
|
+
PageUp: ['scrollPageUp'], PageDown: ['scrollPageDown'], 'Shift+Backspace': ['deleteBackward'],
|
|
49
|
+
'Shift+Enter': ['insertNewline'], 'Shift+NumpadEnter': ['insertNewline'], 'Shift+Escape': ['cancelOperation'],
|
|
50
|
+
'Shift+ArrowUp': ['moveUpAndModifySelection'], 'Shift+ArrowDown': ['moveDownAndModifySelection'],
|
|
51
|
+
'Shift+ArrowLeft': ['moveLeftAndModifySelection'], 'Shift+ArrowRight': ['moveRightAndModifySelection'],
|
|
52
|
+
'Shift+F5': ['complete'], 'Shift+Delete': ['deleteForward'], 'Shift+Home': ['moveToBeginningOfDocumentAndModifySelection'],
|
|
53
|
+
'Shift+End': ['moveToEndOfDocumentAndModifySelection'], 'Shift+PageUp': ['pageUpAndModifySelection'],
|
|
54
|
+
'Shift+PageDown': ['pageDownAndModifySelection'], 'Shift+Numpad5': ['delete'], 'Control+Tab': ['selectNextKeyView'],
|
|
55
|
+
'Control+Enter': ['insertLineBreak'], 'Control+NumpadEnter': ['insertLineBreak'],
|
|
56
|
+
'Control+Quote': ['insertSingleQuoteIgnoringSubstitution'], 'Control+KeyA': ['moveToBeginningOfParagraph'],
|
|
57
|
+
'Control+KeyB': ['moveBackward'], 'Control+KeyD': ['deleteForward'], 'Control+KeyE': ['moveToEndOfParagraph'],
|
|
58
|
+
'Control+KeyF': ['moveForward'], 'Control+KeyH': ['deleteBackward'], 'Control+KeyK': ['deleteToEndOfParagraph'],
|
|
59
|
+
'Control+KeyL': ['centerSelectionInVisibleArea'], 'Control+KeyN': ['moveDown'],
|
|
60
|
+
'Control+KeyO': ['insertNewlineIgnoringFieldEditor', 'moveBackward'], 'Control+KeyP': ['moveUp'],
|
|
61
|
+
'Control+KeyT': ['transpose'], 'Control+KeyV': ['pageDown'], 'Control+KeyY': ['yank'],
|
|
62
|
+
'Control+Backspace': ['deleteBackwardByDecomposingPreviousCharacter'], 'Control+ArrowUp': ['scrollPageUp'],
|
|
63
|
+
'Control+ArrowDown': ['scrollPageDown'], 'Control+ArrowLeft': ['moveToLeftEndOfLine'],
|
|
64
|
+
'Control+ArrowRight': ['moveToRightEndOfLine'], 'Shift+Control+Enter': ['insertLineBreak'],
|
|
65
|
+
'Shift+Control+NumpadEnter': ['insertLineBreak'], 'Shift+Control+Tab': ['selectPreviousKeyView'],
|
|
66
|
+
'Shift+Control+Quote': ['insertDoubleQuoteIgnoringSubstitution'],
|
|
67
|
+
'Shift+Control+KeyA': ['moveToBeginningOfParagraphAndModifySelection'], 'Shift+Control+KeyB': ['moveBackwardAndModifySelection'],
|
|
68
|
+
'Shift+Control+KeyE': ['moveToEndOfParagraphAndModifySelection'], 'Shift+Control+KeyF': ['moveForwardAndModifySelection'],
|
|
69
|
+
'Shift+Control+KeyN': ['moveDownAndModifySelection'], 'Shift+Control+KeyP': ['moveUpAndModifySelection'],
|
|
70
|
+
'Shift+Control+KeyV': ['pageDownAndModifySelection'],
|
|
71
|
+
'Shift+Control+Backspace': ['deleteBackwardByDecomposingPreviousCharacter'], 'Shift+Control+ArrowUp': ['scrollPageUp'],
|
|
72
|
+
'Shift+Control+ArrowDown': ['scrollPageDown'], 'Shift+Control+ArrowLeft': ['moveToLeftEndOfLineAndModifySelection'],
|
|
73
|
+
'Shift+Control+ArrowRight': ['moveToRightEndOfLineAndModifySelection'], 'Alt+Backspace': ['deleteWordBackward'],
|
|
74
|
+
'Alt+Enter': ['insertNewlineIgnoringFieldEditor'], 'Alt+NumpadEnter': ['insertNewlineIgnoringFieldEditor'],
|
|
75
|
+
'Alt+Escape': ['complete'], 'Alt+ArrowUp': ['moveBackward', 'moveToBeginningOfParagraph'],
|
|
76
|
+
'Alt+ArrowDown': ['moveForward', 'moveToEndOfParagraph'], 'Alt+ArrowLeft': ['moveWordLeft'],
|
|
77
|
+
'Alt+ArrowRight': ['moveWordRight'], 'Alt+Delete': ['deleteWordForward'], 'Alt+PageUp': ['pageUp'],
|
|
78
|
+
'Alt+PageDown': ['pageDown'], 'Shift+Alt+Backspace': ['deleteWordBackward'],
|
|
79
|
+
'Shift+Alt+Enter': ['insertNewlineIgnoringFieldEditor'], 'Shift+Alt+NumpadEnter': ['insertNewlineIgnoringFieldEditor'],
|
|
80
|
+
'Shift+Alt+Escape': ['complete'], 'Shift+Alt+ArrowUp': ['moveParagraphBackwardAndModifySelection'],
|
|
81
|
+
'Shift+Alt+ArrowDown': ['moveParagraphForwardAndModifySelection'], 'Shift+Alt+ArrowLeft': ['moveWordLeftAndModifySelection'],
|
|
82
|
+
'Shift+Alt+ArrowRight': ['moveWordRightAndModifySelection'], 'Shift+Alt+Delete': ['deleteWordForward'],
|
|
83
|
+
'Shift+Alt+PageUp': ['pageUp'], 'Shift+Alt+PageDown': ['pageDown'], 'Control+Alt+KeyB': ['moveWordBackward'],
|
|
84
|
+
'Control+Alt+KeyF': ['moveWordForward'], 'Control+Alt+Backspace': ['deleteWordBackward'],
|
|
85
|
+
'Shift+Control+Alt+KeyB': ['moveWordBackwardAndModifySelection'], 'Shift+Control+Alt+KeyF': ['moveWordForwardAndModifySelection'],
|
|
86
|
+
'Shift+Control+Alt+Backspace': ['deleteWordBackward'], 'Meta+NumpadSubtract': ['cancel'],
|
|
87
|
+
'Meta+Backspace': ['deleteToBeginningOfLine'], 'Meta+ArrowUp': ['moveToBeginningOfDocument'],
|
|
88
|
+
'Meta+ArrowDown': ['moveToEndOfDocument'], 'Meta+ArrowLeft': ['moveToLeftEndOfLine'], 'Meta+ArrowRight': ['moveToRightEndOfLine'],
|
|
89
|
+
'Shift+Meta+NumpadSubtract': ['cancel'], 'Shift+Meta+Backspace': ['deleteToBeginningOfLine'],
|
|
90
|
+
'Shift+Meta+ArrowUp': ['moveToBeginningOfDocumentAndModifySelection'], 'Shift+Meta+ArrowDown': ['moveToEndOfDocumentAndModifySelection'],
|
|
91
|
+
'Shift+Meta+ArrowLeft': ['moveToLeftEndOfLineAndModifySelection'], 'Shift+Meta+ArrowRight': ['moveToRightEndOfLineAndModifySelection'],
|
|
92
|
+
'Meta+KeyA': ['selectAll'], 'Meta+KeyC': ['copy'], 'Meta+KeyX': ['cut'], 'Meta+KeyV': ['paste'], 'Meta+KeyZ': ['undo'],
|
|
93
|
+
'Shift+Meta+KeyZ': ['redo'],
|
|
94
|
+
};
|
|
95
|
+
/** Expands the layout into every name a key is pressed by: its code, its key, and its shifted key. */
|
|
96
|
+
function buildLayout() {
|
|
97
|
+
const layout = new Map();
|
|
98
|
+
for (const [code, [keyCode, key, shiftKey, location = 0, text, withoutLocation, shiftKeyCode]] of Object.entries(US_LAYOUT)) {
|
|
99
|
+
const plain = { key, keyCode, keyCodeWithoutLocation: withoutLocation ?? keyCode, code, text: key.length === 1 ? key : (text ?? ''), location };
|
|
100
|
+
const shifted = shiftKey === undefined ? undefined : { ...plain, key: shiftKey, text: shiftKey, ...(shiftKeyCode === undefined ? {} : { keyCode: shiftKeyCode, keyCodeWithoutLocation: shiftKeyCode }) };
|
|
101
|
+
layout.set(code, { ...plain, ...(shifted === undefined ? {} : { shifted }) });
|
|
102
|
+
for (const alias of KEY_ALIASES[code] ?? [])
|
|
103
|
+
layout.set(alias, plain);
|
|
104
|
+
if (location !== 0)
|
|
105
|
+
continue;
|
|
106
|
+
if (key.length === 1)
|
|
107
|
+
layout.set(key, plain);
|
|
108
|
+
if (shifted !== undefined)
|
|
109
|
+
layout.set(shifted.key, shifted);
|
|
110
|
+
}
|
|
111
|
+
return layout;
|
|
112
|
+
}
|
|
113
|
+
/** Every key the keyboard has, by each name it is pressed by. */
|
|
114
|
+
export const KEY_LAYOUT = buildLayout();
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The text of a console call, from the arguments the DevTools protocol reports it with. */
|
|
2
|
+
import type { Protocol } from 'devtools-protocol';
|
|
3
|
+
/** A console call's arguments as one line, the way a terminal would print them. */
|
|
4
|
+
export declare function consoleText(args: readonly Protocol.Runtime.RemoteObject[]): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** The text of a console call, from the arguments the DevTools protocol reports it with. */
|
|
2
|
+
/** A console call's arguments as one line, the way a terminal would print them. */
|
|
3
|
+
export function consoleText(args) {
|
|
4
|
+
return args.map(argumentText).join(' ');
|
|
5
|
+
}
|
|
6
|
+
function argumentText(arg) {
|
|
7
|
+
if (arg.unserializableValue !== undefined)
|
|
8
|
+
return arg.unserializableValue;
|
|
9
|
+
if (arg.type === 'string')
|
|
10
|
+
return String(arg.value);
|
|
11
|
+
if (arg.type === 'undefined')
|
|
12
|
+
return 'undefined';
|
|
13
|
+
if (arg.type !== 'object' && arg.type !== 'function')
|
|
14
|
+
return String(arg.value);
|
|
15
|
+
if (arg.subtype === 'null')
|
|
16
|
+
return 'null';
|
|
17
|
+
// An error prints as its stack does; a plain object or array as the preview the protocol sends with it.
|
|
18
|
+
if (arg.subtype === 'error' || arg.preview === undefined)
|
|
19
|
+
return arg.description ?? arg.type;
|
|
20
|
+
return previewText(arg.preview);
|
|
21
|
+
}
|
|
22
|
+
function previewText(preview) {
|
|
23
|
+
const more = preview.overflow ? ', …' : '';
|
|
24
|
+
if (preview.subtype === 'array')
|
|
25
|
+
return `[${preview.properties.map((property) => property.value ?? property.type).join(', ')}${more}]`;
|
|
26
|
+
return `{${preview.properties.map((property) => `${property.name}: ${property.value ?? property.type}`).join(', ')}${more}}`;
|
|
27
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The DevTools protocol calls on a window's nodes: the ones that run
|
|
3
|
+
* `in-page/` functions in the engine's isolated world, and the DOM snapshot.
|
|
4
|
+
*/
|
|
5
|
+
import { type NodeOps } from './in-page/node-ops.ts';
|
|
6
|
+
import { type PageTarget } from './page.ts';
|
|
7
|
+
import { DomSnapshot } from './snapshot.ts';
|
|
8
|
+
/** One DOM snapshot of a window's main document, indexed, with the document's title. */
|
|
9
|
+
export interface DocumentSnapshot {
|
|
10
|
+
readonly dom: DomSnapshot;
|
|
11
|
+
readonly title: string;
|
|
12
|
+
}
|
|
13
|
+
export declare class DevTools {
|
|
14
|
+
/** Runs `work` in the window's isolated world with an object group of its own, released when the call ends. */
|
|
15
|
+
private inWorld;
|
|
16
|
+
/**
|
|
17
|
+
* Runs one of `NodeOps` on a node in the isolated world and returns its
|
|
18
|
+
* JSON result. The node is resolved fresh from its backend id, so a node
|
|
19
|
+
* the document dropped fails as stale.
|
|
20
|
+
*/
|
|
21
|
+
callOn<K extends keyof NodeOps>(page: PageTarget, backendNodeId: number, name: K, ...args: Parameters<NodeOps[K]>): Promise<ReturnType<NodeOps[K]>>;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the element with keyboard focus takes typed text. Page script
|
|
24
|
+
* stops at the host of a closed shadow root; the DevTools protocol reaches
|
|
25
|
+
* into one, so the walk goes on inside until it finds the focused element.
|
|
26
|
+
*/
|
|
27
|
+
focusedTakesText(page: PageTarget): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* The backend ids of the elements a CSS selector matches in the window's
|
|
30
|
+
* document and in each open shadow root (`queryAll`), run in the isolated
|
|
31
|
+
* world.
|
|
32
|
+
*/
|
|
33
|
+
querySelectorAll(page: PageTarget, selector: string): Promise<ReadonlySet<number>>;
|
|
34
|
+
/** One DOM snapshot of the window's main document, the only place one is captured; undefined while it has none. */
|
|
35
|
+
snapshot(page: PageTarget): Promise<DocumentSnapshot | undefined>;
|
|
36
|
+
}
|
package/dist/devtools.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The DevTools protocol calls on a window's nodes: the ones that run
|
|
3
|
+
* `in-page/` functions in the engine's isolated world, and the DOM snapshot.
|
|
4
|
+
*/
|
|
5
|
+
import { TestError } from '@e2e-dev/core/engine';
|
|
6
|
+
import { stale } from './errors.js';
|
|
7
|
+
import { activeUnder, nodeOp, queryAll } from './in-page/node-ops.js';
|
|
8
|
+
import { thrown, WORLD_NAME } from './page.js';
|
|
9
|
+
import { DomSnapshot, SNAPSHOT_STYLES } from './snapshot.js';
|
|
10
|
+
const NODE_OP = nodeOp.toString();
|
|
11
|
+
const ACTIVE_UNDER = activeUnder.toString();
|
|
12
|
+
let objectGroups = 0;
|
|
13
|
+
/** A DevTools object group of one call's own: releasing it frees that call's handles and never another's still in use. */
|
|
14
|
+
function newObjectGroup() {
|
|
15
|
+
objectGroups += 1;
|
|
16
|
+
return `${WORLD_NAME}${objectGroups}`;
|
|
17
|
+
}
|
|
18
|
+
export class DevTools {
|
|
19
|
+
/** Runs `work` in the window's isolated world with an object group of its own, released when the call ends. */
|
|
20
|
+
async inWorld(page, work) {
|
|
21
|
+
const { session } = page;
|
|
22
|
+
const contextId = await page.world();
|
|
23
|
+
const group = newObjectGroup();
|
|
24
|
+
try {
|
|
25
|
+
return await work(session, contextId, group);
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
await session.send('Runtime.releaseObjectGroup', { objectGroup: group }).catch(() => undefined);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Runs one of `NodeOps` on a node in the isolated world and returns its
|
|
33
|
+
* JSON result. The node is resolved fresh from its backend id, so a node
|
|
34
|
+
* the document dropped fails as stale.
|
|
35
|
+
*/
|
|
36
|
+
callOn(page, backendNodeId, name, ...args) {
|
|
37
|
+
return this.inWorld(page, async (session, executionContextId, objectGroup) => {
|
|
38
|
+
const { object } = await session.send('DOM.resolveNode', { backendNodeId, executionContextId, objectGroup });
|
|
39
|
+
if (object.objectId === undefined)
|
|
40
|
+
throw stale(`node ${backendNodeId} is no longer in the window`);
|
|
41
|
+
const { result, exceptionDetails } = await session.send('Runtime.callFunctionOn', {
|
|
42
|
+
objectId: object.objectId,
|
|
43
|
+
functionDeclaration: NODE_OP,
|
|
44
|
+
arguments: [{ objectId: object.objectId }, { value: name }, { value: args }],
|
|
45
|
+
returnByValue: true,
|
|
46
|
+
awaitPromise: true,
|
|
47
|
+
});
|
|
48
|
+
if (exceptionDetails !== undefined)
|
|
49
|
+
throw new Error(thrown(exceptionDetails));
|
|
50
|
+
return result.value;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Whether the element with keyboard focus takes typed text. Page script
|
|
55
|
+
* stops at the host of a closed shadow root; the DevTools protocol reaches
|
|
56
|
+
* into one, so the walk goes on inside until it finds the focused element.
|
|
57
|
+
*/
|
|
58
|
+
focusedTakesText(page) {
|
|
59
|
+
return this.inWorld(page, async (session, executionContextId, objectGroup) => {
|
|
60
|
+
const focusedUnder = async (objectId) => (await session.send('Runtime.callFunctionOn', { objectId, functionDeclaration: ACTIVE_UNDER, arguments: [{ objectId }], objectGroup })).result.objectId;
|
|
61
|
+
const { result: document } = await session.send('Runtime.evaluate', { expression: 'document', contextId: executionContextId, objectGroup });
|
|
62
|
+
const first = document.objectId === undefined ? undefined : await focusedUnder(document.objectId);
|
|
63
|
+
if (first === undefined)
|
|
64
|
+
return false;
|
|
65
|
+
let active = first;
|
|
66
|
+
for (;;) {
|
|
67
|
+
const { node } = await session.send('DOM.describeNode', { objectId: active, depth: 1, pierce: true });
|
|
68
|
+
const closed = node.shadowRoots?.find((root) => root.shadowRootType === 'closed');
|
|
69
|
+
if (closed === undefined)
|
|
70
|
+
break;
|
|
71
|
+
const { object: root } = await session.send('DOM.resolveNode', { backendNodeId: closed.backendNodeId, executionContextId, objectGroup });
|
|
72
|
+
// Nothing focused inside: the host itself has focus.
|
|
73
|
+
const inner = root.objectId === undefined ? undefined : await focusedUnder(root.objectId);
|
|
74
|
+
if (inner === undefined)
|
|
75
|
+
break;
|
|
76
|
+
active = inner;
|
|
77
|
+
}
|
|
78
|
+
const { result } = await session.send('Runtime.callFunctionOn', {
|
|
79
|
+
objectId: active,
|
|
80
|
+
functionDeclaration: NODE_OP,
|
|
81
|
+
arguments: [{ objectId: active }, { value: 'takesText' }, { value: [] }],
|
|
82
|
+
returnByValue: true,
|
|
83
|
+
});
|
|
84
|
+
return result.value === true;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The backend ids of the elements a CSS selector matches in the window's
|
|
89
|
+
* document and in each open shadow root (`queryAll`), run in the isolated
|
|
90
|
+
* world.
|
|
91
|
+
*/
|
|
92
|
+
querySelectorAll(page, selector) {
|
|
93
|
+
return this.inWorld(page, async (session, contextId, objectGroup) => {
|
|
94
|
+
const { result, exceptionDetails } = await session.send('Runtime.evaluate', { expression: `(${queryAll.toString()})(${JSON.stringify(selector)})`, contextId, objectGroup });
|
|
95
|
+
if (exceptionDetails !== undefined)
|
|
96
|
+
throw new TestError('INVALID_LOCATOR', `${JSON.stringify(selector)} is not a CSS selector: ${thrown(exceptionDetails).split('\n')[0]}`);
|
|
97
|
+
if (result.objectId === undefined)
|
|
98
|
+
return new Set();
|
|
99
|
+
const { result: entries } = await session.send('Runtime.getProperties', { objectId: result.objectId, ownProperties: true });
|
|
100
|
+
// One round trip per match, sent together: a broad selector on a long list is read on every poll of an expect.
|
|
101
|
+
const described = await Promise.all(entries.flatMap((entry) => (/^\d+$/.test(entry.name) && entry.value?.objectId !== undefined ? [session.send('DOM.describeNode', { objectId: entry.value.objectId })] : [])));
|
|
102
|
+
return new Set(described.map(({ node }) => node.backendNodeId));
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/** One DOM snapshot of the window's main document, the only place one is captured; undefined while it has none. */
|
|
106
|
+
async snapshot(page) {
|
|
107
|
+
const { documents, strings } = await page.session.send('DOMSnapshot.captureSnapshot', { computedStyles: [...SNAPSHOT_STYLES] });
|
|
108
|
+
const document = documents[0];
|
|
109
|
+
return document === undefined ? undefined : { dom: new DomSnapshot(document, strings), title: strings[document.title] ?? '' };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `alert` and `confirm` dialogs of one attempt: each goes to the handler
|
|
3
|
+
* `electron.onDialog` registered last. One nothing answers is dismissed, so
|
|
4
|
+
* the app goes on, and is held as the failure of the test's next step.
|
|
5
|
+
*/
|
|
6
|
+
/** An `alert` or `confirm` as a test's handler sees it. Electron has no `prompt`. */
|
|
7
|
+
export interface Dialog {
|
|
8
|
+
readonly type: 'alert' | 'confirm';
|
|
9
|
+
/** The dialog's text. */
|
|
10
|
+
readonly message: string;
|
|
11
|
+
/** Accepts the dialog once, as clicking OK does. */
|
|
12
|
+
accept(): Promise<void>;
|
|
13
|
+
/** Dismisses the dialog once. */
|
|
14
|
+
dismiss(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export type DialogHandler = 'accept' | 'dismiss' | ((dialog: Dialog) => void | Promise<void>);
|
|
17
|
+
/** A dialog the app opened, and how the engine answers it. */
|
|
18
|
+
export interface OpenDialog {
|
|
19
|
+
readonly type: 'alert' | 'confirm';
|
|
20
|
+
readonly message: string;
|
|
21
|
+
answer(accept: boolean): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
export declare class DialogRouter {
|
|
24
|
+
private registrations;
|
|
25
|
+
private pending;
|
|
26
|
+
private readonly running;
|
|
27
|
+
/** Registers a handler, the newest winning, and returns what removes it. */
|
|
28
|
+
add(handler: DialogHandler): () => void;
|
|
29
|
+
/** Forgets the attempt's handlers and whatever it left unreported. */
|
|
30
|
+
reset(): void;
|
|
31
|
+
/** The failure a dialog left for the next step, once. */
|
|
32
|
+
take(): Error | undefined;
|
|
33
|
+
/** Resolves once the handlers running now have returned. */
|
|
34
|
+
settled(): Promise<void>;
|
|
35
|
+
/** Answers one dialog through the newest handler. */
|
|
36
|
+
dispatch(dialog: OpenDialog): void;
|
|
37
|
+
private route;
|
|
38
|
+
}
|
package/dist/dialogs.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `alert` and `confirm` dialogs of one attempt: each goes to the handler
|
|
3
|
+
* `electron.onDialog` registered last. One nothing answers is dismissed, so
|
|
4
|
+
* the app goes on, and is held as the failure of the test's next step.
|
|
5
|
+
*/
|
|
6
|
+
import { ConfigurationError, EngineError, InfrastructureError, TestError } from '@e2e-dev/core/engine';
|
|
7
|
+
/** An error a handler threw that already says what failed: a failed `expect`, a refusal. */
|
|
8
|
+
function classified(cause) {
|
|
9
|
+
return cause instanceof EngineError || cause instanceof TestError || cause instanceof ConfigurationError || cause instanceof InfrastructureError;
|
|
10
|
+
}
|
|
11
|
+
export class DialogRouter {
|
|
12
|
+
registrations = [];
|
|
13
|
+
pending;
|
|
14
|
+
running = new Set();
|
|
15
|
+
/** Registers a handler, the newest winning, and returns what removes it. */
|
|
16
|
+
add(handler) {
|
|
17
|
+
const registration = { handler };
|
|
18
|
+
this.registrations.push(registration);
|
|
19
|
+
return () => {
|
|
20
|
+
this.registrations = this.registrations.filter((each) => each !== registration);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** Forgets the attempt's handlers and whatever it left unreported. */
|
|
24
|
+
reset() {
|
|
25
|
+
this.registrations = [];
|
|
26
|
+
this.pending = undefined;
|
|
27
|
+
}
|
|
28
|
+
/** The failure a dialog left for the next step, once. */
|
|
29
|
+
take() {
|
|
30
|
+
const { pending } = this;
|
|
31
|
+
this.pending = undefined;
|
|
32
|
+
return pending;
|
|
33
|
+
}
|
|
34
|
+
/** Resolves once the handlers running now have returned. */
|
|
35
|
+
async settled() {
|
|
36
|
+
await Promise.all(this.running);
|
|
37
|
+
}
|
|
38
|
+
/** Answers one dialog through the newest handler. */
|
|
39
|
+
dispatch(dialog) {
|
|
40
|
+
const work = this.route(dialog).catch(() => undefined);
|
|
41
|
+
this.running.add(work);
|
|
42
|
+
void work.then(() => this.running.delete(work));
|
|
43
|
+
}
|
|
44
|
+
async route(dialog) {
|
|
45
|
+
const handler = this.registrations.at(-1)?.handler;
|
|
46
|
+
const { type, message } = dialog;
|
|
47
|
+
// The first failure is the one to report: the app's later dialogs follow from it.
|
|
48
|
+
const fail = (error) => {
|
|
49
|
+
this.pending ??= error;
|
|
50
|
+
};
|
|
51
|
+
if (handler === undefined) {
|
|
52
|
+
fail(new EngineError('INVALID_STATE', `unhandled ${type} dialog: ${message}; answer it with electron.onDialog('accept'), 'dismiss', or a handler`, { retryable: false }));
|
|
53
|
+
await dialog.answer(false).catch(() => undefined);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (typeof handler === 'string') {
|
|
57
|
+
await dialog.answer(handler === 'accept').catch(() => undefined);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
let decided = false;
|
|
61
|
+
let answered = false;
|
|
62
|
+
const answer = async (accept) => {
|
|
63
|
+
decided = true;
|
|
64
|
+
await dialog.answer(accept);
|
|
65
|
+
answered = true;
|
|
66
|
+
};
|
|
67
|
+
try {
|
|
68
|
+
await handler({ type, message, accept: () => answer(true), dismiss: () => answer(false) });
|
|
69
|
+
if (decided)
|
|
70
|
+
return;
|
|
71
|
+
// Left open, it would block the page and surface later as an unrelated timeout.
|
|
72
|
+
await dialog.answer(false).catch(() => undefined);
|
|
73
|
+
fail(new EngineError('INVALID_STATE', `dialog handler returned without calling accept or dismiss for ${type} dialog: ${message}`, { retryable: false }));
|
|
74
|
+
}
|
|
75
|
+
catch (cause) {
|
|
76
|
+
fail(classified(cause) ? cause : new EngineError('ENGINE_FAILURE', `dialog handler failed: ${cause instanceof Error ? cause.message : String(cause)}`, { retryable: false, cause }));
|
|
77
|
+
if (!answered)
|
|
78
|
+
await dialog.answer(false).catch(() => undefined);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `electron` fixture: what a test asks of the Electron app itself rather
|
|
3
|
+
* than of a control in a window. The harness records each call as an
|
|
4
|
+
* `electron.<method>` step bounded by the action timeout.
|
|
5
|
+
*/
|
|
6
|
+
import { type EngineFixtureContext } from '@e2e-dev/core/engine';
|
|
7
|
+
import type { Electron } from './fixtures.ts';
|
|
8
|
+
import type { ElectronSurface } from './surface.ts';
|
|
9
|
+
export declare function createElectronFixture(surface: ElectronSurface, context: EngineFixtureContext): Electron;
|