@e2e-dev/electron 0.1.1 → 0.1.2-nightly-20261205030542

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/dist/.build.json CHANGED
@@ -1 +1 @@
1
- {"version":"0.1.1"}
1
+ {"version":"0.1.2-nightly-20261205030542"}
package/dist/actions.d.ts CHANGED
@@ -13,8 +13,6 @@ export interface ActionContext {
13
13
  readonly devtools: DevTools;
14
14
  readonly windows: Windows;
15
15
  readonly projectRoot: string;
16
- /** The attempt's directory for files the engine writes for the app to read, made on first use and removed with the attempt. */
17
- uploads(): string;
18
16
  }
19
17
  type ActionOf<K extends LocatorAction['kind']> = Extract<LocatorAction, {
20
18
  readonly kind: K;
package/dist/actions.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * action finds the point to act at and makes the gesture a point action
5
5
  * makes there.
6
6
  */
7
- import { existsSync, mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';
7
+ import { statSync } from 'node:fs';
8
8
  import path from 'node:path';
9
9
  import { EngineError, parseKey, sleep, TestError, pollCondition, withTimeout, } from '@e2e-dev/core/engine';
10
10
  import { actionablePoint, contentBox, waitReady, whole } from './actionability.js';
@@ -17,6 +17,7 @@ const LONG_PRESS_MS = 800;
17
17
  const RELEASE_MARGIN_MS = 100;
18
18
  /** How long a paced drag (`swipeTo`) takes by default. */
19
19
  const SWIPE_TO_MS = 300;
20
+ /** Why a directory is refused to a file input that takes files only. */
20
21
  /** The time between two moves of a paced drag: one frame at 60 Hz. */
21
22
  const FRAME_MS = 16;
22
23
  /** The share of a box one wheel scroll covers, by momentum, as the web engine scrolls. */
@@ -148,8 +149,13 @@ async function scrollIntoView(step) {
148
149
  });
149
150
  }
