返回 DeepSeek-Reasonix
transcript-retry.test.mjs
根目录 / desktop / frontend / bench / transcript-retry.test.mjs
1 import assert from "node:assert/strict";
2 import { test } from "node:test";
3 import { launchTranscriptRetryHost } from "./transcript-retry.mjs";
4
5 function fakeEngine(events) {
6 return {
7 async launch(options) {
8 events.push(["launch", options]);
9 return {
10 async newContext(contextOptions) {
11 events.push(["newContext", contextOptions]);
12 return {
13 async newPage() {
14 events.push(["newPage"]);
15 return { id: events.length };
16 },
17 async close() {
18 events.push(["closeContext"]);
19 },
20 };
21 },
22 async close() {
23 events.push(["closeBrowser"]);
24 },
25 };
26 },
27 };
28 }
29
30 test("bounded retries own an independent browser and release each context", async () => {
31 const events = [];
32 const host = await launchTranscriptRetryHost(fakeEngine(events), {
33 headless: true,
34 viewport: { width: 1280, height: 900 },
35 });
36 assert.equal(await host.run(async page => page.id), 3);
37 await assert.rejects(() => host.run(async () => { throw new Error("sample failed"); }), /sample failed/);
38 await host.close();
39 await host.close();
40 assert.deepEqual(events, [
41 ["launch", { headless: true }],
42 ["newContext", { viewport: { width: 1280, height: 900 } }],
43 ["newPage"],
44 ["closeContext"],
45 ["newContext", { viewport: { width: 1280, height: 900 } }],
46 ["newPage"],
47 ["closeContext"],
48 ["closeBrowser"],
49 ]);
50 await assert.rejects(() => host.run(async () => undefined), /host is closed/);
51 });
52
52 lines Plain Text