feat(server): pick free port if none specified (#1274)

This commit is contained in:
Marvin Hagemeister
2023-06-12 13:18:52 +02:00
committed by GitHub
parent 69f4fecf5a
commit 36d56a9878
10 changed files with 107 additions and 61 deletions
+12 -13
View File
@@ -606,7 +606,7 @@ Deno.test("experimental Deno.serve", {
ignore: Deno.build.os === "windows", // TODO: Deno.serve hang on Windows?
}, async (t) => {
// Preparation
const { serverProcess, lines } = await startFreshServer({
const { serverProcess, lines, address } = await startFreshServer({
args: [
"run",
"-A",
@@ -619,7 +619,7 @@ Deno.test("experimental Deno.serve", {
await delay(100);
await t.step("ssr", async () => {
const resp = await fetch("http://localhost:8000");
const resp = await fetch(address);
assert(resp);
assertEquals(resp.status, Status.OK);
assertEquals(resp.headers.get("content-type"), "text/html; charset=utf-8");
@@ -637,7 +637,7 @@ Deno.test("experimental Deno.serve", {
});
await t.step("static file", async () => {
const resp = await fetch("http://localhost:8000/foo.txt");
const resp = await fetch(`${address}/foo.txt`);
assertEquals(resp.status, Status.OK);
const body = await resp.text();
assert(body.startsWith("bar"));
@@ -658,14 +658,14 @@ Deno.test("jsx pragma works", {
sanitizeResources: false,
}, async (t) => {
// Preparation
const { serverProcess, lines } = await startFreshServer({
const { serverProcess, lines, address } = await startFreshServer({
args: ["run", "-A", "./tests/fixture_jsx_pragma/main.ts"],
});
await delay(100);
await t.step("ssr", async () => {
const resp = await fetch("http://localhost:8000");
const resp = await fetch(address);
assertEquals(resp.status, Status.OK);
const text = await resp.text();
assertStringIncludes(text, "Hello World");
@@ -675,7 +675,7 @@ Deno.test("jsx pragma works", {
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
const page = await browser.newPage();
await page.goto("http://localhost:8000", {
await page.goto(address, {
waitUntil: "networkidle2",
});
@@ -694,15 +694,14 @@ Deno.test("preact/debug is active in dev mode", {
sanitizeResources: false,
}, async (t) => {
// Preparation
const { serverProcess, lines } = await startFreshServer({
const { serverProcess, lines, address } = await startFreshServer({
args: ["run", "-A", "./tests/fixture_render_error/main.ts"],
});
await delay(100);
const url = "http://localhost:8000";
await t.step("SSR error is shown", async () => {
const resp = await fetch(url);
const resp = await fetch(address);
assertEquals(resp.status, Status.InternalServerError);
const text = await resp.text();
assertStringIncludes(text, "Objects are not valid as a child");
@@ -711,7 +710,7 @@ Deno.test("preact/debug is active in dev mode", {
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
const page = await browser.newPage();
await page.goto(url, {
await page.goto(address, {
waitUntil: "networkidle2",
});
@@ -732,7 +731,7 @@ Deno.test("preloading javascript files", {
sanitizeResources: false,
}, async () => {
// Preparation
const { serverProcess, lines } = await startFreshServer({
const { serverProcess, lines, address } = await startFreshServer({
args: ["run", "-A", "./tests/fixture/main.ts"],
});
@@ -741,13 +740,13 @@ Deno.test("preloading javascript files", {
try {
// request js file to start esbuild execution
await page.goto("http://localhost:8000", {
await page.goto(address, {
waitUntil: "networkidle2",
});
await delay(5000); // wait running esbuild
await page.goto("http://localhost:8000", {
await page.goto(address, {
waitUntil: "networkidle2",
});