summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYoshiya Hinosawa <stibium121@gmail.com>2022-08-22 17:01:43 +0900
committerGitHub <noreply@github.com>2022-08-22 17:01:43 +0900
commit57d48134d168cc128f075cb7381d773ea028c81e (patch)
treee60a5ef22ffb9e6b42aaded54ed5c42f3988f4d1
parent301f6c46ba4491e9aec76037ae9d01365693b0e4 (diff)
fix(ext/flash): fix default onListen callback (#15533)
-rw-r--r--cli/tests/unit/flash_test.ts34
-rw-r--r--ext/flash/01_http.js6
2 files changed, 36 insertions, 4 deletions
diff --git a/cli/tests/unit/flash_test.ts b/cli/tests/unit/flash_test.ts
index fdad1e3ae..fb96e66be 100644
--- a/cli/tests/unit/flash_test.ts
+++ b/cli/tests/unit/flash_test.ts
@@ -101,6 +101,40 @@ Deno.test({ permissions: { net: true } }, async function httpServerPort0() {
await server;
});
+Deno.test(
+ { permissions: { net: true } },
+ async function httpServerDefaultOnListenCallback() {
+ const ac = new AbortController();
+
+ const consoleLog = console.log;
+ console.log = (msg) => {
+ try {
+ const match = msg.match(/Listening on http:\/\/localhost:(\d+)\//);
+ assert(!!match);
+ const port = +match[1];
+ assert(port > 0 && port < 65536);
+ } finally {
+ ac.abort();
+ }
+ };
+
+ try {
+ const server = Deno.serve({
+ fetch() {
+ return new Response("Hello World");
+ },
+ hostname: "0.0.0.0",
+ port: 0,
+ signal: ac.signal,
+ });
+
+ await server;
+ } finally {
+ console.log = consoleLog;
+ }
+ },
+);
+
// https://github.com/denoland/deno/issues/15107
Deno.test(
{ permissions: { net: true } },
diff --git a/ext/flash/01_http.js b/ext/flash/01_http.js
index e8debd5ec..9fda597c7 100644
--- a/ext/flash/01_http.js
+++ b/ext/flash/01_http.js
@@ -205,11 +205,9 @@
return new Response("Internal Server Error", { status: 500 });
};
delete opts.onError;
- const onListen = opts.onListen ?? function () {
+ const onListen = opts.onListen ?? function ({ port }) {
console.log(
- `Listening on http://${
- hostnameForDisplay(opts.hostname)
- }:${opts.port}/`,
+ `Listening on http://${hostnameForDisplay(opts.hostname)}:${port}/`,
);
};
delete opts.onListen;