Skip to content

Commit 5564dbe

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/forms-and-quality-checks
2 parents 0ebb128 + 0bf4cc5 commit 5564dbe

1 file changed

Lines changed: 38 additions & 5 deletions

File tree

‎test/e2e/network.e2e.test.ts‎

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ const EMPTY_CART = '{ "items": [], "total": 0 }';
2424
const HELD_USER = '{ "data": { "user": { "name": "Held", "id": 1 } } }';
2525
const SAVED_USER = '{ "data": { "user": { "name": "Saved", "id": 2 } } }';
2626

27-
/** Starts a call in the page without waiting for it (it may be held); `window.settled` gets what the page got. */
28-
const start = (call: string) => `window.settled = undefined; ${call}.then((r) => { window.settled = r; }); true`;
27+
/**
28+
* Starts a call in the page without waiting for it (it may be held); `window.settled` gets what the page got,
29+
* from the call started last only: one started before it may still settle.
30+
*/
31+
const start = (call: string) =>
32+
`window.settled = undefined; { const n = (window.started = (window.started ?? 0) + 1); ${call}.then((r) => { if (window.started === n) window.settled = r; }); } true`;
2933

3034
describe.skipIf(!built)('Network panel and response overrides in the app', () => {
3135
let site: FixtureSite;
@@ -43,6 +47,32 @@ describe.skipIf(!built)('Network panel and response overrides in the app', () =>
4347
await expect.poll(() => win.getByRole('menu').count()).toBe(0);
4448
await win.getByTestId(testId).click();
4549
}
50+
const heldHeaders = () => win.getByTestId('held-header');
51+
52+
/**
53+
* Whether a breakpoint holds the call started last. The menu shows a breakpoint at once, and main has the
54+
* page stop what it names a moment later, once the workspace is saved: a call that went out before then
55+
* goes through, and `call` is started again.
56+
*/
57+
async function heldOrStartAgain(call: string): Promise<boolean> {
58+
if ((await heldHeaders().count()) > 0) return true;
59+
// Still pending reads as null: only a call that settled is started again.
60+
if (await settled()) await inSite(start(call));
61+
return false;
62+
}
63+
64+
/**
65+
* What the page got from the call started last, once it went through without being held. Main drops a
66+
* removed breakpoint a moment after the menu does: a call it held meanwhile is let go, and `call` is
67+
* started again.
68+
*/
69+
async function settledOrStartAgain(call: string): Promise<unknown> {
70+
if ((await heldHeaders().count()) === 0) return settled();
71+
await win.getByTestId('held-send-original').click();
72+
await expect.poll(() => heldHeaders().count()).toBe(0);
73+
await inSite(start(call));
74+
return undefined;
75+
}
4676
const editorText = async () => (await win.locator('.monaco-editor .view-lines').textContent())?.replace(/\u00a0/g, ' ');
4777

4878
/** Replaces the active editor's text. Pasted: typing would have the editor close each bracket as it opens. */
@@ -126,7 +156,8 @@ describe.skipIf(!built)('Network panel and response overrides in the app', () =>
126156
await expect.poll(() => win.getByTestId('network-breakpoints').getAttribute('aria-label')).toBe('Breakpoints (1 on)');
127157

128158
expect(await inSite(start("tryGql('GetUser')"))).toBe(true);
129-
await expect.poll(() => win.getByTestId('held-header').textContent(), RELOAD_TIMEOUT).toContain('Paused at the response');
159+
await expect.poll(() => heldOrStartAgain("tryGql('GetUser')"), RELOAD_TIMEOUT).toBe(true);
160+
await expect.poll(() => heldHeaders().textContent()).toContain('Paused at the response');
130161
await expect.poll(() => win.getByTestId('network-held-request').count()).toBe(1);
131162
await expect.poll(() => win.getByTestId('status-paused').textContent()).toContain('1 paused');
132163
expect(await settled()).toBeFalsy();
@@ -164,19 +195,21 @@ describe.skipIf(!built)('Network panel and response overrides in the app', () =>
164195
await win.keyboard.press('Escape');
165196

166197
expect(await inSite(start('tryCart()'))).toBe(true);
167-
await expect.poll(() => win.getByTestId('held-header').textContent(), RELOAD_TIMEOUT).toContain('Paused before sending');
198+
await expect.poll(() => heldOrStartAgain('tryCart()'), RELOAD_TIMEOUT).toBe(true);
199+
await expect.poll(() => heldHeaders().textContent()).toContain('Paused before sending');
168200
expect(await win.getByTestId('held-url').inputValue()).toBe(`${site.url}${CART_PATH}`);
169201
await win.getByTestId('held-fail').click();
170202
await win.getByRole('menuitem', { name: 'Connection refused' }).click();
171203
await expect.poll(settled).toEqual({ error: 'TypeError' });
204+
await expect.poll(() => heldHeaders().count()).toBe(0);
172205

173206
// Removed, the next one goes through.
174207
await win.getByTestId('network-breakpoints').click();
175208
await win.getByTestId('breakpoint-row').last().getByRole('button', { name: 'Remove the breakpoint' }).click();
176209
await expect.poll(() => win.getByTestId('breakpoint-row').count()).toBe(1);
177210
await win.keyboard.press('Escape');
178211
expect(await inSite(start('tryCart()'))).toBe(true);
179-
await expect.poll(settled).toMatchObject({ status: 200 });
212+
await expect.poll(() => settledOrStartAgain('tryCart()'), RELOAD_TIMEOUT).toMatchObject({ status: 200 });
180213
});
181214

182215
it('patches the live response with the saved edits', async () => {

0 commit comments

Comments
 (0)