chore: extract withPageName util (#1389)
This commit is contained in:
+1
-30
@@ -4,9 +4,8 @@ import {
|
|||||||
assertStringIncludes,
|
assertStringIncludes,
|
||||||
delay,
|
delay,
|
||||||
Page,
|
Page,
|
||||||
puppeteer,
|
|
||||||
} from "./deps.ts";
|
} from "./deps.ts";
|
||||||
import { startFreshServer } from "./test_utils.ts";
|
import { withPageName } from "./test_utils.ts";
|
||||||
|
|
||||||
Deno.test({
|
Deno.test({
|
||||||
name: "island tests",
|
name: "island tests",
|
||||||
@@ -63,34 +62,6 @@ function withPage(fn: (page: Page, address: string) => Promise<void>) {
|
|||||||
return withPageName("./tests/fixture/main.ts", fn);
|
return withPageName("./tests/fixture/main.ts", fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function withPageName(
|
|
||||||
name: string,
|
|
||||||
fn: (page: Page, address: string) => Promise<void>,
|
|
||||||
) {
|
|
||||||
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({
|
Deno.test({
|
||||||
name: "island tests with </script>",
|
name: "island tests with </script>",
|
||||||
|
|
||||||
|
|||||||
+29
-1
@@ -1,4 +1,4 @@
|
|||||||
import { TextLineStream } from "./deps.ts";
|
import { delay, Page, puppeteer, TextLineStream } from "./deps.ts";
|
||||||
|
|
||||||
export async function startFreshServer(options: Deno.CommandOptions) {
|
export async function startFreshServer(options: Deno.CommandOptions) {
|
||||||
const serverProcess = new Deno.Command(Deno.execPath(), {
|
const serverProcess = new Deno.Command(Deno.execPath(), {
|
||||||
@@ -29,3 +29,31 @@ export async function startFreshServer(options: Deno.CommandOptions) {
|
|||||||
|
|
||||||
return { serverProcess, lines, address };
|
return { serverProcess, lines, address };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function withPageName(
|
||||||
|
name: string,
|
||||||
|
fn: (page: Page, address: string) => Promise<void>,
|
||||||
|
) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user