Skip to content

Commit fe24c7b

Browse files
committed
test: use the same browser instance across tests
1 parent 54d18d8 commit fe24c7b

1 file changed

Lines changed: 14 additions & 21 deletions

File tree

tests/test_utils.tsx

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ import { NodeProcess } from "./fixtures_islands/NodeProcess.tsx";
2828
import { FreshAttrs } from "./fixtures_islands/FreshAttrs.tsx";
2929
import { OptOutPartialLink } from "./fixtures_islands/OptOutPartialLink.tsx";
3030

31+
const browser = await launch({
32+
args: [
33+
"--window-size=1280,7201",
34+
...((Deno.env.get("CI") && Deno.build.os === "linux")
35+
? ["--no-sandbox"]
36+
: []),
37+
],
38+
headless: true,
39+
});
40+
41+
addEventListener("unload", async () => {
42+
await browser.close();
43+
});
44+
3145
export function getIsland(pathname: string) {
3246
return path.join(
3347
import.meta.dirname!,
@@ -85,37 +99,17 @@ export async function withBrowserApp(
8599
signal: aborter.signal,
86100
}, await app.handler());
87101

88-
const browser = await launch({
89-
args: [
90-
"--window-size=1280,720",
91-
...((Deno.env.get("CI") && Deno.build.os === "linux")
92-
? ["--no-sandbox"]
93-
: []),
94-
],
95-
headless: true,
96-
});
97-
98102
const page = await browser.newPage();
99103
try {
100104
await fn(page, `http://localhost:${server.addr.port}`);
101105
} finally {
102106
await page.close();
103-
await browser.close();
104107
aborter.abort();
105108
await server?.finished;
106109
}
107110
}
108111

109112
export async function withBrowser(fn: (page: Page) => void | Promise<void>) {
110-
const browser = await launch({
111-
args: [
112-
"--window-size=1280,7201",
113-
...((Deno.env.get("CI") && Deno.build.os === "linux")
114-
? ["--no-sandbox"]
115-
: []),
116-
],
117-
headless: true,
118-
});
119113
const page = await browser.newPage();
120114
try {
121115
await fn(page);
@@ -128,7 +122,6 @@ export async function withBrowser(fn: (page: Page) => void | Promise<void>) {
128122
throw err;
129123
} finally {
130124
await page.close();
131-
await browser.close();
132125
}
133126
}
134127

0 commit comments

Comments
 (0)