diff --git a/tests/islands_test.ts b/tests/islands_test.ts index 3ca37f83..4e00387e 100644 --- a/tests/islands_test.ts +++ b/tests/islands_test.ts @@ -4,9 +4,8 @@ import { assertStringIncludes, delay, Page, - puppeteer, } from "./deps.ts"; -import { startFreshServer } from "./test_utils.ts"; +import { withPageName } from "./test_utils.ts"; Deno.test({ name: "island tests", @@ -63,34 +62,6 @@ function withPage(fn: (page: Page, address: string) => Promise) { return withPageName("./tests/fixture/main.ts", fn); } -async function withPageName( - name: string, - fn: (page: Page, address: string) => Promise, -) { - const { lines, serverProcess, address } = await startFreshServer({ - args: ["run", "-A", name], - }); - - try { - await delay(100); - const browser = await puppeteer.launch({ args: ["--no-sandbox"] }); - - try { - const page = await browser.newPage(); - await fn(page, address); - } finally { - await browser.close(); - } - } finally { - await lines.cancel(); - - serverProcess.kill("SIGTERM"); - - // Wait until the process exits - await serverProcess.status; - } -} - Deno.test({ name: "island tests with ", diff --git a/tests/test_utils.ts b/tests/test_utils.ts index 53ebac13..96b3c6f9 100644 --- a/tests/test_utils.ts +++ b/tests/test_utils.ts @@ -1,4 +1,4 @@ -import { TextLineStream } from "./deps.ts"; +import { delay, Page, puppeteer, TextLineStream } from "./deps.ts"; export async function startFreshServer(options: Deno.CommandOptions) { const serverProcess = new Deno.Command(Deno.execPath(), { @@ -29,3 +29,31 @@ export async function startFreshServer(options: Deno.CommandOptions) { return { serverProcess, lines, address }; } + +export async function withPageName( + name: string, + fn: (page: Page, address: string) => Promise, +) { + const { lines, serverProcess, address } = await startFreshServer({ + args: ["run", "-A", name], + }); + + try { + await delay(100); + const browser = await puppeteer.launch({ args: ["--no-sandbox"] }); + + try { + const page = await browser.newPage(); + await fn(page, address); + } finally { + await browser.close(); + } + } finally { + await lines.cancel(); + + serverProcess.kill("SIGTERM"); + + // Wait until the process exits + await serverProcess.status; + } +}