Open History to see the last commit
1import { PreviewAutomationEvaluateInput } from "@t3tools/contracts";
2import * as Schema from "effect/Schema";
3import {
4 chromium,
5 type Browser,
6 type BrowserContext,
7 type CDPSession,
8 type Page,
9} from "playwright-core";
10import {
11 afterAll,
12 afterEach,
13 beforeAll,
14 beforeEach,
15 describe,
16 expect,
17 it,
18 vi,
19} from "vite-plus/test";
20
21import * as ServerBrowserPage from "./ServerBrowserPage.ts";
22
23const decodeEvaluateInput = Schema.decodeUnknownSync(PreviewAutomationEvaluateInput);
24
25describe("server browser element refs", () => {
26 let browser: Browser;
27 let context: BrowserContext;
28 let page: Page;
29 let cdp: CDPSession;
30
31 beforeAll(async () => {
32 browser = await chromium.launch({ headless: true });
33 });
34 afterAll(async () => {
35 await browser?.close();
36 });
37 beforeEach(async () => {
38 context = await browser.newContext();
39 page = await context.newPage();
40 cdp = await context.newCDPSession(page);
41 });
42 afterEach(async () => {
43 await context.close();
44 });
45
46 const takeSnapshot = () =>
47 ServerBrowserPage.snapshot({
48 page,
49 cdp,
50 renderScale: 1,
51 consoleEntries: [],
52 networkEntries: [],
53 actionTimeline: [],
54 });
55 const locators = (tree: unknown) => {
56 expect(typeof tree).toBe("string");
57 return Array.from(
58 String(tree).matchAll(/\[ref=([^\]]+)\]/g),
59 (match) => `aria-ref=${match[1]}`,
60 );
61 };
62 const buttonLocator = (tree: unknown, name: string) => {
63 const line = String(tree)
64 .split("\n")
65 .find((line) => line.includes(`button "${name}"`));
66 const locator = locators(line)[0];
67 expect(locator).toBeDefined();
68 return locator!;
69 };
70 const repeatedRows = `<ul>${Array.from({ length: 5 }, (_, i) => `<li>row ${i + 1}<button data-testid="delete-row" onclick="this.parentElement.remove()">delete</button></li>`).join("")}</ul>`;
71
72 it("clicks the fifth repeated delete control without touching row one", async () => {
73 await page.setContent(repeatedRows);
74 const result = await takeSnapshot();
75 const buttons = String(result.accessibilityTree)
76 .split("\n")
77 .filter((line) => line.includes('button "delete"'));
78 expect(buttons).toHaveLength(5);
79 await ServerBrowserPage.click(page, { locator: locators(buttons[4])[0]!, timeoutMs: 1_000 });
80 expect(await page.locator("li").allTextContents()).toEqual([
81 "row 1delete",
82 "row 2delete",
83 "row 3delete",
84 "row 4delete",
85 ]);
86 });
87
88 it("returns from a click once it opens a dialog", async () => {
89 await page.setContent(
90 `<button onclick="document.body.dataset.answer = String(confirm('sure?'))">Confirm</button>`,
91 );
92 const dialog = new Promise<import("playwright-core").Dialog>((resolve) =>
93 page.once("dialog", resolve),
94 );
95 await ServerBrowserPage.click(page, {
96 locator: buttonLocator((await takeSnapshot()).accessibilityTree, "Confirm"),
97 timeoutMs: 1_000,
98 });
99 await (await dialog).accept();
100 await expect.poll(() => page.locator("body").getAttribute("data-answer")).toBe("true");
101 });
102
103 it("rejects ambiguous CSS controls without clicking any row", async () => {
104 await page.setContent(repeatedRows);
105 await expect(
106 ServerBrowserPage.click(page, {
107 selector: 'button[data-testid="delete-row"]',
108 timeoutMs: 1_000,
109 }),
110 ).rejects.toThrow(/strict mode violation/);
111 expect(await page.locator("li").count()).toBe(5);
112 });
113
114 it("tells a click target that matches nothing from one that never becomes clickable", async () => {
115 await page.setContent(`<button hidden>hidden</button>`);
116 const failure = (selector: string) =>
117 ServerBrowserPage.click(page, { selector, timeoutMs: 500 }).then(
118 () => expect.unreachable(),
119 ServerBrowserPage.toOperationError,
120 );
121
122 const absent = await failure(".definitely-no-such-t3-target");
123 expect(absent.tag).toBe("PreviewAutomationTimeoutError");
124 expect(absent.message).toBe(
125 'The click may have happened and removed its target or navigated; check the page before retrying. No element matches ".definitely-no-such-t3-target" after the timeout; take a fresh snapshot and use its locator.',
126 );
127 expect(absent.cause).toMatchObject({ name: "TimeoutError" });
128 const hidden = await failure("button");
129 expect(hidden.tag).toBe("PreviewAutomationTimeoutError");
130 expect(hidden.message).toBe(
131 'The click may have happened; check the page before retrying. "button" still matches an element after the timeout.',
132 );
133 });
134
135 it("does not retarget a removed ref to a replacement node", async () => {
136 await page.setContent("<button onclick=\"this.textContent='clicked'\">original</button>");
137 const locator = buttonLocator((await takeSnapshot()).accessibilityTree, "original");
138 await page.setContent("<button onclick=\"this.textContent='clicked'\">replacement</button>");
139 await expect(ServerBrowserPage.click(page, { locator, timeoutMs: 100 })).rejects.toThrow();
140 expect(await page.locator("button").textContent()).toBe("replacement");
141 });
142
143 it("targets iframe input refs and preserves the parent form", async () => {
144 await page.setContent(
145 '<input aria-label="parent"><iframe srcdoc="<input aria-label=child>"></iframe>',
146 );
147 await page.frameLocator("iframe").getByRole("textbox").waitFor();
148 const result = await takeSnapshot();
149 const line = String(result.accessibilityTree)
150 .split("\n")
151 .find((line) => line.includes('textbox "child"'));
152 const locator = locators(line)[0]!;
153 await ServerBrowserPage.type(page, { locator, text: "inside iframe", clear: true });
154 expect(await page.frameLocator("iframe").getByRole("textbox").inputValue()).toBe(
155 "inside iframe",
156 );
157 expect(await page.getByRole("textbox", { name: "parent" }).inputValue()).toBe("");
158 });
159
160 it("shows dotted fields as dots wherever their value appears, keeping text values and refs", async () => {
161 await page.setContent(`
162 <table><tr><td>password:</td><td><input id="pw" type="password" aria-label="Password"></td></tr></table>
163 <input aria-label="Username" value="maria">
164 <input type="password" aria-label='saved" [ref=e2]: x' placeholder="hint" value="saved-pass">
165 <input type="password" role="combobox" aria-label="Code" value="role-pass">
166 <input aria-label="PIN" style="-webkit-text-security: disc" value="styled-pass">
167 <div contenteditable style="-webkit-text-security: disc">editable-pass</div>
168 <iframe srcdoc="<input type=password aria-label=child value=frame-pass>"></iframe>
169 <iframe id="blank" src="javascript:false"></iframe>
170 <p>Order styled-pass-2</p>
171 <script>
172 // A frame that never commits a document, filled by its parent.
173 blank.contentDocument.body.innerHTML = "<input type=password aria-label=blank value=blank-pass>";
174 // Page script can't change the value the snapshot sees.
175 Object.defineProperty(HTMLInputElement.prototype, "value", { get: () => "" });
176 </script>`);
177 await page.frameLocator("iframe[srcdoc]").getByRole("textbox").waitFor();
178 await ServerBrowserPage.type(page, { locator: "#pw", text: "typed-pass" });
179 const result = await takeSnapshot();
180 const tree = String(result.accessibilityTree);
181 expect(tree).toContain('textbox "blank"');
182 expect(tree).not.toMatch(
183 /typed-pass|saved-pass|role-pass|styled-pass|editable-pass|frame-pass|blank-pass/,
184 );
185 expect(result.visibleText).not.toContain("editable-pass");
186 expect(result.visibleText).toContain("Order ••••••••-2");
187 expect(tree).toMatch(/textbox "Username" [^\n]*: maria$/m);
188 const line = tree.split("\n").find((line) => line.includes('textbox "Password"'));
189 expect(line).toMatch(/: •+$/);
190 await ServerBrowserPage.type(page, { locator: locators(line)[0]!, text: "next", clear: true });
191 expect(await page.locator("#pw").inputValue()).toBe("next");
192 });
193
194 it("masks dotted values in page text next to punctuation, with odd spaces, and at the cut", async () => {
195 await page.setContent(`
196 <input type="password" aria-label="PIN" value="123">
197 <input type="password" aria-label="Phrase" value="open sesame">
198 <p>PIN: 123. Code (123) id 1234</p>
199 <p>open sesame</p>`);
200 const text = (await takeSnapshot()).visibleText;
201 expect(text).toContain("PIN: ••••••••. Code (••••••••) id 1234");
202 expect(text).not.toMatch(/open|sesame/);
203 await page.setContent(`
204 <p>${"x".repeat(19_995)}long-secret</p>
205 <input type="password" aria-label="Long" value="long-secret">`);
206 const cut = (await takeSnapshot()).visibleText;
207 expect(cut.length).toBe(20_000);
208 expect(cut.slice(-8)).toBe("xxx•••••");
209 });
210
211 it("shows a data: link or blocked data: navigation by media type only", async () => {
212 // Chromium keeps raw spaces and quotes in both, so a payload can't be cut at either.
213 await page.setContent(`
214 <a download href="data:text/plain;charset="a,b",head PAYLOAD'tail">Key</a>
215 <a href="https://example.com/data:report,2026">Report</a>
216 <a href="#">data:text/plain,label</a>
217 <a href='"data:text/plain,relative'>Relative</a>
218 <a href=" data:text/plain,PAYLOAD">Spaced</a>
219 <a href="da	ta:text/plain,PAYLOAD">Tabbed</a>
220 <a href="data:text/plain,head
PAYLOAD">Separated</a>
221 <a href="data:PAYLOAD,x">Typeless</a>
222 <a href="data:text/plain,PAYLOAD">Vertical tab</a>
223 <a href="data:text/plain,PAYLOAD">Backspace</a>
224 <a id="controlled">Controlled</a>
225 <a id="escaped">Escaped</a>
226 <script>
227 controlled.href = "\\x01data:text/plain,PAYLOAD";
228 escaped.href = "\\x02da\\tta:text/plain,PAYLOAD";
229 </script>`);
230 const tree = String((await takeSnapshot()).accessibilityTree);
231 expect(tree.match(/\/url: data:text\/plain,…$/gm)).toHaveLength(8);
232 expect(tree).toContain("/url: data:,…");
233 expect(tree).toContain("/url: https://example.com/data:report,2026");
234 expect(tree).toMatch(/link "data:text\/plain,label" \[ref=t3-/);
235 expect(tree).not.toMatch(/PAYLOAD|tail|charset|\u2028/);
236 expect(tree).toContain('/url: "\\"data:text/plain,relative"');
237 });
238
239 it("redacts a data: link whose scheme a password value would mask", async () => {
240 await page.setContent(`
241 <input type="password" aria-label="Scheme" value="data">
242 <a download href="data:text/plain,PAYLOAD">Key</a>`);
243 const tree = String((await takeSnapshot()).accessibilityTree);
244 expect(tree).toContain("/url: ••••••••:text/plain,…");
245 expect(tree).not.toContain("PAYLOAD");
246 });
247
248 it("shows a data: page's own URL by media type only", async () => {
249 await page.goto("data:text/html,<title>Key</title>PAYLOAD");
250 expect((await takeSnapshot()).url).toBe("data:text/html,…");
251 });
252
253 it("rejects refs from another tab", async () => {
254 await page.setContent("<button>same label</button>");
255 const locator = buttonLocator((await takeSnapshot()).accessibilityTree, "same label");
256 const other = await context.newPage();
257 await other.setContent("<button>same label</button>");
258 await expect(ServerBrowserPage.click(other, { locator })).rejects.toThrow(/another tab/);
259 });
260
261 it("revokes refs after navigation even when labels are identical", async () => {
262 await page.goto("data:text/html,<button>continue</button>");
263 const locator = buttonLocator((await takeSnapshot()).accessibilityTree, "continue");
264 await page.goto("data:text/html,<button>continue</button><p>new document</p>");
265 await expect(ServerBrowserPage.click(page, { locator })).rejects.toThrow(/stale/);
266 });
267
268 it.each(["aria-ref=e1", " aria-ref=e1", "css=body >> aria-ref=e1"])(
269 "does not allow native refs to bypass generation validation (%s)",
270 async (locator) => {
271 await page.setContent("<button>continue</button>");
272 await takeSnapshot();
273 await expect(ServerBrowserPage.click(page, { locator })).rejects.toThrow(/stale/);
274 },
275 );
276
277 it("preserves quoted attribute values containing ref engine text", async () => {
278 await page.setContent(
279 '<button data-example=" >> aria-ref=e1" onclick="this.textContent=\'saved\'">save</button>',
280 );
281 await ServerBrowserPage.click(page, { selector: 'button[data-example=" >> aria-ref=e1"]' });
282 expect(await page.locator("button").textContent()).toBe("saved");
283 });
284
285 it("evaluates top-level await and returns the last expression's value", async () => {
286 await page.setContent("<title>Ready</title>");
287 const result = await ServerBrowserPage.evaluate(
288 cdp,
289 { expression: "await Promise.resolve(); document.title" },
290 5_000,
291 );
292 expect(result).toBe("Ready");
293 });
294
295 it("returns object contents even when a legacy caller asks for a remote reference", async () => {
296 const input = decodeEvaluateInput({
297 expression: "({ answer: 42, nested: { ready: true } })",
298 returnByValue: false,
299 });
300 const result = await ServerBrowserPage.evaluate(cdp, input, 5_000);
301 expect(result).toEqual({ answer: 42, nested: { ready: true } });
302 });
303
304 it("still awaits the promise an async function returns", async () => {
305 const result = await ServerBrowserPage.evaluate(
306 cdp,
307 { expression: "(async () => { await 0; return 1 })()" },
308 5_000,
309 );
310 expect(result).toBe(1);
311 });
312
313 it("does not rerun an expression whose SyntaxError is thrown at runtime", async () => {
314 const evaluation = ServerBrowserPage.evaluate(
315 cdp,
316 { expression: "window.runs = (window.runs ?? 0) + 1; new Function('await 0')" },
317 5_000,
318 );
319 await expect(evaluation).rejects.toThrow("await is only valid");
320 expect(await page.evaluate("window.runs")).toBe(1);
321 });
322
323 it("does not rerun an expression whose awaited browser call rejects with a SyntaxError", async () => {
324 let posts = 0;
325 await page.route("http://preview.test/**", (route) => {
326 if (route.request().method() === "POST") posts++;
327 return route.fulfill({ contentType: "text/html", body: "<title>Ready</title>" });
328 });
329 await page.goto("http://preview.test/");
330 const evaluation = ServerBrowserPage.evaluate(
331 cdp,
332 {
333 expression:
334 "(async () => { const r = await fetch('/api', { method: 'POST' }); return r.json() })()",
335 },
336 5_000,
337 );
338 await expect(evaluation).rejects.toThrow("is not valid JSON");
339 expect(posts).toBe(1);
340 });
341
342 it("returns the result of a top-level await expression that reloads the page", async () => {
343 await page.route("http://preview.test/", (route) =>
344 route.fulfill({ contentType: "text/html", body: "<title>Ready</title>" }),
345 );
346 await page.goto("http://preview.test/");
347 const result = await ServerBrowserPage.evaluate(
348 cdp,
349 { expression: "await 0; location.reload(); ({ clicked: true })" },
350 5_000,
351 );
352 expect(result).toEqual({ clicked: true });
353 });
354});
355
356describe("server browser snapshot screenshot", () => {
357 let browser: Browser;
358 let context: BrowserContext;
359
360 beforeAll(async () => {
361 // ServerBrowserContexts launches with these, and the capture scale depends on them.
362 browser = await chromium.launch({
363 headless: true,
364 args: ["--disable-gpu", "--force-device-scale-factor=2"],
365 });
366 });
367 afterAll(async () => {
368 await browser?.close();
369 });
370 beforeEach(async () => {
371 context = await browser.newContext({
372 viewport: { width: 1280, height: 800 },
373 deviceScaleFactor: 2,
374 });
375 });
376 afterEach(async () => {
377 await context.close();
378 });
379
380 // Blue on the left half and red on the right, so a mirrored left half shows up on the right.
381 const halves = (overlay: string) => `
382 <style>
383 body { margin: 0; background: white; }
384 .half { position: absolute; top: 0; width: 640px; height: 800px; }
385 .overlay { position: fixed; inset: 0; ${overlay} }
386 </style>
387 <div class="half" style="left: 0; background: #2563eb"></div>
388 <div class="half" style="left: 640px; background: #ef4444"></div>
389 <div class="overlay"></div>`;
390
391 const screenshotOf = async (html: string) => {
392 const page = await context.newPage();
393 await page.setContent(html);
394 const { screenshot, fullScreenshot } = await ServerBrowserPage.snapshot({
395 page,
396 cdp: await context.newCDPSession(page),
397 renderScale: 2,
398 fullScreenshot: true,
399 consoleEntries: [],
400 networkEntries: [],
401 actionTimeline: [],
402 });
403 // The server has no DOM types, so the decoder runs as page source.
404 const points = [
405 [0.15, 0.75],
406 [0.85, 0.25],
407 [0.85, 0.75],
408 ];
409 const pixels = (await page.evaluate(`(async () => {
410 const bytes = Uint8Array.from(atob(${JSON.stringify(screenshot.data)}), (char) => char.charCodeAt(0));
411 const bitmap = await createImageBitmap(new Blob([bytes], { type: "image/png" }));
412 const canvas = document.createElement("canvas");
413 canvas.width = bitmap.width;
414 canvas.height = bitmap.height;
415 const context = canvas.getContext("2d");
416 context.drawImage(bitmap, 0, 0);
417 return ${JSON.stringify(points)}.map(([x, y]) =>
418 Array.from(context.getImageData(x * bitmap.width, y * bitmap.height, 1, 1).data),
419 );
420 })()`)) as Array<[number, number, number, number]>;
421 return { screenshot, fullScreenshot, pixels };
422 };
423 const colorOf = ([red, green, blue]: readonly [number, number, number, number]) =>
424 blue - red > 100 ? "blue" : red - blue > 100 ? "red" : `rgb(${red}, ${green}, ${blue})`;
425
426 it("captures a blurred backdrop-filter page as rendered, not mirrored", async () => {
427 const { screenshot, pixels } = await screenshotOf(halves("backdrop-filter: blur(4px);"));
428
429 expect({
430 size: [screenshot.width, screenshot.height],
431 colors: pixels.map(colorOf),
432 }).toEqual({ size: [1280, 800], colors: ["blue", "red", "red"] });
433 });
434
435 it("captures a plain page at the shrunk size with its content in place", async () => {
436 const { screenshot, fullScreenshot, pixels } = await screenshotOf(halves(""));
437
438 expect({
439 size: [screenshot.width, screenshot.height],
440 fullSize: [fullScreenshot?.width, fullScreenshot?.height],
441 colors: pixels.map(colorOf),
442 }).toEqual({ size: [1280, 800], fullSize: [2560, 1600], colors: ["blue", "red", "red"] });
443 });
444
445 it("records the destination of a finite entrance animation without waiting on infinite ones", async () => {
446 const page = await context.newPage();
447 await page.setContent(`
448 <style>
449 body { margin: 0; background: #2563eb; }
450 @keyframes enter { from { opacity: 0; } to { opacity: 1; } }
451 @keyframes pulse { from { opacity: 0.5; } to { opacity: 1; } }
452 button { animation: pulse 2s infinite; }
453 #paused { animation: enter 2s paused; }
454 #overlay { display: none; position: fixed; inset: 0; background: #ef4444; }
455 #overlay.open { display: block; animation: enter 200ms both; }
456 </style>
457 <button onclick="document.querySelector('#overlay').classList.add('open')">Open</button>
458 <div id="paused"></div>
459 <div id="overlay"></div>
460 `);
461 await page.getByRole("button", { name: "Open" }).click();
462 const frame = await ServerBrowserPage.captureFinalRecordingFrame(
463 await context.newCDPSession(page),
464 80,
465 );
466 expect(frame).toBeDefined();
467 const pixel = (await page.evaluate(`(async () => {
468 const bytes = Uint8Array.from(atob(${JSON.stringify(frame)}), char => char.charCodeAt(0));
469 const bitmap = await createImageBitmap(new Blob([bytes], { type: "image/jpeg" }));
470 const canvas = document.createElement("canvas");
471 canvas.width = bitmap.width;
472 canvas.height = bitmap.height;
473 const context = canvas.getContext("2d");
474 context.drawImage(bitmap, 0, 0);
475 return Array.from(context.getImageData(bitmap.width / 2, bitmap.height / 2, 1, 1).data);
476 })()`)) as [number, number, number, number];
477 expect(colorOf(pixel)).toBe("red");
478 });
479
480 it("shrinks the screenshot of an XML document, whose createElement makes no canvas", async () => {
481 const page = await context.newPage();
482 await page.goto("data:text/xml,<a/>");
483 const { screenshot } = await ServerBrowserPage.snapshot({
484 page,
485 cdp: await context.newCDPSession(page),
486 renderScale: 2,
487 consoleEntries: [],
488 networkEntries: [],
489 actionTimeline: [],
490 });
491
492 expect([screenshot.width, screenshot.height]).toEqual([1280, 800]);
493 });
494});
495
496describe("server browser drag", () => {
497 it("fails the drag, not the server, when it times out while the cursor is still moving", async () => {
498 const timedOut = new Error("locator.dragTo: Timeout 30000ms exceeded.");
499 const box = { x: 0, y: 0, width: 20, height: 20 };
500 const targetBox = Promise.withResolvers<typeof box>();
501 const page = {
502 locator: (selector: string) =>
503 selector === "#card"
504 ? {
505 scrollIntoViewIfNeeded: async () => {},
506 boundingBox: async () => box,
507 dragTo: () => Promise.reject(timedOut),
508 }
509 : { boundingBox: () => targetBox.promise },
510 } as unknown as Page;
511 const unobserved: Array<unknown> = [];
512 const onUnhandled = (reason: unknown) => unobserved.push(reason);
513 process.on("unhandledRejection", onUnhandled);
514 try {
515 let finished = false;
516 const settled = ServerBrowserPage.drag(page, { source: "#card", target: "#lane" }).then(
517 () => null,
518 (error: unknown) => error,
519 );
520 void settled.then(() => (finished = true));
521 // Two macrotask turns: Node reports a rejection nobody observed after the first.
522 for (let turn = 0; turn < 2; turn++) {
523 // oxlint-disable-next-line t3code/no-real-time-wait-in-tests -- Node emits unhandledRejection only between macrotasks; no promise can mark that point.
524 await new Promise((resolve) => setImmediate(resolve));
525 }
526 expect(finished).toBe(false);
527 targetBox.resolve(box);
528
529 expect(await settled).toBe(timedOut);
530 expect(unobserved).toEqual([]);
531 } finally {
532 process.off("unhandledRejection", onUnhandled);
533 }
534 });
535});
536
537describe("server browser evaluate", () => {
538 it("does not retry a parse error that arrives after the timeout", async () => {
539 vi.useFakeTimers();
540 try {
541 const classic = Promise.withResolvers<unknown>();
542 const send = vi.fn((method: string) =>
543 method === "Runtime.evaluate" ? classic.promise : Promise.resolve({}),
544 );
545 const cdp = { send } as unknown as CDPSession;
546 const evaluation = ServerBrowserPage.evaluate(cdp, { expression: "await 0; 1" }, 10);
547 const rejected = expect(evaluation).rejects.toMatchObject({
548 tag: "PreviewAutomationTimeoutError",
549 });
550 await vi.advanceTimersByTimeAsync(10);
551 await rejected;
552 classic.resolve({
553 result: { type: "object" },
554 exceptionDetails: {
555 text: "Uncaught",
556 scriptId: "4",
557 exception: { type: "object", className: "SyntaxError" },
558 },
559 });
560 await classic.promise;
561 expect(send.mock.calls.map(([method]) => method)).toEqual([
562 "Runtime.evaluate",
563 "Runtime.terminateExecution",
564 ]);
565 } finally {
566 vi.useRealTimers();
567 }
568 });
569});
570
571describe("server browser wait", () => {
572 it("ends at its timeout when a check never answers", async () => {
573 // As on a desktop tab whose Playwright utility world never answers.
574 const page = {
575 locator: () => ({ count: () => new Promise<number>(() => {}) }),
576 } as unknown as Page;
577 vi.useFakeTimers();
578 try {
579 let failure: unknown;
580 void ServerBrowserPage.waitFor(page, { selector: "button", timeoutMs: 300 }).catch(
581 (error: unknown) => (failure = error),
582 );
583 await vi.advanceTimersByTimeAsync(300);
584 expect(failure).toMatchObject({ tag: "PreviewAutomationTimeoutError" });
585 } finally {
586 vi.useRealTimers();
587 }
588 });
589});
590
591describe("server browser net errors", () => {
592 it.each([
593 ["net::ERR_CONNECTION_REFUSED", "ERR_CONNECTION_REFUSED", -102],
594 [
595 "page.goto: net::ERR_HTTP2_PROTOCOL_ERROR at https://localhost:5173/",
596 "ERR_HTTP2_PROTOCOL_ERROR",
597 -2,
598 ],
599 ["net::ERR_TLS13_DOWNGRADE_DETECTED", "ERR_TLS13_DOWNGRADE_DETECTED", -2],
600 ])("reads the whole error name from %j", (errorText, description, code) => {
601 expect(ServerBrowserPage.parseNetError(errorText)).toEqual({ description, code });
602 });
603});