@e2e-dev/electron 0.0.0 → 0.0.1-nightly-20261130030410

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -59,8 +59,10 @@ test('signs in', async ({ app, screen }) => {
59
59
  - **Windows.** The agent sees them as tabs. The `electron` fixture has
60
60
  `launch` (per-test arguments and environment), `userDataDir`, `evaluate`
61
61
  (main process), `windows`, `activeWindow`, `waitForWindow`, `window`,
62
- `waitForDownload`, `onDialog`, `locator` (CSS), `keyboard`, and `mouse`. A
63
- window has `evaluate` (its page) and `reload`.
62
+ `waitForDownload`, `onDialog`, `locator` (CSS), `keyboard`, `mouse`, and
63
+ `waitForURL`. A window has `evaluate` (its page) and `reload`.
64
+ `expect(electron)` asserts the active window's URL and title, and an
65
+ element's class.
64
66
  - **Video.** The shown window's screencast, encoded to one `.webm` by ffmpeg,
65
67
  which the engine downloads on the first recording when the machine has none.
66
68
  - **Secrets.** Password fields report no value, and screenshots paint them
package/dist/.build.json CHANGED
@@ -1 +1 @@
1
- {"version":"0.0.0"}
1
+ {"version":"0.0.1-nightly-20261130030410"}
@@ -100,6 +100,13 @@ export declare class AppProcess {
100
100
  downloads(): Promise<readonly AppDownload[]>;
101
101
  /** The OS window title of a page's `BrowserWindow`, read in the main process; undefined for a view, or when the app does not answer. */
102
102
  windowTitle(page: PageTarget): Promise<string | undefined>;
103
+ /**
104
+ * The OS window title of a page's `BrowserWindow`, as `windowTitle` reads
105
+ * it, but waited for as long as the caller waits: '' only when the app
106
+ * answered with none (a view, or an app with no main-process inspector),
107
+ * never because it answered late.
108
+ */
109
+ answeredWindowTitle(page: PageTarget): Promise<string>;
103
110
  /** Closes one window, past any `beforeunload` guard, and resolves once it is gone. */
104
111
  closeWindow(page: PageTarget): Promise<void>;
105
112
  }
@@ -371,12 +371,24 @@ export class AppProcess {
371
371
  const main = this.app === undefined ? undefined : await answerWithin(this.app.main, TITLE_MS);
372
372
  if (main === undefined)
373
373
  return undefined;
374
- const title = await answerWithin(main.evaluate(({ BrowserWindow, webContents }, targetId) => {
375
- const contents = webContents.fromDevToolsTargetId(targetId);
376
- return contents === undefined ? undefined : BrowserWindow.fromWebContents(contents)?.getTitle();
377
- }, page.targetId), TITLE_MS);
374
+ const title = await answerWithin(main.evaluate(osWindowTitle, page.targetId), TITLE_MS);
378
375
  return title ?? undefined;
379
376
  }
377
+ /**
378
+ * The OS window title of a page's `BrowserWindow`, as `windowTitle` reads
379
+ * it, but waited for as long as the caller waits: '' only when the app
380
+ * answered with none (a view, or an app with no main-process inspector),
381
+ * never because it answered late.
382
+ */
383
+ async answeredWindowTitle(page) {
384
+ const app = this.app;
385
+ if (app === undefined)
386
+ throw this.notRunning();
387
+ const main = await app.main;
388
+ if (main === undefined)
389
+ return '';
390
+ return (await main.evaluate(osWindowTitle, page.targetId)) ?? '';
391
+ }
380
392
  /** Closes one window, past any `beforeunload` guard, and resolves once it is gone. */
381
393
  async closeWindow(page) {
382
394
  const app = this.app;
@@ -494,6 +506,11 @@ function describeExit({ code, signal }) {
494
506
  return signal !== null ? `on ${signal}` : code !== null ? `with exit code ${code}` : '';
495
507
  }
496
508
  /** The Electron and Chromium versions of the running app, for the report's environment. */
509
+ /** Runs in the main process: the title of the `BrowserWindow` that shows a DevTools target, undefined for a view. */
510
+ function osWindowTitle({ BrowserWindow, webContents }, targetId) {
511
+ const contents = webContents.fromDevToolsTargetId(targetId);
512
+ return contents === undefined ? undefined : BrowserWindow.fromWebContents(contents)?.getTitle();
513
+ }
497
514
  async function readVersions(app, main) {
498
515
  if (main !== undefined)
499
516
  return await main.evaluate(() => ({ electron: process.versions.electron ?? '', chromium: process.versions.chrome ?? '' }), undefined);
package/dist/electron.js CHANGED
@@ -4,6 +4,7 @@
4
4
  * `electron.<method>` step bounded by the action timeout.
5
5
  */
6
6
  import { ConfigurationError, isSecret, stepTimeout, TestError } from '@e2e-dev/core/engine';
7
+ import { EXPECTATION_OPERATIONS, WindowConditions } from './expectation.js';
7
8
  import { typeKeys } from './actions.js';
8
9
  import { hasKey } from './cdp/input.js';
9
10
  import { unsupported } from './errors.js';
@@ -56,7 +57,9 @@ export function createElectronFixture(surface, context) {
56
57
  throw unsupported(`the keyboard has no key ${JSON.stringify(name)}: name a key such as "Shift" or "Enter", or a character of a US keyboard`);
57
58
  await surface.input(`keyboard.${direction}`, (window, budget) => budget.send(() => window.page.keyboard[direction](name)), context.operation());
58
59
  };
60
+ const conditions = new WindowConditions(surface, context);
59
61
  const electron = {
62
+ waitForURL: (url, options) => conditions.waitForURL(url, options),
60
63
  get userDataDir() {
61
64
  return surface.dataDirectory();
62
65
  },
@@ -146,7 +149,8 @@ export function createElectronFixture(surface, context) {
146
149
  },
147
150
  };
148
151
  const input = { kind: 'resource' };
149
- return context.fixture('electron', electron, {
152
+ return context.fixture('electron', context.expectable(electron, () => context.fixture('expect', conditions.expectation(), EXPECTATION_OPERATIONS)), {
153
+ waitForURL: { kind: 'resource', timeout: false, verifies: true, label: (url) => String(url) },
150
154
  launch: { kind: 'resource', timeout: false },
151
155
  keyboard: {
152
156
  press: { ...input, label: (key) => String(key) },
@@ -10,4 +10,4 @@ export type { ElectronEngine } from './engine.ts';
10
10
  export { electron as default } from './engine.ts';
11
11
  export type { ElectronOptions } from './options.ts';
12
12
  export type { Dialog, DialogHandler } from './dialogs.ts';
13
- export type { Electron, ElectronFixtures, ElectronKeyboard, ElectronLaunchOptions, ElectronMainModule, ElectronMouse, ElectronWindow, WindowMatcher } from './fixtures.ts';
13
+ export type { Electron, ElectronExpectation, ElectronFixtures, ElectronKeyboard, ElectronLaunchOptions, ElectronMainModule, ElectronMouse, ElectronWindow, WindowMatcher } from './fixtures.ts';
@@ -0,0 +1,30 @@
1
+ /**
2
+ * `expect(electron)` and `electron.waitForURL`: conditions of the active
3
+ * window polled against the assertion timeout, as `expect(browser)` polls a
4
+ * tab's on the web. Each failure reports the last read.
5
+ */
6
+ import { type EngineFixtureContext, type FixtureOperations } from '@e2e-dev/core/engine';
7
+ import type { ElectronExpectation } from './fixtures.ts';
8
+ import type { ElectronSurface } from './surface.ts';
9
+ export declare class WindowConditions {
10
+ private readonly surface;
11
+ private readonly context;
12
+ constructor(surface: ElectronSurface, context: EngineFixtureContext);
13
+ /** Polls `read` until it matches, or fails with the last read once the assertion timeout (or `timeout`) is over. */
14
+ private poll;
15
+ /**
16
+ * Whether a failed read is one a wait goes on through: the document went
17
+ * away under it (a navigation), or the window is closed or not there yet
18
+ * while the app still runs. A read that hangs is the poll's own to judge.
19
+ */
20
+ private passing;
21
+ private url;
22
+ /** `electron.waitForURL()`: the poll `expect(electron).toHaveURL` runs. */
23
+ waitForURL(expected: string | RegExp, options: {
24
+ readonly timeout?: number;
25
+ } | undefined): Promise<void>;
26
+ /** The `expect(electron)` matchers, or their negations. */
27
+ expectation(negated?: boolean): ElectronExpectation;
28
+ }
29
+ /** How the harness records each matcher: an assertion that owns its deadline. */
30
+ export declare const EXPECTATION_OPERATIONS: FixtureOperations<ElectronExpectation>;
@@ -0,0 +1,167 @@
1
+ /**
2
+ * `expect(electron)` and `electron.waitForURL`: conditions of the active
3
+ * window polled against the assertion timeout, as `expect(browser)` polls a
4
+ * tab's on the web. Each failure reports the last read.
5
+ */
6
+ import { Deadline, describePattern, EngineError, matchesText, pollCondition, rejectUnknownOptions, stepTimeout, TestError, toTextPattern, urlMatches, withTimeout, } from '@e2e-dev/core/engine';
7
+ export class WindowConditions {
8
+ surface;
9
+ context;
10
+ constructor(surface, context) {
11
+ this.surface = surface;
12
+ this.context = context;
13
+ }
14
+ /** Polls `read` until it matches, or fails with the last read once the assertion timeout (or `timeout`) is over. */
15
+ async poll(call, label, read, timeout) {
16
+ const { context } = this;
17
+ const deadline = new Deadline(context.operation(stepTimeout(timeout, call.api) ?? context.timeouts.assertion).timeoutMs);
18
+ let last;
19
+ await pollCondition({
20
+ deadline,
21
+ signal: context.signal,
22
+ negated: call.negated,
23
+ evaluate: async () => {
24
+ // A dialog nothing answered fails this step, as it fails any other: one that opens under the wait, too.
25
+ this.surface.failOnDialog();
26
+ try {
27
+ last = await read(deadline);
28
+ }
29
+ catch (cause) {
30
+ if (!this.passing(cause))
31
+ throw cause;
32
+ // What the read before it saw stays what the failure reports: this one saw nothing.
33
+ last = { matches: undefined, observed: last?.observed ?? 'nothing: the window was loading or closing' };
34
+ }
35
+ // One that opened while the read ran is this step's too. Outside the catch: it is no read to wait through.
36
+ this.surface.failOnDialog();
37
+ return last.matches;
38
+ },
39
+ onTimeout: (cause) => new TestError('ASSERTION_FAILED', `${call.name} failed\nexpected: ${call.negated ? 'not ' : ''}${label}\nobserved: ${last?.observed ?? 'nothing'}`, cause === undefined ? undefined : { cause }),
40
+ });
41
+ }
42
+ /**
43
+ * Whether a failed read is one a wait goes on through: the document went
44
+ * away under it (a navigation), or the window is closed or not there yet
45
+ * while the app still runs. A read that hangs is the poll's own to judge.
46
+ */
47
+ passing(cause) {
48
+ if (!(cause instanceof EngineError))
49
+ return false;
50
+ return cause.retryable || (cause.code === 'INVALID_STATE' && this.surface.appRunning && !this.surface.shownCrashed);
51
+ }
52
+ url(call, expected, options) {
53
+ const ignoreCase = options?.ignoreCase;
54
+ if (ignoreCase !== undefined && typeof ignoreCase !== 'boolean')
55
+ throw new TestError('INVALID_ARGUMENT', `${call.name} option ignoreCase must be a boolean`);
56
+ const pattern = toTextPattern(expected);
57
+ // An Electron target has no base URL, and the window's own moves with the wait: a relative string has nothing to resolve against.
58
+ if (pattern.kind !== 'regexp' && !URL.canParse(pattern.value)) {
59
+ throw new TestError('INVALID_ARGUMENT', `${call.name} takes an absolute URL or a RegExp, not ${JSON.stringify(pattern.value)}: an Electron app has no base URL to resolve it against`);
60
+ }
61
+ // Parsed once, on its own: `https:page` would resolve against a base of the same scheme, and the window's moves.
62
+ const wanted = pattern.kind === 'regexp' ? expected : new URL(pattern.value).href;
63
+ return this.poll(call, `URL ${String(wanted)}${ignoreCase === true ? ' (ignoring case)' : ''}`, () => {
64
+ const url = this.surface.shownWindow().page.url();
65
+ return Promise.resolve({ matches: urlMatches(url, wanted, String(wanted), ignoreCase), observed: `URL ${url}` });
66
+ }, options?.timeout);
67
+ }
68
+ /** `electron.waitForURL()`: the poll `expect(electron).toHaveURL` runs. */
69
+ waitForURL(expected, options) {
70
+ rejectUnknownOptions('electron.waitForURL', options, ['timeout']);
71
+ return this.url({ api: 'electron.waitForURL', name: 'electron.waitForURL', negated: false }, expected, options);
72
+ }
73
+ /** The `expect(electron)` matchers, or their negations. */
74
+ expectation(negated = false) {
75
+ const call = (api) => ({ api, name: `expect.${negated ? 'not.' : ''}${api}`, negated });
76
+ const timeoutOf = (api, options) => {
77
+ rejectUnknownOptions(`expect.${negated ? 'not.' : ''}${api}`, options, ['timeout']);
78
+ return options?.timeout;
79
+ };
80
+ const negate = () => this.expectation(!negated);
81
+ return {
82
+ get not() {
83
+ return negate();
84
+ },
85
+ toHaveURL: (expected, options) => {
86
+ rejectUnknownOptions(`expect.${negated ? 'not.' : ''}toHaveURL`, options, ['ignoreCase', 'timeout']);
87
+ return this.url(call('toHaveURL'), expected, options);
88
+ },
89
+ toHaveTitle: (expected, options) => {
90
+ const pattern = toTextPattern(expected, { exact: true });
91
+ return this.poll(call('toHaveTitle'), `title ${describePattern(pattern)}`, async (deadline) => {
92
+ const window = this.surface.shownWindow();
93
+ const switched = whenInactive(this.surface, window);
94
+ let title;
95
+ try {
96
+ // A slow read of a window that is no longer the active one is not waited for: the next poll reads the one that is.
97
+ title = await Promise.race([this.surface.currentTitle(window, this.context.operation(deadline.remaining())), switched.changed]);
98
+ }
99
+ finally {
100
+ switched.stop();
101
+ }
102
+ // Another window became the active one while this one answered: its title is not the one asked about.
103
+ if (title === undefined || !this.surface.isActiveWindow(window))
104
+ return { matches: undefined, observed: 'nothing: the active window changed' };
105
+ return { matches: matchesText(title, pattern), observed: `title ${JSON.stringify(title)}` };
106
+ }, timeoutOf('toHaveTitle', options));
107
+ },
108
+ toHaveClass: (target, expected, options) => {
109
+ const pattern = toTextPattern(expected, { exact: true });
110
+ return this.poll(call('toHaveClass'), `class ${describePattern(pattern)}`, async (deadline) => {
111
+ let value;
112
+ try {
113
+ // A locator read takes the action timeout; the poll's deadline is the tighter bound.
114
+ value = await withTimeout(readClass(target), deadline.remaining(), () => new EngineError('OPERATION_TIMEOUT', 'class read timed out', { retryable: false }));
115
+ }
116
+ catch (cause) {
117
+ if (cause.code === 'LOCATOR_NOT_FOUND')
118
+ return { matches: undefined, observed: 'no node' };
119
+ throw cause;
120
+ }
121
+ if (value === undefined)
122
+ return { matches: undefined, observed: 'no node' };
123
+ // An absent attribute is no class list at all, which '' does not match, as on the web.
124
+ if (value === null)
125
+ return { matches: false, observed: 'no class attribute' };
126
+ return { matches: matchesText(value.trim().split(/\s+/).join(' '), pattern), observed: `class ${JSON.stringify(value)}` };
127
+ }, timeoutOf('toHaveClass', options));
128
+ },
129
+ };
130
+ }
131
+ }
132
+ /** How often a read of one window checks that the window is still the active one. */
133
+ const ACTIVE_CHECK_MS = 50;
134
+ /**
135
+ * Resolves with undefined once `window` is no longer the active one, checked
136
+ * every `ACTIVE_CHECK_MS` until `stop` is called. Nothing tells the surface
137
+ * of the switch but its own reads, so it is sampled.
138
+ */
139
+ function whenInactive(surface, window) {
140
+ let timer;
141
+ const changed = new Promise((resolve) => {
142
+ timer = setInterval(() => {
143
+ if (!surface.isActiveWindow(window))
144
+ resolve(undefined);
145
+ }, ACTIVE_CHECK_MS);
146
+ });
147
+ return { changed, stop: () => clearInterval(timer) };
148
+ }
149
+ /**
150
+ * The class attribute of one match, undefined while nothing matches. A read
151
+ * waits for its match until the action timeout, so the poll samples absence
152
+ * first: a node that never arrives stays an assertion failure.
153
+ */
154
+ async function readClass(target) {
155
+ if ((await target.count()) === 0)
156
+ return undefined;
157
+ return target.getAttribute('class');
158
+ }
159
+ /** How the harness records each matcher: an assertion that owns its deadline. */
160
+ export const EXPECTATION_OPERATIONS = {
161
+ toHaveURL: { kind: 'assertion', timeout: false, label: (expected) => String(expected) },
162
+ toHaveTitle: { kind: 'assertion', timeout: false, label: (expected) => String(expected) },
163
+ toHaveClass: { kind: 'assertion', timeout: false, label: (_target, expected) => String(expected) },
164
+ get not() {
165
+ return EXPECTATION_OPERATIONS;
166
+ },
167
+ };
@@ -3,7 +3,7 @@
3
3
  * what the package's public entries declare, apart from the engine's own
4
4
  * modules.
5
5
  */
6
- import type { Locator } from '@e2e-dev/core/engine';
6
+ import type { Expectable, Locator, TextMatch } from '@e2e-dev/core/engine';
7
7
  import type { DialogHandler } from './dialogs.ts';
8
8
  /**
9
9
  * One window of the running app: a `BrowserWindow`, a `WebContentsView`, or a
@@ -48,7 +48,7 @@ export type ElectronMainModule = typeof import('electron');
48
48
  /** What `electron.launch` adds to the target's own launch arguments and the engine's `env`. */
49
49
  export interface ElectronLaunchOptions {
50
50
  /** Arguments after the target's `app.launchArguments`: the app's own switches and Chromium's. */
51
- readonly args?: readonly string[] | undefined;
51
+ readonly launchArguments?: readonly string[] | undefined;
52
52
  /** Variables over the engine's `env`. Never `ELECTRON_RUN_AS_NODE` or `NODE_OPTIONS`. */
53
53
  readonly env?: Readonly<Record<string, string>> | undefined;
54
54
  /** The directory the app's process starts in, over the engine's `cwd`: absolute, or relative to the project root. */
@@ -86,8 +86,26 @@ export interface ElectronMouse {
86
86
  /** Scrolls by a wheel turn where the pointer is. */
87
87
  wheel(deltaX: number, deltaY: number): Promise<void>;
88
88
  }
89
+ /** What `expect(electron)` asserts of the active window, each polled until the assertion timeout or `timeout`. */
90
+ export interface ElectronExpectation {
91
+ /** The same matchers, negated. */
92
+ readonly not: ElectronExpectation;
93
+ /** The window's URL: a string is an absolute URL, compared as one; a `RegExp` is tested against it. */
94
+ toHaveURL(expected: string | RegExp, options?: {
95
+ readonly ignoreCase?: boolean;
96
+ readonly timeout?: number;
97
+ }): Promise<void>;
98
+ /** The window's title, the document's or else the OS window's. */
99
+ toHaveTitle(expected: TextMatch, options?: {
100
+ readonly timeout?: number;
101
+ }): Promise<void>;
102
+ /** The `class` attribute of the one node `target` matches: a string is the whole class list, a `RegExp` is tested against it. */
103
+ toHaveClass(target: Locator, expected: TextMatch, options?: {
104
+ readonly timeout?: number;
105
+ }): Promise<void>;
106
+ }
89
107
  /** Deterministic Electron app management exposed to tests as `electron`. */
90
- export interface Electron {
108
+ export interface Electron extends Expectable<ElectronExpectation> {
91
109
  /**
92
110
  * The directory the app keeps its data in for this test, empty until the
93
111
  * app writes to it. It exists before the app is launched, so a test can
@@ -104,6 +122,14 @@ export interface Electron {
104
122
  launch(options?: ElectronLaunchOptions): Promise<void>;
105
123
  /** The active window, the one `screen`, `expect`, and the agent act on. Throws `INVALID_STATE` when the app has no open window. */
106
124
  activeWindow(): ElectronWindow;
125
+ /**
126
+ * Waits for the active window's URL to match: a string is an absolute URL,
127
+ * never a glob or a path; a `RegExp` is tested against it. Rejects with `ASSERTION_FAILED` after
128
+ * `timeout` milliseconds, or else the assertion timeout.
129
+ */
130
+ waitForURL(url: string | RegExp, options?: {
131
+ readonly timeout?: number;
132
+ }): Promise<void>;
107
133
  /** Keyboard input to the active window. */
108
134
  readonly keyboard: ElectronKeyboard;
109
135
  /** Pointer input to the active window. */
package/dist/options.js CHANGED
@@ -98,7 +98,7 @@ export function checkCwd(label, projectRoot, cwd, code) {
98
98
  if (statSync(resolved, { throwIfNoEntry: false })?.isDirectory() !== true)
99
99
  throw refusal(code, `${label} names ${resolved}, which is not a directory`);
100
100
  }
101
- const LAUNCH_KEYS = ['args', 'env', 'cwd', 'timeout'];
101
+ const LAUNCH_KEYS = ['launchArguments', 'env', 'cwd', 'timeout'];
102
102
  /** What `electron.launch()` was given, checked: the arguments, variables, and directory one test adds to its launches. */
103
103
  export function checkLaunchOptions(options, projectRoot) {
104
104
  const label = 'electron.launch()';
@@ -107,12 +107,12 @@ export function checkLaunchOptions(options, projectRoot) {
107
107
  if (typeof options !== 'object' || options === null || Array.isArray(options))
108
108
  throw refusal('INVALID_ARGUMENT', `${label} takes an object of options`);
109
109
  rejectUnknownKeys(`${label} options`, options, LAUNCH_KEYS, 'INVALID_ARGUMENT');
110
- const { args = [], env, cwd } = options;
110
+ const { launchArguments: args = [], env, cwd } = options;
111
111
  if (!Array.isArray(args) || args.some((argument) => typeof argument !== 'string'))
112
- throw refusal('INVALID_ARGUMENT', 'electron.launch({ args }) must be a list of strings');
112
+ throw refusal('INVALID_ARGUMENT', 'electron.launch({ launchArguments }) must be a list of strings');
113
113
  const owned = args.map(ownedArgument).find((reason) => reason !== undefined);
114
114
  if (owned !== undefined)
115
- throw refusal('INVALID_ARGUMENT', `electron.launch({ args }) ${owned}`);
115
+ throw refusal('INVALID_ARGUMENT', `electron.launch({ launchArguments }) ${owned}`);
116
116
  checkEnv('electron.launch({ env })', env, 'INVALID_ARGUMENT');
117
117
  checkCwdShape('electron.launch({ cwd })', cwd, 'INVALID_ARGUMENT');
118
118
  checkCwd('electron.launch({ cwd })', projectRoot, cwd, 'INVALID_ARGUMENT');
package/dist/surface.d.ts CHANGED
@@ -83,7 +83,7 @@ export declare class ElectronSurface {
83
83
  /** Why the window is not one to observe, trace, or capture: it shows a local file outside the app's directory. */
84
84
  private leftApp;
85
85
  /** Fails the step that follows a dialog nothing answered, or whose handler failed. */
86
- private failOnDialog;
86
+ failOnDialog(): void;
87
87
  private requireWindow;
88
88
  /**
89
89
  * Every action goes through here: its input within the operation's budget,
@@ -133,6 +133,18 @@ export declare class ElectronSurface {
133
133
  * does not. Either is a title `electron.window({ title })` matches.
134
134
  */
135
135
  windowTitle(window: AppWindow, operation: OperationContext): Promise<string>;
136
+ /**
137
+ * The title `expect(electron).toHaveTitle` polls: the document's, read
138
+ * within the operation so a read the deadline cuts off is a timeout and
139
+ * never another title, else the OS window's for a document with none. A
140
+ * window whose renderer crashed is waited on as `readShown` waits on it:
141
+ * briefly, for the app to load it again, and then said to have crashed.
142
+ */
143
+ currentTitle(window: AppWindow, operation: OperationContext): Promise<string>;
144
+ /** Whether the shown window's renderer crashed: a wait on the window ends with that, where a closing window is waited through. */
145
+ get shownCrashed(): boolean;
146
+ /** Whether the app is running: a wait on its window goes on through a window closing or loading, and ends when the app is gone. */
147
+ get appRunning(): boolean;
136
148
  /** `electron.onDialog()`: answers the app's dialogs from now on, until what it returns is called. */
137
149
  onDialog(handler: DialogHandler): () => void;
138
150
  /** Runs a function in the app's main process. */
package/dist/surface.js CHANGED
@@ -492,6 +492,60 @@ export class ElectronSurface {
492
492
  return document;
493
493
  return (await this.app.windowTitle(window.page)) ?? '';
494
494
  }
495
+ /**
496
+ * The title `expect(electron).toHaveTitle` polls: the document's, read
497
+ * within the operation so a read the deadline cuts off is a timeout and
498
+ * never another title, else the OS window's for a document with none. A
499
+ * window whose renderer crashed is waited on as `readShown` waits on it:
500
+ * briefly, for the app to load it again, and then said to have crashed.
501
+ */
502
+ async currentTitle(window, operation) {
503
+ const { page } = window;
504
+ const read = async () => {
505
+ const document = await page.title();
506
+ // The OS title is read within the operation too: a main process that answers late has said nothing, not ''.
507
+ return document !== '' ? document : await this.app.answeredWindowTitle(page);
508
+ };
509
+ return await withBudget(operation, 'window title', async (budget) => {
510
+ for (;;) {
511
+ if (this.windowList.isCrashed(window)) {
512
+ let stopListening = () => undefined;
513
+ const loadedOrClosed = new Promise((resolve) => {
514
+ const stops = [page.on('load', resolve), page.on('close', resolve)];
515
+ stopListening = () => stops.forEach((stop) => stop());
516
+ });
517
+ await answerWithin(loadedOrClosed, Math.min(CRASH_RELOAD_WAIT_MS, budget.waits.remaining()));
518
+ stopListening();
519
+ if (page.isClosed())
520
+ throw invalidState('the window closed');
521
+ if (this.windowList.isCrashed(window))
522
+ throw crashed();
523
+ }
524
+ // A read the renderer's crash leaves pending would never settle: the crash ends it, and the next pass waits.
525
+ let stopWaiting = () => undefined;
526
+ const crash = new Promise((resolve) => {
527
+ stopWaiting = page.on('crash', () => resolve('crashed'));
528
+ });
529
+ try {
530
+ const title = await Promise.race([read(), crash]);
531
+ if (title !== 'crashed' || !this.windowList.isCrashed(window))
532
+ return title;
533
+ }
534
+ finally {
535
+ stopWaiting();
536
+ }
537
+ }
538
+ });
539
+ }
540
+ /** Whether the shown window's renderer crashed: a wait on the window ends with that, where a closing window is waited through. */
541
+ get shownCrashed() {
542
+ const window = this.windowList.current();
543
+ return window !== undefined && this.windowList.isCrashed(window);
544
+ }
545
+ /** Whether the app is running: a wait on its window goes on through a window closing or loading, and ends when the app is gone. */
546
+ get appRunning() {
547
+ return this.app.running;
548
+ }
495
549
  /** `electron.onDialog()`: answers the app's dialogs from now on, until what it returns is called. */
496
550
  onDialog(handler) {
497
551
  return this.dialogs.add(handler);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e2e-dev/electron",
3
- "version": "0.0.0",
3
+ "version": "0.0.1-nightly-20261130030410",
4
4
  "description": "Electron engine for e2e agentic end-to-end testing: launches an Electron app and drives its windows through Chromium's accessibility tree",
5
5
  "keywords": [
6
6
  "e2e",
@@ -42,8 +42,8 @@
42
42
  "NOTICE"
43
43
  ],
44
44
  "peerDependencies": {
45
- "@e2e-dev/core": ">=0.25.1 <1",
46
- "e2e": ">=0.25.1 <1",
45
+ "@e2e-dev/core": "0.26.0-nightly-20261130030410",
46
+ "e2e": "0.26.0-nightly-20261130030410",
47
47
  "electron": "*"
48
48
  },
49
49
  "peerDependenciesMeta": {
@@ -52,11 +52,11 @@
52
52
  }
53
53
  },
54
54
  "devDependencies": {
55
- "@e2e-dev/core": "0.25.0",
55
+ "@e2e-dev/core": "0.26.0-nightly-20261130030410",
56
56
  "@napi-rs/image": "1.16.0",
57
57
  "@types/node": "26.6.11",
58
58
  "devtools-protocol": "0.0.1756183",
59
- "e2e": "0.25.0",
59
+ "e2e": "0.26.0-nightly-20261130030410",
60
60
  "electron": "45.5.0",
61
61
  "typescript": "7.0.2",
62
62
  "vitest": "5.1.2"