summaryrefslogtreecommitdiff
path: root/std/examples/chat/server_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/examples/chat/server_test.ts')
-rw-r--r--std/examples/chat/server_test.ts15
1 files changed, 12 insertions, 3 deletions
diff --git a/std/examples/chat/server_test.ts b/std/examples/chat/server_test.ts
index 0d21b3787..65e0b5958 100644
--- a/std/examples/chat/server_test.ts
+++ b/std/examples/chat/server_test.ts
@@ -3,13 +3,22 @@ import { assert, assertEquals } from "../../testing/asserts.ts";
import { TextProtoReader } from "../../textproto/mod.ts";
import { BufReader } from "../../io/bufio.ts";
import { connectWebSocket, WebSocket } from "../../ws/mod.ts";
+import { randomPort } from "../../http/test_util.ts";
import { delay } from "../../util/async.ts";
+const port = randomPort();
+
const { test, build } = Deno;
async function startServer(): Promise<Deno.Process> {
const server = Deno.run({
- args: [Deno.execPath(), "--allow-net", "--allow-read", "server.ts"],
+ args: [
+ Deno.execPath(),
+ "--allow-net",
+ "--allow-read",
+ "server.ts",
+ `127.0.0.1:${port}`
+ ],
cwd: "examples/chat",
stdout: "piped"
});
@@ -35,7 +44,7 @@ test({
async fn() {
const server = await startServer();
try {
- const resp = await fetch("http://127.0.0.1:8080/");
+ const resp = await fetch(`http://127.0.0.1:${port}/`);
assertEquals(resp.status, 200);
assertEquals(resp.headers.get("content-type"), "text/html");
const html = await resp.body.text();
@@ -55,7 +64,7 @@ test({
const server = await startServer();
let ws: WebSocket | undefined;
try {
- ws = await connectWebSocket("http://127.0.0.1:8080/ws");
+ ws = await connectWebSocket(`http://127.0.0.1:${port}/ws`);
const it = ws.receive();
assertEquals((await it.next()).value, "Connected: [1]");
ws.send("Hello");