summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ext/http/00_serve.ts3
-rw-r--r--tests/integration/serve_tests.rs8
-rw-r--r--tests/specs/serve/basic/__test__.jsonc16
-rw-r--r--tests/specs/serve/basic/main_not_win.out1
-rw-r--r--tests/unit/serve_test.ts6
5 files changed, 24 insertions, 10 deletions
diff --git a/ext/http/00_serve.ts b/ext/http/00_serve.ts
index 670b64676..a58d19d76 100644
--- a/ext/http/00_serve.ts
+++ b/ext/http/00_serve.ts
@@ -657,7 +657,8 @@ function serve(arg1, arg2) {
// If the hostname is "0.0.0.0", we display "localhost" in console
// because browsers in Windows don't resolve "0.0.0.0".
// See the discussion in https://github.com/denoland/deno_std/issues/1165
- const hostname = addr.hostname == "0.0.0.0" || addr.hostname == "::"
+ const hostname = (addr.hostname == "0.0.0.0" || addr.hostname == "::") &&
+ (Deno.build.os === "windows")
? "localhost"
: addr.hostname;
addr.hostname = hostname;
diff --git a/tests/integration/serve_tests.rs b/tests/integration/serve_tests.rs
index 3d64ce3a3..cfe7e4d6a 100644
--- a/tests/integration/serve_tests.rs
+++ b/tests/integration/serve_tests.rs
@@ -21,8 +21,8 @@ async fn deno_serve_port_0() {
let mut buffer = [0; 52];
let _read = stdout.read(&mut buffer).unwrap();
let msg = std::str::from_utf8(&buffer).unwrap();
- let port_regex = Regex::new(r"(\d+)").unwrap();
- let port = port_regex.find(msg).unwrap().as_str();
+ let port_regex = Regex::new(r":(\d+)").unwrap();
+ let port = port_regex.captures(msg).unwrap().get(1).unwrap().as_str();
let cert = reqwest::Certificate::from_pem(include_bytes!(
"../testdata/tls/RootCA.crt"
@@ -64,8 +64,8 @@ async fn deno_serve_no_args() {
let mut buffer = [0; 52];
let _read = stdout.read(&mut buffer).unwrap();
let msg = std::str::from_utf8(&buffer).unwrap();
- let port_regex = Regex::new(r"(\d+)").unwrap();
- let port = port_regex.find(msg).unwrap().as_str();
+ let port_regex = Regex::new(r":(\d+)").unwrap();
+ let port = port_regex.captures(msg).unwrap().get(1).unwrap().as_str();
let cert = reqwest::Certificate::from_pem(include_bytes!(
"../testdata/tls/RootCA.crt"
diff --git a/tests/specs/serve/basic/__test__.jsonc b/tests/specs/serve/basic/__test__.jsonc
index 9a37d60ff..a8eaca0b6 100644
--- a/tests/specs/serve/basic/__test__.jsonc
+++ b/tests/specs/serve/basic/__test__.jsonc
@@ -1,5 +1,15 @@
{
- "args": "serve --port 12345 main.ts",
- "output": "main.out",
- "tempDir": true
+ "tempDir": true,
+ "tests": {
+ "basic_win": {
+ "if": "windows",
+ "args": "serve --host 0.0.0.0 --port 12345 main.ts",
+ "output": "main.out"
+ },
+ "basic_not_win": {
+ "if": "unix",
+ "args": "serve --host 0.0.0.0 --port 12345 main.ts",
+ "output": "main_not_win.out"
+ }
+ }
}
diff --git a/tests/specs/serve/basic/main_not_win.out b/tests/specs/serve/basic/main_not_win.out
new file mode 100644
index 000000000..cbfd3395e
--- /dev/null
+++ b/tests/specs/serve/basic/main_not_win.out
@@ -0,0 +1 @@
+deno serve: Listening on http://0.0.0.0:12345/
diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts
index 4a7d53e1b..450ab6d93 100644
--- a/tests/unit/serve_test.ts
+++ b/tests/unit/serve_test.ts
@@ -748,9 +748,11 @@ Deno.test(
const consoleLog = console.log;
console.log = (msg) => {
try {
- const match = msg.match(/Listening on http:\/\/localhost:(\d+)\//);
+ const match = msg.match(
+ /Listening on http:\/\/(localhost|0\.0\.0\.0):(\d+)\//,
+ );
assert(!!match, `Didn't match ${msg}`);
- const port = +match[1];
+ const port = +match[2];
assert(port > 0 && port < 65536);
} finally {
ac.abort();