summaryrefslogtreecommitdiff
path: root/cli/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/unit')
-rw-r--r--cli/tests/unit/fetch_test.ts26
-rw-r--r--cli/tests/unit/net_test.ts100
-rw-r--r--cli/tests/unit/resources_test.ts6
-rw-r--r--cli/tests/unit/serve_test.ts166
-rw-r--r--cli/tests/unit/streams_deprecated.ts16
5 files changed, 154 insertions, 160 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts
index 08689a2a0..db553f14d 100644
--- a/cli/tests/unit/fetch_test.ts
+++ b/cli/tests/unit/fetch_test.ts
@@ -10,6 +10,8 @@ import {
} from "./test_util.ts";
import { Buffer } from "../../../test_util/std/io/buffer.ts";
+const listenPort = 4504;
+
Deno.test(
{ permissions: { net: true } },
async function fetchRequiresOneArgument() {
@@ -639,7 +641,7 @@ Deno.test(
permissions: { net: true },
},
async function fetchRequest() {
- const addr = "127.0.0.1:4501";
+ const addr = `127.0.0.1:${listenPort}`;
const bufPromise = bufferServer(addr);
const response = await fetch(`http://${addr}/blah`, {
method: "POST",
@@ -673,7 +675,7 @@ Deno.test(
permissions: { net: true },
},
async function fetchRequestAcceptHeaders() {
- const addr = "127.0.0.1:4501";
+ const addr = `127.0.0.1:${listenPort}`;
const bufPromise = bufferServer(addr);
const response = await fetch(`http://${addr}/blah`, {
method: "POST",
@@ -705,7 +707,7 @@ Deno.test(
permissions: { net: true },
},
async function fetchPostBodyString() {
- const addr = "127.0.0.1:4511";
+ const addr = `127.0.0.1:${listenPort}`;
const bufPromise = bufferServer(addr);
const body = "hello world";
const response = await fetch(`http://${addr}/blah`, {
@@ -743,7 +745,7 @@ Deno.test(
permissions: { net: true },
},
async function fetchPostBodyTypedArray() {
- const addr = "127.0.0.1:4503";
+ const addr = `127.0.0.1:${listenPort}`;
const bufPromise = bufferServer(addr);
const bodyStr = "hello world";
const body = new TextEncoder().encode(bodyStr);
@@ -781,7 +783,7 @@ Deno.test(
permissions: { net: true },
},
async function fetchUserSetContentLength() {
- const addr = "127.0.0.1:4501";
+ const addr = `127.0.0.1:${listenPort}`;
const bufPromise = bufferServer(addr);
const response = await fetch(`http://${addr}/blah`, {
method: "POST",
@@ -812,7 +814,7 @@ Deno.test(
permissions: { net: true },
},
async function fetchUserSetTransferEncoding() {
- const addr = "127.0.0.1:4501";
+ const addr = `127.0.0.1:${listenPort}`;
const bufPromise = bufferServer(addr);
const response = await fetch(`http://${addr}/blah`, {
method: "POST",
@@ -1158,7 +1160,7 @@ Deno.test(
permissions: { net: true },
},
async function fetchPostBodyReadableStream() {
- const addr = "127.0.0.1:4511";
+ const addr = `127.0.0.1:${listenPort}`;
const bufPromise = bufferServer(addr);
const stream = new TransformStream();
const writer = stream.writable.getWriter();
@@ -1217,7 +1219,7 @@ Deno.test(
async function fetchFilterOutCustomHostHeader(): Promise<
void
> {
- const addr = "127.0.0.1:4511";
+ const addr = `127.0.0.1:${listenPort}`;
const [hostname, port] = addr.split(":");
const listener = Deno.listen({
hostname,
@@ -1717,7 +1719,7 @@ Deno.test(
async function fetchWithInvalidContentLengthAndTransferEncoding(): Promise<
void
> {
- const addr = "127.0.0.1:4516";
+ const addr = `127.0.0.1:${listenPort}`;
const data = "a".repeat(10 << 10);
const body = new TextEncoder().encode(
@@ -1749,7 +1751,7 @@ Deno.test(
async function fetchWithInvalidContentLength(): Promise<
void
> {
- const addr = "127.0.0.1:4517";
+ const addr = `127.0.0.1:${listenPort}`;
const data = "a".repeat(10 << 10);
const body = new TextEncoder().encode(
@@ -1777,7 +1779,7 @@ Deno.test(
async function fetchWithInvalidContentLength(): Promise<
void
> {
- const addr = "127.0.0.1:4518";
+ const addr = `127.0.0.1:${listenPort}`;
const data = "a".repeat(10 << 10);
const contentLength = data.length / 2;
@@ -1804,7 +1806,7 @@ Deno.test(
async function fetchWithInvalidContentLength(): Promise<
void
> {
- const addr = "127.0.0.1:4519";
+ const addr = `127.0.0.1:${listenPort}`;
const data = "a".repeat(10 << 10);
const contentLength = data.length * 2;
diff --git a/cli/tests/unit/net_test.ts b/cli/tests/unit/net_test.ts
index 935a6f846..32250bbd0 100644
--- a/cli/tests/unit/net_test.ts
+++ b/cli/tests/unit/net_test.ts
@@ -12,6 +12,10 @@ import {
} from "./test_util.ts";
import { join } from "../../../test_util/std/path/mod.ts";
+// Since these tests may run in parallel, ensure this port is unique to this file
+const listenPort = 4503;
+const listenPort2 = 4504;
+
let isCI: boolean;
try {
isCI = Deno.env.get("CI") !== undefined;
@@ -20,10 +24,10 @@ try {
}
Deno.test({ permissions: { net: true } }, function netTcpListenClose() {
- const listener = Deno.listen({ hostname: "127.0.0.1", port: 3500 });
+ const listener = Deno.listen({ hostname: "127.0.0.1", port: listenPort });
assert(listener.addr.transport === "tcp");
assertEquals(listener.addr.hostname, "127.0.0.1");
- assertEquals(listener.addr.port, 3500);
+ assertEquals(listener.addr.port, listenPort);
assertNotEquals(listener.rid, 0);
listener.close();
});
@@ -35,12 +39,12 @@ Deno.test(
function netUdpListenClose() {
const socket = Deno.listenDatagram({
hostname: "127.0.0.1",
- port: 3500,
+ port: listenPort,
transport: "udp",
});
assert(socket.addr.transport === "udp");
assertEquals(socket.addr.hostname, "127.0.0.1");
- assertEquals(socket.addr.port, 3500);
+ assertEquals(socket.addr.port, listenPort);
socket.close();
},
);
@@ -127,7 +131,7 @@ Deno.test(
permissions: { net: true },
},
async function netTcpCloseWhileAccept() {
- const listener = Deno.listen({ port: 4501 });
+ const listener = Deno.listen({ port: listenPort });
const p = listener.accept();
listener.close();
// TODO(piscisaureus): the error type should be `Interrupted` here, which
@@ -212,22 +216,22 @@ Deno.test(
);
Deno.test({ permissions: { net: true } }, async function netTcpDialListen() {
- const listener = Deno.listen({ port: 3500 });
+ const listener = Deno.listen({ port: listenPort });
listener.accept().then(
async (conn) => {
assert(conn.remoteAddr != null);
assert(conn.localAddr.transport === "tcp");
assertEquals(conn.localAddr.hostname, "127.0.0.1");
- assertEquals(conn.localAddr.port, 3500);
+ assertEquals(conn.localAddr.port, listenPort);
await conn.write(new Uint8Array([1, 2, 3]));
conn.close();
},
);
- const conn = await Deno.connect({ hostname: "127.0.0.1", port: 3500 });
+ const conn = await Deno.connect({ hostname: "127.0.0.1", port: listenPort });
assert(conn.remoteAddr.transport === "tcp");
assertEquals(conn.remoteAddr.hostname, "127.0.0.1");
- assertEquals(conn.remoteAddr.port, 3500);
+ assertEquals(conn.remoteAddr.port, listenPort);
assert(conn.localAddr != null);
const buf = new Uint8Array(1024);
const readResult = await conn.read(buf);
@@ -247,23 +251,23 @@ Deno.test({ permissions: { net: true } }, async function netTcpDialListen() {
});
Deno.test({ permissions: { net: true } }, async function netTcpSetNoDelay() {
- const listener = Deno.listen({ port: 3500 });
+ const listener = Deno.listen({ port: listenPort });
listener.accept().then(
async (conn) => {
assert(conn.remoteAddr != null);
assert(conn.localAddr.transport === "tcp");
assertEquals(conn.localAddr.hostname, "127.0.0.1");
- assertEquals(conn.localAddr.port, 3500);
+ assertEquals(conn.localAddr.port, listenPort);
await conn.write(new Uint8Array([1, 2, 3]));
conn.close();
},
);
- const conn = await Deno.connect({ hostname: "127.0.0.1", port: 3500 });
+ const conn = await Deno.connect({ hostname: "127.0.0.1", port: listenPort });
conn.setNoDelay(true);
assert(conn.remoteAddr.transport === "tcp");
assertEquals(conn.remoteAddr.hostname, "127.0.0.1");
- assertEquals(conn.remoteAddr.port, 3500);
+ assertEquals(conn.remoteAddr.port, listenPort);
assert(conn.localAddr != null);
const buf = new Uint8Array(1024);
const readResult = await conn.read(buf);
@@ -283,23 +287,23 @@ Deno.test({ permissions: { net: true } }, async function netTcpSetNoDelay() {
});
Deno.test({ permissions: { net: true } }, async function netTcpSetKeepAlive() {
- const listener = Deno.listen({ port: 3500 });
+ const listener = Deno.listen({ port: listenPort });
listener.accept().then(
async (conn) => {
assert(conn.remoteAddr != null);
assert(conn.localAddr.transport === "tcp");
assertEquals(conn.localAddr.hostname, "127.0.0.1");
- assertEquals(conn.localAddr.port, 3500);
+ assertEquals(conn.localAddr.port, listenPort);
await conn.write(new Uint8Array([1, 2, 3]));
conn.close();
},
);
- const conn = await Deno.connect({ hostname: "127.0.0.1", port: 3500 });
+ const conn = await Deno.connect({ hostname: "127.0.0.1", port: listenPort });
conn.setKeepAlive(true);
assert(conn.remoteAddr.transport === "tcp");
assertEquals(conn.remoteAddr.hostname, "127.0.0.1");
- assertEquals(conn.remoteAddr.port, 3500);
+ assertEquals(conn.remoteAddr.port, listenPort);
assert(conn.localAddr != null);
const buf = new Uint8Array(1024);
const readResult = await conn.read(buf);
@@ -360,14 +364,14 @@ Deno.test(
Deno.test(
{ permissions: { net: true } },
async function netUdpSendReceive() {
- const alice = Deno.listenDatagram({ port: 3500, transport: "udp" });
+ const alice = Deno.listenDatagram({ port: listenPort, transport: "udp" });
assert(alice.addr.transport === "udp");
- assertEquals(alice.addr.port, 3500);
+ assertEquals(alice.addr.port, listenPort);
assertEquals(alice.addr.hostname, "127.0.0.1");
- const bob = Deno.listenDatagram({ port: 4501, transport: "udp" });
+ const bob = Deno.listenDatagram({ port: listenPort2, transport: "udp" });
assert(bob.addr.transport === "udp");
- assertEquals(bob.addr.port, 4501);
+ assertEquals(bob.addr.port, listenPort2);
assertEquals(bob.addr.hostname, "127.0.0.1");
const sent = new Uint8Array([1, 2, 3]);
@@ -377,7 +381,7 @@ Deno.test(
const [recvd, remote] = await bob.receive();
assert(remote.transport === "udp");
- assertEquals(remote.port, 3500);
+ assertEquals(remote.port, listenPort);
assertEquals(recvd.length, 3);
assertEquals(1, recvd[0]);
assertEquals(2, recvd[1]);
@@ -393,18 +397,18 @@ Deno.test(
// Must bind sender to an address that can send to the broadcast address on MacOS.
// Macos will give us error 49 when sending the broadcast packet if we omit hostname here.
const alice = Deno.listenDatagram({
- port: 3500,
+ port: listenPort,
transport: "udp",
hostname: "0.0.0.0",
});
const bob = Deno.listenDatagram({
- port: 4501,
+ port: listenPort,
transport: "udp",
hostname: "0.0.0.0",
});
assert(bob.addr.transport === "udp");
- assertEquals(bob.addr.port, 4501);
+ assertEquals(bob.addr.port, listenPort);
assertEquals(bob.addr.hostname, "0.0.0.0");
const broadcastAddr = { ...bob.addr, hostname: "255.255.255.255" };
@@ -415,7 +419,7 @@ Deno.test(
assertEquals(byteLength, 3);
const [recvd, remote] = await bob.receive();
assert(remote.transport === "udp");
- assertEquals(remote.port, 3500);
+ assertEquals(remote.port, listenPort);
assertEquals(recvd.length, 3);
assertEquals(1, recvd[0]);
assertEquals(2, recvd[1]);
@@ -563,9 +567,9 @@ Deno.test(
Deno.test(
{ permissions: { net: true } },
async function netUdpConcurrentSendReceive() {
- const socket = Deno.listenDatagram({ port: 3500, transport: "udp" });
+ const socket = Deno.listenDatagram({ port: listenPort, transport: "udp" });
assert(socket.addr.transport === "udp");
- assertEquals(socket.addr.port, 3500);
+ assertEquals(socket.addr.port, listenPort);
assertEquals(socket.addr.hostname, "127.0.0.1");
const recvPromise = socket.receive();
@@ -588,7 +592,7 @@ Deno.test(
{ permissions: { net: true } },
async function netUdpBorrowMutError() {
const socket = Deno.listenDatagram({
- port: 4501,
+ port: listenPort,
transport: "udp",
});
// Panic happened on second send: BorrowMutError
@@ -761,7 +765,7 @@ Deno.test(
Deno.test(
{ permissions: { net: true } },
async function netListenAsyncIterator() {
- const addr = { hostname: "127.0.0.1", port: 3500 };
+ const addr = { hostname: "127.0.0.1", port: listenPort };
const listener = Deno.listen(addr);
const runAsyncIterator = async () => {
for await (const conn of listener) {
@@ -794,7 +798,7 @@ Deno.test(
permissions: { net: true },
},
async function netCloseWriteSuccess() {
- const addr = { hostname: "127.0.0.1", port: 3500 };
+ const addr = { hostname: "127.0.0.1", port: listenPort };
const listener = Deno.listen(addr);
const closeDeferred = deferred();
listener.accept().then(async (conn) => {
@@ -850,7 +854,7 @@ Deno.test(
}
}
- const addr = { hostname: "127.0.0.1", port: 3500 };
+ const addr = { hostname: "127.0.0.1", port: listenPort };
const listener = Deno.listen(addr);
const listenerPromise = iteratorReq(listener);
const connectionPromise = (async () => {
@@ -898,13 +902,13 @@ Deno.test(
Deno.test({ permissions: { net: true } }, async function whatwgStreams() {
(async () => {
- const listener = Deno.listen({ hostname: "127.0.0.1", port: 3500 });
+ const listener = Deno.listen({ hostname: "127.0.0.1", port: listenPort });
const conn = await listener.accept();
await conn.readable.pipeTo(conn.writable);
listener.close();
})();
- const conn = await Deno.connect({ hostname: "127.0.0.1", port: 3500 });
+ const conn = await Deno.connect({ hostname: "127.0.0.1", port: listenPort });
const reader = conn.readable.getReader();
const writer = conn.writable.getWriter();
const encoder = new TextEncoder();
@@ -957,7 +961,7 @@ Deno.test(
async function netListenUnref() {
const [statusCode, _output] = await execCode(`
async function main() {
- const listener = Deno.listen({ port: 3500 });
+ const listener = Deno.listen({ port: ${listenPort} });
listener.unref();
await listener.accept(); // This doesn't block the program from exiting
}
@@ -972,14 +976,14 @@ Deno.test(
async function netListenUnref() {
const [statusCode, _output] = await execCode(`
async function main() {
- const listener = Deno.listen({ port: 3500 });
+ const listener = Deno.listen({ port: ${listenPort} });
await listener.accept();
listener.unref();
await listener.accept(); // The program exits here
throw new Error(); // The program doesn't reach here
}
main();
- const conn = await Deno.connect({ port: 3500 });
+ const conn = await Deno.connect({ port: ${listenPort} });
conn.close();
`);
assertEquals(statusCode, 0);
@@ -991,7 +995,7 @@ Deno.test(
async function netListenUnrefAndRef() {
const p = execCode2(`
async function main() {
- const listener = Deno.listen({ port: 3500 });
+ const listener = Deno.listen({ port: ${listenPort} });
listener.unref();
listener.ref(); // This restores 'ref' state of listener
console.log("started");
@@ -1001,7 +1005,7 @@ Deno.test(
main();
`);
await p.waitStdoutText("started");
- const conn = await Deno.connect({ port: 3500 });
+ const conn = await Deno.connect({ port: listenPort });
conn.close();
const [statusCode, output] = await p.finished();
assertEquals(statusCode, 0);
@@ -1013,7 +1017,7 @@ Deno.test(
{ permissions: { net: true } },
async function netListenUnrefConcurrentAccept() {
const timer = setTimeout(() => {}, 1000);
- const listener = Deno.listen({ port: 3500 });
+ const listener = Deno.listen({ port: listenPort });
listener.accept().catch(() => {});
listener.unref();
// Unref'd listener still causes Busy error
@@ -1044,12 +1048,12 @@ Deno.test({
Deno.test(
{ permissions: { net: true, read: true, run: true } },
async function netConnUnref() {
- const listener = Deno.listen({ port: 3500 });
+ const listener = Deno.listen({ port: listenPort });
const intervalId = setInterval(() => {}); // This keeps event loop alive.
const program = execCode(`
async function main() {
- const conn = await Deno.connect({ port: 3500 });
+ const conn = await Deno.connect({ port: ${listenPort} });
conn.unref();
await conn.read(new Uint8Array(10)); // The program exits here
throw new Error(); // The program doesn't reach here
@@ -1068,12 +1072,12 @@ Deno.test(
Deno.test(
{ permissions: { net: true, read: true, run: true } },
async function netConnUnrefReadable() {
- const listener = Deno.listen({ port: 3500 });
+ const listener = Deno.listen({ port: listenPort });
const intervalId = setInterval(() => {}); // This keeps event loop alive.
const program = execCode(`
async function main() {
- const conn = await Deno.connect({ port: 3500 });
+ const conn = await Deno.connect({ port: ${listenPort} });
conn.unref();
const reader = conn.readable.getReader();
await reader.read(); // The program exits here
@@ -1093,7 +1097,7 @@ Deno.test(
Deno.test({ permissions: { net: true } }, async function netTcpReuseAddr() {
const listener1 = Deno.listen({
hostname: "127.0.0.1",
- port: 3500,
+ port: listenPort,
});
listener1.accept().then(
(conn) => {
@@ -1101,7 +1105,7 @@ Deno.test({ permissions: { net: true } }, async function netTcpReuseAddr() {
},
);
- const conn1 = await Deno.connect({ hostname: "127.0.0.1", port: 3500 });
+ const conn1 = await Deno.connect({ hostname: "127.0.0.1", port: listenPort });
const buf1 = new Uint8Array(1024);
await conn1.read(buf1);
listener1.close();
@@ -1109,7 +1113,7 @@ Deno.test({ permissions: { net: true } }, async function netTcpReuseAddr() {
const listener2 = Deno.listen({
hostname: "127.0.0.1",
- port: 3500,
+ port: listenPort,
});
listener2.accept().then(
@@ -1118,7 +1122,7 @@ Deno.test({ permissions: { net: true } }, async function netTcpReuseAddr() {
},
);
- const conn2 = await Deno.connect({ hostname: "127.0.0.1", port: 3500 });
+ const conn2 = await Deno.connect({ hostname: "127.0.0.1", port: listenPort });
const buf2 = new Uint8Array(1024);
await conn2.read(buf2);
diff --git a/cli/tests/unit/resources_test.ts b/cli/tests/unit/resources_test.ts
index 2d1f2fd75..4a55f05a7 100644
--- a/cli/tests/unit/resources_test.ts
+++ b/cli/tests/unit/resources_test.ts
@@ -1,6 +1,8 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals, assertThrows } from "./test_util.ts";
+const listenPort = 4505;
+
Deno.test(function resourcesCloseBadArgs() {
assertThrows(() => {
Deno.close((null as unknown) as number);
@@ -16,8 +18,8 @@ Deno.test(function resourcesStdio() {
});
Deno.test({ permissions: { net: true } }, async function resourcesNet() {
- const listener = Deno.listen({ port: 4501 });
- const dialerConn = await Deno.connect({ port: 4501 });
+ const listener = Deno.listen({ port: listenPort });
+ const dialerConn = await Deno.connect({ port: listenPort });
const listenerConn = await listener.accept();
const res = Deno.resources();
diff --git a/cli/tests/unit/serve_test.ts b/cli/tests/unit/serve_test.ts
index c26d3f751..d3faac78d 100644
--- a/cli/tests/unit/serve_test.ts
+++ b/cli/tests/unit/serve_test.ts
@@ -14,6 +14,9 @@ import {
fail,
} from "./test_util.ts";
+// Since these tests may run in parallel, ensure this port is unique to this file
+const servePort = 4502;
+
const {
upgradeHttpRaw,
addTrailers,
@@ -42,18 +45,18 @@ Deno.test(async function httpServerShutsDownPortBeforeResolving() {
const server = Deno.serve({
handler: (_req) => new Response("ok"),
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
});
await listeningPromise;
- assertThrows(() => Deno.listen({ port: 4501 }));
+ assertThrows(() => Deno.listen({ port: servePort }));
ac.abort();
await server.finished;
- const listener = Deno.listen({ port: 4501 });
+ const listener = Deno.listen({ port: servePort });
listener!.close();
});
@@ -79,14 +82,14 @@ Deno.test(async function httpServerCanResolveHostnames() {
const server = Deno.serve({
handler: (_req) => new Response("ok"),
hostname: "localhost",
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const resp = await fetch("http://localhost:4501/", {
+ const resp = await fetch(`http://localhost:${servePort}/`, {
headers: { "connection": "close" },
});
const text = await resp.text();
@@ -102,7 +105,7 @@ Deno.test(async function httpServerRejectsOnAddrInUse() {
const server = Deno.serve({
handler: (_req) => new Response("ok"),
hostname: "localhost",
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
@@ -114,7 +117,7 @@ Deno.test(async function httpServerRejectsOnAddrInUse() {
Deno.serve({
handler: (_req) => new Response("ok"),
hostname: "localhost",
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
@@ -135,20 +138,20 @@ Deno.test({ permissions: { net: true } }, async function httpServerBasic() {
// FIXME(bartlomieju):
// make sure that request can be inspected
console.log(request);
- assertEquals(new URL(request.url).href, "http://127.0.0.1:4501/");
+ assertEquals(new URL(request.url).href, `http://127.0.0.1:${servePort}/`);
assertEquals(await request.text(), "");
assertEquals(remoteAddr.hostname, "127.0.0.1");
promise.resolve();
return new Response("Hello World", { headers: { "foo": "bar" } });
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const resp = await fetch("http://127.0.0.1:4501/", {
+ const resp = await fetch(`http://127.0.0.1:${servePort}/`, {
headers: { "connection": "close" },
});
await promise;
@@ -173,7 +176,7 @@ Deno.test({ permissions: { net: true } }, async function httpServerOnError() {
await new Promise((r) => setTimeout(r, 100));
throw "fail";
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: () => {
@@ -182,14 +185,14 @@ Deno.test({ permissions: { net: true } }, async function httpServerOnError() {
});
await listeningPromise;
- const resp = await fetch("http://127.0.0.1:4501/", {
+ const resp = await fetch(`http://127.0.0.1:${servePort}/`, {
headers: { "connection": "close" },
});
const text = await resp.text();
ac.abort();
await server;
- assertEquals(text, "failed: http://127.0.0.1:4501/");
+ assertEquals(text, `failed: http://127.0.0.1:${servePort}/`);
});
Deno.test(
@@ -208,7 +211,7 @@ Deno.test(
await new Promise((r) => setTimeout(r, 100));
throw "fail";
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: () => {
@@ -217,7 +220,7 @@ Deno.test(
});
await listeningPromise;
- const resp = await fetch("http://127.0.0.1:4501/", {
+ const resp = await fetch(`http://127.0.0.1:${servePort}/`, {
headers: { "connection": "close" },
});
const text = await resp.text();
@@ -234,7 +237,7 @@ Deno.test({ permissions: { net: true } }, async function httpServerOverload1() {
const listeningPromise = deferred();
const server = Deno.serve({
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
@@ -242,14 +245,14 @@ Deno.test({ permissions: { net: true } }, async function httpServerOverload1() {
// FIXME(bartlomieju):
// make sure that request can be inspected
console.log(request);
- assertEquals(new URL(request.url).href, "http://127.0.0.1:4501/");
+ assertEquals(new URL(request.url).href, `http://127.0.0.1:${servePort}/`);
assertEquals(await request.text(), "");
promise.resolve();
return new Response("Hello World", { headers: { "foo": "bar" } });
});
await listeningPromise;
- const resp = await fetch("http://127.0.0.1:4501/", {
+ const resp = await fetch(`http://127.0.0.1:${servePort}/`, {
headers: { "connection": "close" },
});
await promise;
@@ -269,7 +272,7 @@ Deno.test({ permissions: { net: true } }, async function httpServerOverload2() {
const listeningPromise = deferred();
const server = Deno.serve({
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
@@ -277,14 +280,14 @@ Deno.test({ permissions: { net: true } }, async function httpServerOverload2() {
// FIXME(bartlomieju):
// make sure that request can be inspected
console.log(request);
- assertEquals(new URL(request.url).href, "http://127.0.0.1:4501/");
+ assertEquals(new URL(request.url).href, `http://127.0.0.1:${servePort}/`);
assertEquals(await request.text(), "");
promise.resolve();
return new Response("Hello World", { headers: { "foo": "bar" } });
});
await listeningPromise;
- const resp = await fetch("http://127.0.0.1:4501/", {
+ const resp = await fetch(`http://127.0.0.1:${servePort}/`, {
headers: { "connection": "close" },
});
await promise;
@@ -387,14 +390,14 @@ Deno.test(
promise.resolve();
return new Response("");
},
- port: 2333,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const conn = await Deno.connect({ port: 2333 });
+ const conn = await Deno.connect({ port: servePort });
// Send GET request with a body + content-length.
const encoder = new TextEncoder();
const body =
@@ -525,18 +528,18 @@ Deno.test(
promise.resolve();
return new Response("", { headers: {} });
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const conn = await Deno.connect({ port: 4501 });
+ const conn = await Deno.connect({ port: servePort });
// Send GET request with a body + content-length.
const encoder = new TextEncoder();
const body =
- `GET / HTTP/1.1\r\nHost: 127.0.0.1:4501\r\nContent-Length: 5\r\n\r\n12345`;
+ `GET / HTTP/1.1\r\nHost: 127.0.0.1:${servePort}\r\nContent-Length: 5\r\n\r\n12345`;
const writeResult = await conn.write(encoder.encode(body));
assertEquals(body.length, writeResult);
@@ -590,14 +593,14 @@ function createStreamTest(count: number, delay: number, action: string) {
handler: (_request) => {
return new Response(makeStream(count, delay));
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const resp = await fetch("http://127.0.0.1:4501/");
+ const resp = await fetch(`http://127.0.0.1:${servePort}/`);
const text = await resp.text();
ac.abort();
@@ -643,14 +646,14 @@ Deno.test(
assertEquals("hello world", reqBody);
return new Response("yo");
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const resp = await fetch("http://127.0.0.1:4501/", {
+ const resp = await fetch(`http://127.0.0.1:${servePort}/`, {
body: stream.readable,
method: "POST",
headers: { "connection": "close" },
@@ -667,13 +670,13 @@ Deno.test({ permissions: { net: true } }, async function httpServerClose() {
const listeningPromise = deferred();
const server = Deno.serve({
handler: () => new Response("ok"),
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const client = await Deno.connect({ port: 4501 });
+ const client = await Deno.connect({ port: servePort });
client.close();
ac.abort();
await server;
@@ -692,13 +695,13 @@ Deno.test({ permissions: { net: true } }, async function httpServerCloseGet() {
responsePromise.resolve();
return new Response("ok");
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const conn = await Deno.connect({ port: 4501 });
+ const conn = await Deno.connect({ port: servePort });
const encoder = new TextEncoder();
const body =
`GET / HTTP/1.1\r\nHost: example.domain\r\nConnection: close\r\n\r\n`;
@@ -719,14 +722,14 @@ Deno.test(
const listeningPromise = deferred();
const server = Deno.serve({
handler: () => new Response(new Blob([])),
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const resp = await fetch("http://127.0.0.1:4501/");
+ const resp = await fetch(`http://127.0.0.1:${servePort}/`);
const respBody = await resp.text();
assertEquals("", respBody);
@@ -754,7 +757,7 @@ Deno.test(
});
return new Response(body);
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: (err) => {
@@ -768,7 +771,7 @@ Deno.test(
});
await listeningPromise;
- const resp = await fetch("http://127.0.0.1:4501/");
+ const resp = await fetch(`http://127.0.0.1:${servePort}/`);
// Incorrectly implemented reader ReadableStream should reject.
assertStringIncludes(await resp.text(), "Failed to execute 'enqueue'");
await errorPromise;
@@ -833,7 +836,7 @@ Deno.test({ permissions: { net: true } }, async function httpServerWebSocket() {
};
return response;
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
@@ -841,7 +844,7 @@ Deno.test({ permissions: { net: true } }, async function httpServerWebSocket() {
await listeningPromise;
const def = deferred();
- const ws = new WebSocket("ws://localhost:4501");
+ const ws = new WebSocket(`ws://localhost:${servePort}`);
ws.onmessage = (m) => assertEquals(m.data, "foo");
ws.onerror = (e) => {
console.error(e);
@@ -887,7 +890,7 @@ Deno.test(
conn.close();
return response;
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
@@ -895,7 +898,7 @@ Deno.test(
await listeningPromise;
- const conn = await Deno.connect({ port: 4501 });
+ const conn = await Deno.connect({ port: servePort });
await conn.write(
new TextEncoder().encode(
"GET / HTTP/1.1\r\nConnection: Upgrade\r\nUpgrade: websocket\r\n\r\nUpgrade data",
@@ -962,7 +965,7 @@ Deno.test(
};
return response;
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
@@ -970,7 +973,7 @@ Deno.test(
await listeningPromise;
const def = deferred();
- const ws = new WebSocket("ws://localhost:4501");
+ const ws = new WebSocket(`ws://localhost:${servePort}`);
ws.onmessage = (m) => assertEquals(m.data, "foo");
ws.onerror = (e) => {
console.error(e);
@@ -999,7 +1002,7 @@ Deno.test(
socket.onopen = () => socket.close();
return response;
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
@@ -1007,7 +1010,7 @@ Deno.test(
await listeningPromise;
const def = deferred();
- const ws = new WebSocket("ws://localhost:4501");
+ const ws = new WebSocket(`ws://localhost:${servePort}`);
ws.onerror = (e) => {
console.error(e);
fail();
@@ -1041,7 +1044,7 @@ Deno.test(
};
return response;
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
@@ -1049,8 +1052,9 @@ Deno.test(
await listeningPromise;
const def = deferred();
- const ws = new WebSocket("ws://localhost:4501");
- ws.onmessage = (m) => assertEquals(m.data, "http://localhost:4501/");
+ const ws = new WebSocket(`ws://localhost:${servePort}`);
+ ws.onmessage = (m) =>
+ assertEquals(m.data, `http://localhost:${servePort}/`);
ws.onerror = (e) => {
console.error(e);
fail();
@@ -1078,14 +1082,14 @@ Deno.test(
promise.resolve();
return new Response("");
},
- port: 2333,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const conn = await Deno.connect({ port: 2333 });
+ const conn = await Deno.connect({ port: servePort });
// Send GET request with a body + content-length.
const encoder = new TextEncoder();
const smthElse = "x".repeat(16 * 1024 + 256);
@@ -1118,14 +1122,14 @@ Deno.test(
promise.resolve();
return new Response("");
},
- port: 2333,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const conn = await Deno.connect({ port: 2333 });
+ const conn = await Deno.connect({ port: servePort });
// Send GET request with a body + content-length.
const encoder = new TextEncoder();
const smthElse = "x".repeat(16 * 1024 + 256);
@@ -1161,14 +1165,14 @@ Deno.test(
promise.resolve();
return new Response("");
},
- port: 2333,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const conn = await Deno.connect({ port: 2333 });
+ const conn = await Deno.connect({ port: servePort });
// Send GET request with a body + connection: close.
const encoder = new TextEncoder();
const body =
@@ -1191,7 +1195,7 @@ Deno.test(
const ac = new AbortController();
const server = Deno.serve(
- { port: 2333, signal: ac.signal },
+ { port: servePort, signal: ac.signal },
(request) => {
assert(request.body);
@@ -1203,7 +1207,7 @@ Deno.test(
const ts = new TransformStream();
const writable = ts.writable.getWriter();
- const resp = await fetch("http://127.0.0.1:2333/", {
+ const resp = await fetch(`http://127.0.0.1:${servePort}/`, {
method: "POST",
body: ts.readable,
});
@@ -1255,7 +1259,7 @@ Deno.test(
const w = new BufWriter(conn);
const r = new BufReader(conn);
- const body = `GET / HTTP/1.1\r\nHost: 127.0.0.1:4501\r\n\r\n`;
+ const body = `GET / HTTP/1.1\r\nHost: 127.0.0.1:${servePort}\r\n\r\n`;
const writeResult = await w.write(encoder.encode(body));
assertEquals(body.length, writeResult);
await w.flush();
@@ -1313,7 +1317,7 @@ Deno.test(
promise.resolve();
return new Response(periodicStream());
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
@@ -1321,7 +1325,7 @@ Deno.test(
await listeningPromise;
// start a client
- const clientConn = await Deno.connect({ port: 4501 });
+ const clientConn = await Deno.connect({ port: servePort });
const r1 = await writeRequest(clientConn);
assertEquals(r1, "0\n1\n2\n");
@@ -1345,16 +1349,16 @@ Deno.test(
promise.resolve();
return new Response("hello", { headers: { "X-Header-Test": "Æ" } });
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const clientConn = await Deno.connect({ port: 4501 });
+ const clientConn = await Deno.connect({ port: servePort });
const requestText =
- "GET / HTTP/1.1\r\nHost: 127.0.0.1:4501\r\nX-Header-Test: á\r\n\r\n";
+ `GET / HTTP/1.1\r\nHost: 127.0.0.1:${servePort}\r\nX-Header-Test: á\r\n\r\n`;
const requestBytes = new Uint8Array(requestText.length);
for (let i = 0; i < requestText.length; i++) {
requestBytes[i] = requestText.charCodeAt(i);
@@ -1388,19 +1392,19 @@ Deno.test(
const server = Deno.serve({
handler: async (request) => {
// FIXME:
- // assertEquals(new URL(request.url).href, "http://127.0.0.1:4501/");
+ // assertEquals(new URL(request.url).href, `http://127.0.0.1:${servePort}/`);
assertEquals(await request.text(), "");
promise.resolve();
return new Response("11");
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const clientConn = await Deno.connect({ port: 4501 });
+ const clientConn = await Deno.connect({ port: servePort });
async function writeRequest(conn: Deno.Conn) {
const encoder = new TextEncoder();
@@ -1408,7 +1412,7 @@ Deno.test(
const w = new BufWriter(conn);
const r = new BufReader(conn);
const body =
- `CONNECT 127.0.0.1:4501 HTTP/1.1\r\nHost: 127.0.0.1:4501\r\n\r\n`;
+ `CONNECT 127.0.0.1:${servePort} HTTP/1.1\r\nHost: 127.0.0.1:${servePort}\r\n\r\n`;
const writeResult = await w.write(encoder.encode(body));
assertEquals(body.length, writeResult);
await w.flush();
@@ -1446,7 +1450,7 @@ Deno.test(
promise.resolve();
return new Response("ok");
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
@@ -1454,7 +1458,7 @@ Deno.test(
});
await listeningPromise;
- const resp = await fetch("http://127.0.0.1:4501/", {
+ const resp = await fetch(`http://127.0.0.1:${servePort}/`, {
headers: [
["connection", "close"],
["cookie", "foo=bar"],
@@ -1482,21 +1486,20 @@ Deno.test(
const ac = new AbortController();
const hostname = "localhost";
- const port = 4501;
const server = Deno.serve({
handler: () => {
promise.resolve();
return new Response("ok");
},
- port: port,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const url = `http://${hostname}:${port}/`;
+ const url = `http://${hostname}:${servePort}/`;
const args = ["-X", "DELETE", url];
const { success } = await new Deno.Command("curl", {
args,
@@ -1525,13 +1528,13 @@ Deno.test(
promise.resolve();
return new Response(new Uint8Array([128]));
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
});
await listeningPromise;
- const resp = await fetch("http://localhost:4501/");
+ const resp = await fetch(`http://localhost:${servePort}/`);
await promise;
@@ -2211,12 +2214,11 @@ Deno.test(
const ac = new AbortController();
const listeningPromise = deferred();
const hostname = "127.0.0.1";
- const port = 4501;
const server = Deno.serve({
handler: () => new Response("Hello World"),
hostname,
- port,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
@@ -2227,7 +2229,7 @@ Deno.test(
await listeningPromise;
const caCert = Deno.readTextFileSync("cli/tests/testdata/tls/RootCA.pem");
const client = Deno.createHttpClient({ caCerts: [caCert] });
- const resp = await fetch(`https://localhost:${port}/`, {
+ const resp = await fetch(`https://localhost:${servePort}/`, {
client,
headers: { "connection": "close" },
});
@@ -2332,7 +2334,7 @@ Deno.test(
const ac = new AbortController();
const server = Deno.serve({
handler: (_request) => new Response(null, { status: 204 }),
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
@@ -2340,7 +2342,7 @@ Deno.test(
try {
await listeningPromise;
- const resp = await fetch("http://127.0.0.1:4501/", {
+ const resp = await fetch(`http://127.0.0.1:${servePort}/`, {
method: "GET",
headers: { "connection": "close" },
});
@@ -2641,7 +2643,7 @@ Deno.test(
const server = Deno.serve({
handler: (_req) => new Response("ok"),
hostname: "localhost",
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
@@ -2940,7 +2942,7 @@ Deno.test(
addTrailers(response, [["baz", "why"]]);
return response;
},
- port: 4501,
+ port: servePort,
signal: ac.signal,
onListen: onListen(listeningPromise),
onError: createOnErrorCb(ac),
@@ -2948,7 +2950,7 @@ Deno.test(
// We don't have a great way to access this right now, so just fetch the trailers with cURL
const [_, stderr] = await curlRequestWithStdErr([
- "http://localhost:4501/path",
+ `http://localhost:${servePort}/path`,
"-v",
"--http2",
"--http2-prior-knowledge",
diff --git a/cli/tests/unit/streams_deprecated.ts b/cli/tests/unit/streams_deprecated.ts
deleted file mode 100644
index 04dbfa3fb..000000000
--- a/cli/tests/unit/streams_deprecated.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
-import { assertEquals } from "./test_util.ts";
-
-Deno.test(async function symlinkSyncPerm() {
- const rs = new ReadableStream<string>({
- start(controller) {
- controller.enqueue("hello ");
- controller.enqueue("deno");
- controller.close();
- },
- });
-
- for await (const chunk of rs.getIterator()) {
- assertEquals(typeof chunk, "string");
- }
-});