150
151
  async function fill(step, value) {
151
- const { devtools, window, backendNodeId, budget } = step;
152
- await waitReady(step, 'checkEditable');
152
+ const { devtools, window, budget } = step;
153
+ // The text of a label fills the control the label names, as check() acts on it: the control is the one that must be
154
+ // editable and that no modal dialog blocks, since it is the one written to. A label inside a modal can name a control
155
+ // behind it.
156
+ const control = { ...step, backendNodeId: await devtools.followLabel(window.page, step.backendNodeId) };
157
+ const { backendNodeId } = control;
158
+ await waitReady(control, 'checkEditable');
153
159
  // A date, time, color, or range input takes no typed text: its value is set, as a browser's own picker does.
154
160
  const set = await budget.send(() => devtools.callOn(window.page, backendNodeId, 'setValue', value));
155
161
  if (set !== null) {
@@ -158,27 +164,86 @@ async function fill(step, value) {
158
164
  return;
159
165
  }
160
166
  // The app's focus handler can hand focus on; text goes only to the node that still holds it.
161
- if (!(await budget.send(() => devtools.callOn(window.page, backendNodeId, 'selectContents'))))
167
+ const selected = await budget.send(() => devtools.callOn(window.page, backendNodeId, 'selectContents'));
168
+ if (selected === 'moved')
162
169
  throw lostFocus();
163
170
  // Text replaces the selection as typing would, with input events and no key events, as fill promises; an empty value
164
- // is a Delete key, so an editor that keeps its own model sees beforeinput.
165
- if (value === '')
166
- await budget.send(() => window.page.keyboard.press('Delete'));
167
- else
171
+ // is a Delete key, so an editor that keeps its own model sees beforeinput. An empty element in an editing host leaves
172
+ // only a caret, and Delete there would take the text after it: there is nothing to clear.
173
+ if (value !== '')
168
174
  await budget.send(() => window.page.keyboard.insertText(value));
175
+ else if (selected === 'selected')
176
+ await budget.send(() => window.page.keyboard.press('Delete'));
169
177
  }
170
- async function setChecked(step, want) {
178
+ /**
179
+ * The checked state of a node, as the page reads it, else as Chromium's tree
180
+ * does: a custom element can give itself a role and a state through its
181
+ * ElementInternals, which no attribute shows. Null when it has none.
182
+ */
183
+ async function readChecked(step) {
171
184
  const { devtools, window, backendNodeId } = step;
185
+ const own = await devtools.callOn(window.page, backendNodeId, 'readChecked');
186
+ if (own !== null)
187
+ return own;
188
+ const { nodes } = await window.page.session.send('Accessibility.getPartialAXTree', { backendNodeId, fetchRelatives: false });
189
+ const checked = nodes[0]?.properties?.find((property) => property.name === 'checked')?.value.value;
190
+ // A mixed checkbox is not checked: check() clicks it.
191
+ return checked === undefined ? null : checked === true || checked === 'true';
192
+ }
193
+ /**
194
+ * The checked state a native checkbox or radio had when it left the page,
195
+ * or null when the node is no such input or can no longer be reached.
196
+ */
197
+ async function leftChecked(control) {
198
+ try {
199
+ return await control.devtools.callOn(control.window.page, control.backendNodeId, 'readCheckedAsLeft');
200
+ }
201
+ catch (cause) {
202
+ if (isGone(cause))
203
+ return null;
204
+ throw cause;
205
+ }
206
+ }
207
+ /**
208
+ * The checked state of the control that the label the step clicked names
209
+ * now, when the label is still in the page and names a control other than
210
+ * `gone`, the one that left. Null when the step's node is the control itself,
211
+ * the label left too, or it names no control with a checked state.
212
+ */
213
+ async function checkedNamedNow(step, gone) {
214
+ if (gone.backendNodeId === step.backendNodeId)
215
+ return null;
216
+ try {
217
+ const backendNodeId = await step.devtools.followLabel(step.window.page, step.backendNodeId);
218
+ if (backendNodeId === step.backendNodeId || backendNodeId === gone.backendNodeId)
219
+ return null;
220
+ return await readChecked({ ...step, backendNodeId });
221
+ }
222
+ catch (cause) {
223
+ if (isGone(cause))
224
+ return null;
225
+ throw cause;
226
+ }
227
+ }
228
+ async function setChecked(step, want) {
229
+ const { devtools, window } = step;
172
230
  const kind = want ? 'check' : 'uncheck';
173
- const now = await devtools.callOn(window.page, backendNodeId, 'readChecked');
231
+ // The text of a label acts on the control the label names, as on the web: the control is the one whose state is read
232
+ // and that must be enabled, and the label is only what is clicked. A label that replaces itself on the click leaves
233
+ // the control to read.
234
+ const control = { ...step, backendNodeId: await devtools.followLabel(window.page, step.backendNodeId) };
235
+ const now = await readChecked(control);
174
236
  if (now === null)
175
237
  throw notActionable(`the element has no checked state to ${kind}: it is no checkbox, radio, or switch`);
176
238
  if (now === want)
177
239
  return;
178
240
  // A click on a checked native radio leaves it checked: only another radio of its group clears it. A custom radio
179
241
  // clears if its app says so, which the read after the click finds out.
180
- if (!want && (await devtools.callOn(window.page, backendNodeId, 'isNativeRadio')))
242
+ if (!want && (await devtools.callOn(window.page, control.backendNodeId, 'isNativeRadio')))
181
243
  throw notActionable('uncheck cannot clear a radio button; select another radio in its group');
244
+ // An enabled label still toggles a control marked aria-disabled: the control is waited on to be enabled, as the node clicked is.
245
+ if (control.backendNodeId !== step.backendNodeId)
246
+ await waitReady(control, 'checkControlEnabled');
182
247
  await click(step.budget, window, await actionablePoint(step, true), {});
183
248
  // A custom widget can set its state in a later task: the state is polled until the deadline, as the checks before the click are.
184
249
  let read = false;
@@ -189,13 +254,29 @@ async function setChecked(step, want) {
189
254
  evaluate: async () => {
190
255
  let state;
191
256
  try {
192
- state = await devtools.callOn(window.page, backendNodeId, 'readChecked');
257
+ state = await readChecked(control);
193
258
  }
194
259
  catch (cause) {
195
- // The app answered the click by replacing the control (a "Saved" in its place): the click did its work. One
196
- // that goes away after it was read unchanged did not take it.
197
- if (!read && isGone(cause))
198
- return true;
260
+ // The control left the page before its state was read. A label that stays and names a new control now, as an
261
+ // app that renders the box again does, is followed again and that control read, as Playwright reads the
262
+ // label's control after the click. Otherwise leaving says nothing either way: a todo list removes a row once
263
+ // its box is checked, and an app can answer the click with a "Saved" in the box's place, but it can also
264
+ // cancel the click and render an unchecked copy along with its label. A native box is read as it left the
265
+ // page; a custom control, whose state no detached node keeps, is taken to have done its work. One that goes
266
+ // away after it was read unchanged did not take the click.
267
+ if (!isGone(cause))
268
+ throw cause;
269
+ const renamed = await checkedNamedNow(step, control);
270
+ if (renamed !== null) {
271
+ if (renamed === want)
272
+ return true;
273
+ throw notActionable(`clicking the element did not ${kind} it: the control its label names now is ${want ? 'unchecked' : 'checked'}`);
274
+ }
275
+ if (!read) {
276
+ if ((await leftChecked(control)) !== !want)
277
+ return true;
278
+ throw notActionable(`clicking the element did not ${kind} it: ${control.backendNodeId === step.backendNodeId ? 'it' : 'the control its label names'} left the page ${want ? 'unchecked' : 'checked'}`);
279
+ }
199
280
  throw cause;
200
281
  }
201
282
  read = true;
@@ -222,47 +303,86 @@ async function selectOption(step, action) {
222
303
  }
223
304
  async function setInputFiles(step, action) {
224
305
  const files = action.paths.map((file) => path.resolve(step.context.projectRoot, file));
225
- // The DevTools call takes a path that names nothing and attaches nothing, reporting success.
226
- const missing = files.find((file) => !existsSync(file));
227
- if (missing !== undefined)
228
- throw new TestError('INVALID_ARGUMENT', `setInputFiles: no file at ${missing}`);
306
+ // The DevTools call takes a path that names nothing and attaches nothing, reporting success. It attaches a directory as
307
+ // a file named after it, except to an input with webkitdirectory, which takes the files under it: one directory, alone,
308
+ // as a folder upload is.
309
+ let directory = false;
310
+ for (const file of files) {
311
+ const stat = statOf(file);
312
+ if (stat === undefined)
313
+ throw new TestError('INVALID_ARGUMENT', `setInputFiles: no file at ${file}`);
314
+ if (stat.isDirectory() && files.length === 1)
315
+ directory = true;
316
+ else if (stat.isDirectory())
317
+ throw new TestError('INVALID_ARGUMENT', `setInputFiles: ${file} is a directory; pass the files themselves, or one directory alone`);
318
+ else if (!stat.isFile())
319
+ throw new TestError('INVALID_ARGUMENT', `setInputFiles: ${file} is not a regular file; pass the files themselves`);
320
+ }
321
+ await attachFiles(step, files.length, (backendNodeId) => step.window.page.session.send('DOM.setFileInputFiles', { files, backendNodeId }), directory);
322
+ }
323
+ /**
324
+ * What is at a path to upload, or undefined when nothing is. A path the file
325
+ * system refuses to read (too long, a link loop, no permission) is the test's
326
+ * argument to fix, as a missing file is.
327
+ */
328
+ function statOf(file) {
329
+ try {
330
+ return statSync(file, { throwIfNoEntry: false });
331
+ }
332
+ catch (cause) {
333
+ const code = cause.code;
334
+ throw new TestError('INVALID_ARGUMENT', `setInputFiles: cannot read ${file}${code === undefined ? '' : ` (${code})`}`, { cause });
335
+ }
336
+ }
337
+ /**
338
+ * In-memory files, made in the page with the name and MIME type the test
339
+ * gave: the DevTools protocol sets a file input from paths only, and the
340
+ * type of a file read from disk is the one its name implies.
341
+ */
342
+ async function setInputFilePayloads(step, action) {
343
+ const files = action.files.map((file) => ({ name: file.name, mimeType: file.mimeType, base64: Buffer.from(file.buffer).toString('base64') }));
344
+ await attachFiles(step, files.length, (backendNodeId, inDocument) => step.devtools.callOn(step.window.page, backendNodeId, 'setFiles', files, inDocument));
345
+ }
346
+ /**
347
+ * Gives `count` files, through `attach`, to the file input the node is, or
348
+ * to the one the file chooser it opens belongs to. `[]` clears the input:
349
+ * the DevTools call leaves it as it was for an empty list. `attach` is told
350
+ * whether the input must still be in the document: the one the test named
351
+ * must, a chooser's need not.
352
+ */
353
+ async function attachFiles(step, count, attach, directory = false) {
229
354
  if (!(await step.devtools.callOn(step.window.page, step.backendNodeId, 'isFileInput')))
230
- return await chooseFiles(step, files);
355
+ return await chooseFiles(step, count, attach, directory);
231
356
  await waitReady(step, 'checkFileInput');
232
- const takes = await step.devtools.callOn(step.window.page, step.backendNodeId, 'takesFiles', files.length);
357
+ const takes = await step.devtools.callOn(step.window.page, step.backendNodeId, 'takesFiles', count);
233
358
  if (!takes.ok)
234
359
  throw new TestError('INVALID_ARGUMENT', `setInputFiles: ${takes.reason}`);
235
- // The DevTools call leaves the input as it was for an empty list; `[]` clears it.
236
- if (files.length === 0) {
237
- await step.budget.send(() => step.devtools.callOn(step.window.page, step.backendNodeId, 'clearFiles'));
238
- return;
239
- }
240
- await step.budget.send(() => step.window.page.session.send('DOM.setFileInputFiles', { files, backendNodeId: step.backendNodeId }));
360
+ await checkFolderUpload(step, step.backendNodeId, count, directory);
361
+ if (count === 0)
362
+ await step.budget.send(() => step.devtools.callOn(step.window.page, step.backendNodeId, 'clearFiles', true));
363
+ else
364
+ await step.budget.send(() => attach(step.backendNodeId, true));
241
365
  }
242
366
  /**
243
- * In-memory files. The DevTools protocol sets a file input from paths only,
244
- * so each file is written to the attempt's upload directory, which lasts as
245
- * long as the app may read it: a page reads a chosen file when it sends it,
246
- * not when it is chosen.
367
+ * Refuses a directory to a file input without webkitdirectory, and files to
368
+ * one with it, as Playwright does: such an input lets the user pick a folder
369
+ * only. Clearing the input passes either way.
247
370
  */
248
- async function setInputFilePayloads(step, action) {
249
- const directory = mkdtempSync(path.join(step.context.uploads(), 'files-'));
250
- const paths = action.files.map((file, index) => {
251
- // A directory per file: two files may share a name, and a name is the page's to read, never a path to follow.
252
- const own = path.join(directory, String(index));
253
- mkdirSync(own);
254
- const written = path.join(own, path.basename(file.name) || 'file');
255
- writeFileSync(written, file.buffer);
256
- return written;
257
- });
258
- await setInputFiles(step, { kind: 'setInputFiles', paths });
371
+ async function checkFolderUpload(step, backendNodeId, count, directory) {
372
+ if (count === 0)
373
+ return;
374
+ const folders = await step.devtools.callOn(step.window.page, backendNodeId, 'takesDirectory');
375
+ if (directory && !folders)
376
+ throw new TestError('INVALID_ARGUMENT', 'setInputFiles: the file input takes no directory: it has no webkitdirectory attribute; pass the files themselves');
377
+ if (!directory && folders)
378
+ throw new TestError('INVALID_ARGUMENT', 'setInputFiles: the file input takes a directory: it has a webkitdirectory attribute; pass the path of one directory');
259
379
  }
260
380
  /**
261
381
  * Files for a control that is no file input itself: a button whose click
262
382
  * opens a file chooser. The chooser is held back from the screen, the control
263
383
  * clicked, and the files given to the input the chooser belongs to.
264
384
  */
265
- async function chooseFiles(step, files) {
385
+ async function chooseFiles(step, count, attach, directory) {
266
386
  const { session } = step.window.page;
267
387
  let opened = () => undefined;
268
388
  const chooser = new Promise((resolve) => {
@@ -275,13 +395,13 @@ async function chooseFiles(step, files) {
275
395
  const { backendNodeId, mode } = await withTimeout(chooser, Math.max(1, step.deadline.remaining()), () => notActionable('the element is not a file input, and clicking it opened no file chooser'));
276
396
  if (backendNodeId === undefined)
277
397
  throw notActionable('the file chooser the element opened belongs to no input in the window');
278
- if (files.length > 1 && mode !== 'selectMultiple')
279
- throw new TestError('INVALID_ARGUMENT', `setInputFiles: the file chooser takes one file, not ${files.length}`);
280
- // The DevTools call leaves the input as it was for an empty list, as on the input itself.
281
- if (files.length === 0)
282
- await step.budget.send(() => step.devtools.callOn(step.window.page, backendNodeId, 'clearFiles'));
398
+ if (count > 1 && mode !== 'selectMultiple')
399
+ throw new TestError('INVALID_ARGUMENT', `setInputFiles: the file chooser takes one file, not ${count}`);
400
+ await checkFolderUpload(step, backendNodeId, count, directory);
401
+ if (count === 0)
402
+ await step.budget.send(() => step.devtools.callOn(step.window.page, backendNodeId, 'clearFiles', false));
283
403
  else
284
- await step.budget.send(() => session.send('DOM.setFileInputFiles', { files: [...files], backendNodeId }));
404
+ await step.budget.send(() => attach(backendNodeId, false));
285
405
  }
286
406
  finally {
287
407
  stopListening();
@@ -328,14 +448,14 @@ async function hover(budget, window, at) {
328
448
  async function longPress(budget, window, at, durationMs = LONG_PRESS_MS) {
329
449
  const { mouse } = window.page;
330
450
  await budget.send(() => mouse.move(at.x, at.y));
331
- await budget.send(() => mouse.down());
451
+ await budget.send(() => mouse.down('left', 1, { local: true }));
332
452
  // The release lands before the operation's bound fires, so a press its budget cuts short is up when the step fails.
333
453
  const held = Math.min(durationMs, Math.max(0, budget.deadline.remaining() - RELEASE_MARGIN_MS));
334
454
  try {
335
455
  await sleep(held, budget.operation.signal);
336
456
  }
337
457
  finally {
338
- await mouse.up();
458
+ await mouse.up('left', 1, { local: true });
339
459
  }
340
460
  budget.check();
341
461
  if (held < durationMs)
@@ -350,7 +470,7 @@ async function longPress(budget, window, at, durationMs = LONG_PRESS_MS) {
350
470
  async function drag(budget, window, from, target, durationMs) {
351
471
  const { mouse } = window.page;
352
472
  await budget.send(() => mouse.move(from.x, from.y));
353
- await budget.send(() => mouse.down());
473
+ await budget.send(() => mouse.down('left', 1, { local: true }));
354
474
  try {
355
475
  const to = await target();
356
476
  const steps = durationMs === undefined ? 2 : Math.max(2, Math.round(durationMs / FRAME_MS));
@@ -364,7 +484,7 @@ async function drag(budget, window, from, target, durationMs) {
364
484
  await budget.send(() => mouse.move(to.x, to.y));
365
485
  }
366
486
  finally {
367
- await mouse.up();
487
+ await mouse.up('left', 1, { local: true });
368
488
  }
369
489
  }
370
490
  /** A wheel scroll with the pointer at a point, its distance a share of `box` by momentum, then a frame for the app to render it. */
@@ -386,21 +506,27 @@ async function swipe(budget, window, at, box, action) {
386
506
  export async function withModifiers(budget, window, modifiers, input) {
387
507
  const { keyboard } = window.page;
388
508
  const held = [];
509
+ const pinned = [];
389
510
  try {
390
511
  for (const modifier of modifiers) {
391
- // One the test already holds (`electron.keyboard.down('Shift')`) stays the test's to release.
392
- if (keyboard.holds(modifier))
512
+ // One the test already holds (`electron.keyboard.down('Shift')`) stays the test's to release, and is pinned here in case another window closes.
513
+ if (keyboard.holds(modifier)) {
514
+ keyboard.pinModifier(modifier);
515
+ pinned.push(modifier);
393
516
  continue;
517
+ }
394
518
  await budget.send(() => {
395
519
  held.push(modifier);
396
- return keyboard.down(modifier);
520
+ return keyboard.down(modifier, { local: true });
397
521
  });
398
522
  }
399
523
  await budget.send(input);
400
524
  }
401
525
  finally {
526
+ for (const modifier of pinned)
527
+ keyboard.unpinModifier(modifier);
402
528
  for (const modifier of held.toReversed())
403
- await keyboard.up(modifier);
529
+ await keyboard.up(modifier, { local: true });
404
530
  }
405
531
  }
406
532
  /**
@@ -8,6 +8,7 @@ import { existsSync, readdirSync } from 'node:fs';
8
8
  import path from 'node:path';
9
9
  import { Deadline, EngineError, pollCondition, raceAbort, TestError } from '@e2e-dev/core/engine';
10
10
  import { answerWithin, Budget } from './budget.js';
11
+ import { HeldInput } from './cdp/input.js';
11
12
  import { consoleText } from './console-text.js';
12
13
  import { closedWindow, invalidState, unsupported } from './errors.js';
13
14
  import { appDirectory } from './file-bound.js';
@@ -218,7 +219,7 @@ export class AppProcess {
218
219
  // Node keeps a finished process alive for its inspector's client: let go, or the app never exits.
219
220
  process.onWaitingForInspector(() => void connected.then((client) => client?.close()));
220
221
  void process.exited.then(() => connected.then((client) => client?.close()));
221
- return { process, main, withoutMain, pages: new Map() };
222
+ return { process, main, withoutMain, pages: new Map(), held: new HeldInput() };
222
223
  }
223
224
  /**
224
225
  * Follows one launched app: its page targets attached and registered as
@@ -260,7 +261,7 @@ export class AppProcess {
260
261
  // A target that went away while it was being attached was never a window.
261
262
  if (!attaching.delete(info.targetId))
262
263
  return;
263
- const page = new PageTarget(info.targetId, app.process.browser.session(sessionId), info.url, info.openerId === undefined ? undefined : app.pages.get(info.openerId));
264
+ const page = new PageTarget(info.targetId, app.process.browser.session(sessionId), info.url, info.openerId === undefined ? undefined : app.pages.get(info.openerId), app.held);
264
265
  app.pages.set(info.targetId, page);
265
266
  // A window that has loaded nothing has no renderer and never answers: it becomes a window once it does.
266
267
  await this.follow(page, report, app.process.browser);
@@ -663,15 +664,19 @@ export function launchEnv(runEnv, layers, platform = process.platform) {
663
664
  };
664
665
  for (const [key, value] of Object.entries(runEnv)) {
665
666
  const name = key.toUpperCase();
666
- if (value !== undefined && (INHERITED_ENV.has(name) || name.startsWith('LC_')))
667
+ if (value !== undefined && validEnvName(key) && (INHERITED_ENV.has(name) || name.startsWith('LC_')))
667
668
  set(key, value);
668
669
  }
669
670
  for (const layer of layers)
670
671
  for (const [key, value] of Object.entries(layer))
671
- if (!REFUSED_ENV.has(key.toUpperCase()))
672
+ if (validEnvName(key) && !REFUSED_ENV.has(key.toUpperCase()))
672
673
  set(key, value);
673
674
  return env;
674
675
  }
676
+ /** Whether a string is a variable name `spawn` will not split into another variable. */
677
+ function validEnvName(key) {
678
+ return key !== '' && !key.includes('=');
679
+ }
675
680
  /** The variables of the run's environment an app is started with, by their upper-case names. */
676
681
  const INHERITED_ENV = new Set([
677
682
  'PATH', 'HOME', 'USER', 'LOGNAME', 'SHELL', 'LANG', 'LANGUAGE', 'TZ', 'TMPDIR', 'TMP', 'TEMP', '__CF_USER_TEXT_ENCODING',
package/dist/budget.d.ts CHANGED
@@ -15,6 +15,8 @@ export declare class Budget {
15
15
  */
16
16
  readonly waits: Deadline;
17
17
  private sent;
18
+ /** Set when the timeout fired. The timer and the deadline read different clocks, so the timer can fire a millisecond before the deadline says it expired. */
19
+ private ended;
18
20
  constructor(operation: OperationContext, label: string);
19
21
  /** Throws once the operation ended: its caller stopped waiting, and nothing more may reach the app. */
20
22
  check(): void;
@@ -25,6 +27,7 @@ export declare class Budget {
25
27
  send<T>(input: () => Promise<T>): Promise<T>;
26
28
  /** Runs `work` within the budget and the operation's signal, its failures translated into engine errors. */
27
29
  run<T>(work: () => Promise<T>): Promise<T>;
30
+ private end;
28
31
  private timedOut;
29
32
  }
30
33
  /** Runs `work` on a budget of the operation's own. */
package/dist/budget.js CHANGED
@@ -18,6 +18,8 @@ export class Budget {
18
18
  */
19
19
  waits;
20
20
  sent = false;
21
+ /** Set when the timeout fired. The timer and the deadline read different clocks, so the timer can fire a millisecond before the deadline says it expired. */
22
+ ended = false;
21
23
  constructor(operation, label) {
22
24
  this.operation = operation;
23
25
  this.label = label;
@@ -28,7 +30,7 @@ export class Budget {
28
30
  check() {
29
31
  if (this.operation.signal.aborted)
30
32
  throw new EngineError('CANCELLED', `${this.label} was cancelled`, { retryable: false });
31
- if (this.deadline.expired())
33
+ if (this.ended || this.deadline.expired())
32
34
  throw this.timedOut();
33
35
  }
34
36
  /**
@@ -43,12 +45,16 @@ export class Budget {
43
45
  /** Runs `work` within the budget and the operation's signal, its failures translated into engine errors. */
44
46
  async run(work) {
45
47
  try {
46
- return await raceAbort(() => withTimeout(work(), Math.max(1, this.deadline.remaining()), () => this.timedOut()), this.operation.signal, this.label);
48
+ return await raceAbort(() => withTimeout(work(), Math.max(1, this.deadline.remaining()), () => this.end()), this.operation.signal, this.label);
47
49
  }
48
50
  catch (cause) {
49
51
  throw translate(cause, this.label, this.sent);
50
52
  }
51
53
  }
54
+ end() {
55
+ this.ended = true;
56
+ return this.timedOut();
57
+ }
52
58
  timedOut() {
53
59
  return new EngineError('OPERATION_TIMEOUT', `${this.label} timed out after ${this.operation.timeoutMs}ms`, { retryable: false });
54
60
  }
package/dist/capture.d.ts CHANGED
@@ -1,21 +1,31 @@
1
1
  /**
2
- * Pixels: screenshots with every password field and nested document painted
3
- * over, withheld when the window holds one no mask reaches.
2
+ * Pixels: screenshots of the viewport or the whole page with every password
3
+ * field and nested document painted over, withheld when the window holds one
4
+ * no mask reaches.
4
5
  */
5
- import { type EngineSnapshot } from '@e2e-dev/core/engine';
6
+ import { type EngineScreenshotOptions, type EngineSnapshot } from '@e2e-dev/core/engine';
6
7
  import type { DevTools } from './devtools.ts';
7
8
  import { type RawRead } from './locate.ts';
8
9
  import type { AppWindow } from './windows.ts';
9
- /** Adds the pixels to an observation of a read window, or leaves them out when they are withheld. */
10
- export declare function withPixels(devtools: DevTools, raw: RawRead, snapshot: EngineSnapshot): Promise<EngineSnapshot>;
11
10
  /**
12
- * `app.screenshot(label)`: the window with its masks painted over, written
13
- * under the attempt's artifacts as `screenshots/<n>-<label>.png`. Refused
14
- * with `POLICY_DENIED` when the capture is withheld, when `refused` says why
15
- * the window is not one to capture, or when the window loaded another
16
- * document while the capture waited its turn: the pixels are of the document
17
- * `refused` approved, or none are kept.
11
+ * What a capture covers: the window's viewport when undefined, else the whole
12
+ * page, cut to the options' clip when there is one.
18
13
  */
19
- export declare function screenshotFile(devtools: DevTools, window: AppWindow, artifactsDir: string, name: string, refused: () => string | undefined): Promise<string>;
14
+ type Region = EngineScreenshotOptions | undefined;
15
+ /** Adds the pixels of the viewport, or with `fullPage` of the whole page, to an observation of a read window, or leaves them out when they are withheld. */
16
+ export declare function withPixels(devtools: DevTools, raw: RawRead, snapshot: EngineSnapshot, { fullPage }?: {
17
+ readonly fullPage?: boolean;
18
+ }): Promise<EngineSnapshot>;
19
+ /**
20
+ * `app.screenshot(label)`: the window's viewport, or the whole page the
21
+ * region asks for, with its masks painted over, written under the attempt's
22
+ * artifacts as `screenshots/<n>-<label>.png`. Refused with `POLICY_DENIED`
23
+ * when the capture is withheld, when `refused` says why the window is not
24
+ * one to capture, or when the window loaded another document while the
25
+ * capture waited its turn: the pixels are of the document `refused`
26
+ * approved, or none are kept.
27
+ */
28
+ export declare function screenshotFile(devtools: DevTools, window: AppWindow, artifactsDir: string, name: string, refused: () => string | undefined, region?: Region): Promise<string>;
20
29
  /** A screenshot's file name: its number in the attempt and a label that cannot turn into a path (letters, digits, dashes). */
21
30
  export declare function screenshotName(counter: number, label: string | undefined): string;
31
+ export {};