diff options
-rw-r--r-- | cli/tests/unit/flash_test.ts | 34 | ||||
-rw-r--r-- | ext/flash/01_http.js | 6 |
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; |