Skip to content

Commit 0ebb128

Browse files
committed
Merge remote-tracking branch 'origin/bugfix/page-window-e2e-races' into feature/forms-and-quality-checks
2 parents 52898f6 + 68c3f39 commit 0ebb128

3 files changed

Lines changed: 22 additions & 12 deletions

File tree

‎src/main/ActionsWindow/ActionsWindow.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,16 @@ export class ActionsWindow {
9090
if (win && !win.isDestroyed()) win.destroy();
9191
}
9292

93-
/** The window is asked to close: it docks the panel instead (once the close event is over), unless the app quits. */
93+
/**
94+
* The window is asked to close: it docks the panel instead, once the close event is over (as the website's
95+
* window does: see PageWindow), unless the app quits.
96+
*/
9497
private closing(): void {
9598
if (this.quitting) {
9699
this.quitting = false;
97100
return;
98101
}
99-
queueMicrotask(() => this.attach());
102+
setImmediate(() => this.attach());
100103
}
101104

102105
private show(win: BrowserWindow): void {

‎src/main/PageWindow/PageWindow.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,19 @@ export class PageWindow {
108108
if (win && !win.isDestroyed()) win.destroy();
109109
}
110110

111-
/** The website window is asked to close: it puts the website back instead (once the close event is over). */
111+
/**
112+
* The website window is asked to close: it puts the website back instead, once the close event is over. Not in a
113+
* microtask: that runs before the event returns to Electron, which then goes on with a window destroyed under it
114+
* (the app crashed now and then).
115+
*/
112116
private closing(): void {
113117
// By the quit: it stays as it is, to go with the editor's window (`dispose`) and open again next time. Should
114118
// the editor stay (its drafts couldn't be written), nothing has moved.
115119
if (this.quitting) {
116120
this.quitting = false;
117121
return;
118122
}
119-
queueMicrotask(() => this.attach());
123+
setImmediate(() => this.attach());
120124
}
121125

122126
/** Moves the view back into the editor and destroys the website window. Returns whether there was one. */

‎test/e2e/pageWindow.e2e.test.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ const sandboxArgs = process.getuid?.() === 0 ? ['--no-sandbox'] : [];
2222
const EDITOR_URL = /\/renderer\/index\.html$/;
2323
const PAGE_WINDOW_URL = /\/renderer\/index\.html#page-window$/;
2424

25+
/** A window opening or closing, and Playwright hearing of it: past expect.poll's default second on a busy machine. */
26+
const WINDOW_TIMEOUT = { timeout: 10_000 };
27+
2528
/** Polls until `fn` returns a truthy value (usable outside tests, unlike expect.poll). */
2629
async function waitFor<T>(fn: () => T | undefined, timeout = 30_000): Promise<T> {
2730
const deadline = Date.now() + timeout;
@@ -163,7 +166,7 @@ describe.skipIf(!built)('The website in a window of its own', () => {
163166
const own = await pageWindow(app);
164167
await inSite('window.marker = 43');
165168
await putBack(own);
166-
await expect.poll(openWindows).toBe(0);
169+
await expect.poll(openWindows, WINDOW_TIMEOUT).toBe(0);
167170
await expect.poll(async () => (await host())?.hash).toBe('');
168171
await expect.poll(async () => (await host())?.view.width).toBeGreaterThan(0);
169172
expect(await inSite('window.marker')).toBe(43);
@@ -180,7 +183,7 @@ describe.skipIf(!built)('The website in a window of its own', () => {
180183
BrowserWindow.getAllWindows().find((w) => w.webContents.getURL().endsWith('#page-window'))!.setBounds(bounds);
181184
}, moved);
182185
await app.evaluate(({ BrowserWindow }) => BrowserWindow.getAllWindows().find((w) => w.webContents.getURL().endsWith('#page-window'))!.close());
183-
await expect.poll(openWindows).toBe(0);
186+
await expect.poll(openWindows, WINDOW_TIMEOUT).toBe(0);
184187
await expect.poll(async () => (await host())?.hash).toBe('');
185188
await expect.poll(async () => (await savedPlacement()).bounds).toEqual(moved);
186189

@@ -197,7 +200,7 @@ describe.skipIf(!built)('The website in a window of its own', () => {
197200

198201
it("brings it back from the editor's title bar, and the View menu moves it either way", async () => {
199202
await win.getByRole('button', { name: 'Show website preview' }).click();
200-
await expect.poll(openWindows).toBe(0);
203+
await expect.poll(openWindows, WINDOW_TIMEOUT).toBe(0);
201204
await expect.poll(async () => (await host())?.hash).toBe('');
202205

203206
const menu = (action: 'click' | 'checked') =>
@@ -213,7 +216,7 @@ describe.skipIf(!built)('The website in a window of its own', () => {
213216
await pageWindow(app);
214217
await expect.poll(() => menu('checked')).toBe(true);
215218
await menu('click');
216-
await expect.poll(openWindows).toBe(0);
219+
await expect.poll(openWindows, WINDOW_TIMEOUT).toBe(0);
217220
await expect.poll(() => menu('checked')).toBe(false);
218221
await expect.poll(() => win.getByRole('region', { name: 'Website preview' }).count()).toBe(1);
219222
await expect.poll(async () => (await host())?.view.width).toBeGreaterThan(0);
@@ -229,13 +232,13 @@ describe.skipIf(!built)('The website in a window of its own', () => {
229232
const popup = BrowserWindow.getAllWindows().find((w) => w.webContents.getURL() === url);
230233
return popup ? (popup.getParentWindow()?.webContents.getURL() ?? null) : undefined;
231234
}, `${site.url}/frames.html?popup`);
232-
await expect.poll(popupParent).toMatch(PAGE_WINDOW_URL);
235+
await expect.poll(popupParent, WINDOW_TIMEOUT).toMatch(PAGE_WINDOW_URL);
233236

234237
await putBack(await pageWindow(app));
235-
await expect.poll(openWindows).toBe(0);
238+
await expect.poll(openWindows, WINDOW_TIMEOUT).toBe(0);
236239
await expect.poll(popupParent).toMatch(EDITOR_URL);
237240
await app.evaluate(({ BrowserWindow }, url) => BrowserWindow.getAllWindows().find((w) => w.webContents.getURL() === url)?.close(), `${site.url}/frames.html?popup`);
238-
await expect.poll(popupParent).toBeUndefined();
241+
await expect.poll(popupParent, WINDOW_TIMEOUT).toBeUndefined();
239242
});
240243

241244
it('copes with being put back, or asked for its address bar, while its window still loads', async () => {
@@ -262,7 +265,7 @@ describe.skipIf(!built)('The website in a window of its own', () => {
262265
const own = await pageWindow(app);
263266
await expect.poll(() => own.getByTestId('address-bar').evaluate((el) => el === el.ownerDocument.activeElement)).toBe(true);
264267
await putBack(own);
265-
await expect.poll(openWindows).toBe(0);
268+
await expect.poll(openWindows, WINDOW_TIMEOUT).toBe(0);
266269
});
267270

268271
it('opens in its own window again after a restart, if it was there when the app quit', async () => {

0 commit comments

Comments
 (0)