Skip to content

Commit a1d2429

Browse files
committed
tweaks
1 parent 3c7da8f commit a1d2429

2 files changed

Lines changed: 113 additions & 43 deletions

File tree

deno.lock

Lines changed: 87 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/test_utils.tsx

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -79,36 +79,28 @@ export async function withBrowserApp(
7979
fn: (page: Page, address: string) => void | Promise<void>,
8080
) {
8181
const aborter = new AbortController();
82-
let server: Deno.HttpServer | null = null;
83-
let port = 0;
82+
const server = Deno.serve({
83+
hostname: "localhost",
84+
port: 0,
85+
signal: aborter.signal,
86+
}, await app.handler());
87+
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+
98+
const page = await browser.newPage();
8499
try {
85-
server = await Deno.serve({
86-
hostname: "localhost",
87-
port: 0,
88-
signal: aborter.signal,
89-
onListen: ({ port: p }) => {
90-
port = p;
91-
},
92-
}, await app.handler());
93-
94-
const browser = await launch({
95-
args: [
96-
"--window-size=1280,720",
97-
...((Deno.env.get("CI") && Deno.build.os === "linux")
98-
? ["--no-sandbox"]
99-
: []),
100-
],
101-
headless: !Deno.args.includes("--headful"),
102-
});
103-
104-
const page = await browser.newPage();
105-
try {
106-
await fn(page, `http://localhost:${port}`);
107-
} finally {
108-
await page.close();
109-
await browser.close();
110-
}
100+
await fn(page, `http://localhost:${server.addr.port}`);
111101
} finally {
102+
await page.close();
103+
await browser.close();
112104
aborter.abort();
113105
await server?.finished;
114106
}
@@ -122,22 +114,17 @@ export async function withBrowser(fn: (page: Page) => void | Promise<void>) {
122114
? ["--no-sandbox"]
123115
: []),
124116
],
125-
headless: !Deno.args.includes("--headful"),
117+
headless: true,
126118
});
127119
const page = await browser.newPage();
128-
// page.setDefaultTimeout(1000000);
129120
try {
130121
await fn(page);
131122
} catch (err) {
132-
try {
133-
const raw = await page.content();
134-
const doc = parseHtml(raw);
135-
const html = prettyDom(doc);
136-
// deno-lint-ignore no-console
137-
console.log(html);
138-
} catch {
139-
// Ignore
140-
}
123+
const raw = await page.content();
124+
const doc = parseHtml(raw);
125+
const html = prettyDom(doc);
126+
// deno-lint-ignore no-console
127+
console.log(html);
141128
throw err;
142129
} finally {
143130
await page.close();

0 commit comments

Comments
 (0)