summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarvin Hagemeister <marvin@deno.com>2024-09-14 23:30:06 +0200
committerGitHub <noreply@github.com>2024-09-14 23:30:06 +0200
commit597f2d8d4d9b91ee586b9787d6ba52d247e4ff87 (patch)
tree82bfa7272208b81b34e79572f3c9a5bcc6c4658f /tests
parentaf2d992ecd2b9320072164b6ee295c31a3194406 (diff)
feat: print `Listening on` messages on stderr instead of stdout (#25491)
Fixes https://github.com/denoland/deno/issues/25114 --------- Signed-off-by: Leo Kettmeir <crowlkats@toaxl.com> Co-authored-by: Bartek IwaƄczuk <biwanczuk@gmail.com> Co-authored-by: crowlkats <crowlkats@toaxl.com> Co-authored-by: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/serve_tests.rs12
-rw-r--r--tests/integration/watcher_tests.rs6
-rw-r--r--tests/testdata/serve/parallel.ts4
-rw-r--r--tests/unit/serve_test.ts12
4 files changed, 18 insertions, 16 deletions
diff --git a/tests/integration/serve_tests.rs b/tests/integration/serve_tests.rs
index c34b0e286..a1df7825d 100644
--- a/tests/integration/serve_tests.rs
+++ b/tests/integration/serve_tests.rs
@@ -61,11 +61,13 @@ impl ServeClientBuilder {
fn new() -> Self {
Self(
util::deno_cmd()
+ .env("NO_COLOR", "1")
.current_dir(util::testdata_path())
.arg("serve")
.arg("--port")
.arg("0")
- .stdout_piped(),
+ .stdout_piped()
+ .stderr_piped(),
None,
)
}
@@ -106,12 +108,12 @@ impl ServeClient {
fn output(self) -> String {
let mut child = self.child.borrow_mut();
child.kill().unwrap();
- let mut stdout = child.stdout.take().unwrap();
+ let mut stderr = child.stderr.take().unwrap();
child.wait().unwrap();
let mut output_buf = self.output_buf.borrow_mut();
- stdout.read_to_end(&mut output_buf).unwrap();
+ stderr.read_to_end(&mut output_buf).unwrap();
String::from_utf8(std::mem::take(&mut *output_buf)).unwrap()
}
@@ -128,7 +130,7 @@ impl ServeClient {
let mut buffer = self.output_buf.borrow_mut();
let mut temp_buf = [0u8; 64];
let mut child = self.child.borrow_mut();
- let stdout = child.stdout.as_mut().unwrap();
+ let stderr = child.stderr.as_mut().unwrap();
let port_regex = regex::bytes::Regex::new(r":(\d+)").unwrap();
let start = std::time::Instant::now();
@@ -141,7 +143,7 @@ impl ServeClient {
String::from_utf8_lossy(&buffer)
);
}
- let read = stdout.read(&mut temp_buf).unwrap();
+ let read = stderr.read(&mut temp_buf).unwrap();
buffer.extend_from_slice(&temp_buf[..read]);
if let Some(p) = port_regex
.captures(&buffer)
diff --git a/tests/integration/watcher_tests.rs b/tests/integration/watcher_tests.rs
index 2590e79d6..27c59a27d 100644
--- a/tests/integration/watcher_tests.rs
+++ b/tests/integration/watcher_tests.rs
@@ -1359,16 +1359,16 @@ async fn test_watch_serve() {
.piped_output()
.spawn()
.unwrap();
- let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
+ let (mut _stdout_lines, mut stderr_lines) = child_lines(&mut child);
- wait_contains("Listening on", &mut stdout_lines).await;
+ wait_contains("Listening on", &mut stderr_lines).await;
// Note that we start serving very quickly, so we specifically want to wait for this message
wait_contains(r#"Watching paths: [""#, &mut stderr_lines).await;
file_to_watch.write(file_content);
wait_contains("serving", &mut stderr_lines).await;
- wait_contains("Listening on", &mut stdout_lines).await;
+ wait_contains("Listening on", &mut stderr_lines).await;
check_alive_then_kill(child);
}
diff --git a/tests/testdata/serve/parallel.ts b/tests/testdata/serve/parallel.ts
index f1f118c71..2ba7ccfca 100644
--- a/tests/testdata/serve/parallel.ts
+++ b/tests/testdata/serve/parallel.ts
@@ -1,7 +1,7 @@
-console.log("starting serve");
+console.error("starting serve");
export default {
fetch(_req: Request) {
- console.log("serving request");
+ console.error("serving request");
return new Response("deno serve parallel");
},
};
diff --git a/tests/unit/serve_test.ts b/tests/unit/serve_test.ts
index 4a19d8df2..c1e217a11 100644
--- a/tests/unit/serve_test.ts
+++ b/tests/unit/serve_test.ts
@@ -792,8 +792,8 @@ Deno.test(
async function httpServerDefaultOnListenCallback() {
const ac = new AbortController();
- const consoleLog = console.log;
- console.log = (msg) => {
+ const consoleError = console.error;
+ console.error = (msg) => {
try {
const match = msg.match(
/Listening on http:\/\/(localhost|0\.0\.0\.0):(\d+)\//,
@@ -818,7 +818,7 @@ Deno.test(
await server.finished;
} finally {
- console.log = consoleLog;
+ console.error = consoleError;
}
},
);
@@ -875,8 +875,8 @@ Deno.test({ permissions: { net: true } }, async function ipv6Hostname() {
const ac = new AbortController();
let url = "";
- const consoleLog = console.log;
- console.log = (msg) => {
+ const consoleError = console.error;
+ console.error = (msg) => {
try {
const match = msg.match(/Listening on (http:\/\/(.*?):(\d+)\/)/);
assert(!!match, `Didn't match ${msg}`);
@@ -897,7 +897,7 @@ Deno.test({ permissions: { net: true } }, async function ipv6Hostname() {
assert(new URL(url), `Not a valid URL "${url}"`);
await server.shutdown();
} finally {
- console.log = consoleLog;
+ console.error = consoleError;
}
});