chore(tests): use to spin up server (#1261)
This commit is contained in:
+3
-27
@@ -5,8 +5,8 @@ import {
|
||||
delay,
|
||||
Page,
|
||||
puppeteer,
|
||||
TextLineStream,
|
||||
} from "./deps.ts";
|
||||
import { startFreshServer } from "./test_utils.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "island tests",
|
||||
@@ -64,24 +64,11 @@ function withPage(fn: (page: Page) => Promise<void>) {
|
||||
}
|
||||
|
||||
async function withPageName(name: string, fn: (page: Page) => Promise<void>) {
|
||||
const serverProcess = new Deno.Command(Deno.execPath(), {
|
||||
const { lines, serverProcess } = await startFreshServer({
|
||||
args: ["run", "-A", name],
|
||||
stdout: "piped",
|
||||
stderr: "inherit",
|
||||
}).spawn();
|
||||
|
||||
const textDecoderStream = new TextDecoderStream();
|
||||
const textLineStream = new TextLineStream();
|
||||
|
||||
const lines = serverProcess.stdout
|
||||
.pipeThrough(textDecoderStream)
|
||||
.pipeThrough(textLineStream);
|
||||
});
|
||||
|
||||
try {
|
||||
if (!await didServerStart(lines)) {
|
||||
throw new Error("Server didn't start up");
|
||||
}
|
||||
|
||||
await delay(100);
|
||||
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
|
||||
|
||||
@@ -101,17 +88,6 @@ async function withPageName(name: string, fn: (page: Page) => Promise<void>) {
|
||||
}
|
||||
}
|
||||
|
||||
async function didServerStart(
|
||||
stdoutLines: ReadableStream<string>,
|
||||
): Promise<boolean> {
|
||||
for await (const line of stdoutLines) {
|
||||
if (line.includes("Listening on http://")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Deno.test({
|
||||
name: "island tests with </script>",
|
||||
|
||||
|
||||
@@ -1,30 +1,14 @@
|
||||
import { assert, delay, puppeteer, TextLineStream } from "./deps.ts";
|
||||
import { assert, delay, puppeteer } from "./deps.ts";
|
||||
import { startFreshServer } from "./test_utils.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "wasm island tests",
|
||||
ignore: Deno.build.os === "windows",
|
||||
async fn(t) {
|
||||
// Preparation
|
||||
const serverProcess = new Deno.Command(Deno.execPath(), {
|
||||
const { lines, serverProcess } = await startFreshServer({
|
||||
args: ["run", "-A", "./tests/fixture/main_wasm.ts"],
|
||||
stdout: "piped",
|
||||
}).spawn();
|
||||
|
||||
const decoder = new TextDecoderStream();
|
||||
const lines = serverProcess.stdout
|
||||
.pipeThrough(decoder)
|
||||
.pipeThrough(new TextLineStream());
|
||||
|
||||
let started = false;
|
||||
for await (const line of lines) {
|
||||
if (line.includes("Listening on http://")) {
|
||||
started = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!started) {
|
||||
throw new Error("Server didn't start up");
|
||||
}
|
||||
});
|
||||
|
||||
await delay(100);
|
||||
|
||||
|
||||
+3
-21
@@ -5,10 +5,10 @@ import {
|
||||
assertStringIncludes,
|
||||
delay,
|
||||
puppeteer,
|
||||
TextLineStream,
|
||||
} from "./deps.ts";
|
||||
import manifest from "./fixture_plugin/fresh.gen.ts";
|
||||
import options from "./fixture_plugin/options.ts";
|
||||
import { startFreshServer } from "./test_utils.ts";
|
||||
|
||||
const ctx = await ServerContext.fromManifest(manifest, options);
|
||||
const handler = ctx.handler();
|
||||
@@ -62,27 +62,9 @@ Deno.test({
|
||||
name: "/with-island hydration",
|
||||
async fn(t) {
|
||||
// Preparation
|
||||
const serverProcess = new Deno.Command(Deno.execPath(), {
|
||||
const { lines, serverProcess } = await startFreshServer({
|
||||
args: ["run", "-A", "./tests/fixture_plugin/main.ts"],
|
||||
stdout: "piped",
|
||||
stderr: "inherit",
|
||||
}).spawn();
|
||||
|
||||
const decoder = new TextDecoderStream();
|
||||
const lines = serverProcess.stdout
|
||||
.pipeThrough(decoder)
|
||||
.pipeThrough(new TextLineStream());
|
||||
|
||||
let started = false;
|
||||
for await (const line of lines) {
|
||||
if (line.includes("Listening on http://")) {
|
||||
started = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!started) {
|
||||
throw new Error("Server didn't start up");
|
||||
}
|
||||
});
|
||||
|
||||
await delay(100);
|
||||
|
||||
|
||||
+5
-27
@@ -1,6 +1,7 @@
|
||||
import { assert, delay, puppeteer, TextLineStream } from "./deps.ts";
|
||||
import { assert, delay, puppeteer } from "./deps.ts";
|
||||
|
||||
import { cmpStringArray } from "./fixture_twind_hydrate/utils/utils.ts";
|
||||
import { startFreshServer } from "./test_utils.ts";
|
||||
|
||||
/**
|
||||
* Start the server with the main file.
|
||||
@@ -8,34 +9,10 @@ import { cmpStringArray } from "./fixture_twind_hydrate/utils/utils.ts";
|
||||
* Returns a page instance and a method to terminate the server.
|
||||
*/
|
||||
async function setUpServer(path: string) {
|
||||
const serverProcessCmd = new Deno.Command("deno", {
|
||||
args: [
|
||||
"run",
|
||||
"-A",
|
||||
path,
|
||||
],
|
||||
stdout: "piped",
|
||||
stderr: "inherit",
|
||||
const { lines, serverProcess } = await startFreshServer({
|
||||
args: ["run", "-A", path],
|
||||
});
|
||||
|
||||
const serverProcess = serverProcessCmd.spawn();
|
||||
|
||||
const lines = serverProcess.stdout
|
||||
.pipeThrough(new TextDecoderStream())
|
||||
.pipeThrough(new TextLineStream());
|
||||
|
||||
let started = false;
|
||||
|
||||
for await (const line of lines) {
|
||||
if (line.includes("Listening on http://")) {
|
||||
started = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!started) {
|
||||
throw new Error("Server didn't start up");
|
||||
}
|
||||
|
||||
await delay(100);
|
||||
|
||||
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
|
||||
@@ -45,6 +22,7 @@ async function setUpServer(path: string) {
|
||||
* terminate server
|
||||
*/
|
||||
const terminate = async () => {
|
||||
await lines.cancel();
|
||||
await browser.close();
|
||||
|
||||
serverProcess.kill("SIGKILL");
|
||||
|
||||
+3
-22
@@ -1,32 +1,13 @@
|
||||
import { assertEquals } from "$std/testing/asserts.ts";
|
||||
import { TextLineStream } from "$std/streams/text_line_stream.ts";
|
||||
import { delay } from "$std/async/delay.ts";
|
||||
import { startFreshServer } from "../tests/test_utils.ts";
|
||||
|
||||
Deno.test("CORS should not set on GET /fresh-badge.svg", {
|
||||
sanitizeResources: false,
|
||||
}, async () => {
|
||||
const serverProcess = new Deno.Command(Deno.execPath(), {
|
||||
const { serverProcess, lines } = await startFreshServer({
|
||||
args: ["run", "-A", "./main.ts"],
|
||||
stdin: "null",
|
||||
stdout: "piped",
|
||||
stderr: "inherit",
|
||||
}).spawn();
|
||||
|
||||
const decoder = new TextDecoderStream();
|
||||
const lines = serverProcess.stdout
|
||||
.pipeThrough(decoder)
|
||||
.pipeThrough(new TextLineStream());
|
||||
|
||||
let started = false;
|
||||
for await (const line of lines) {
|
||||
if (line.includes("Listening on http://")) {
|
||||
started = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!started) {
|
||||
throw new Error("Server didn't start up");
|
||||
}
|
||||
});
|
||||
|
||||
const res = await fetch("http://localhost:8000/fresh-badge.svg");
|
||||
await res.body?.cancel();
|
||||
|
||||
Reference in New Issue
Block a user