summaryrefslogtreecommitdiff
path: root/cli/tests/integration_tests.rs
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2021-01-04 15:52:22 +0100
committerGitHub <noreply@github.com>2021-01-04 15:52:22 +0100
commit20babd9bfaf0ee78c462ab8a28eb67660d858b94 (patch)
tree6514e56b6f14c38ec9e59a58618deee41d35ce8d /cli/tests/integration_tests.rs
parentf4246ee1fca5cb70f6a9ddf24d8282d6292c6366 (diff)
fix(inspector): kill child process after test (#8986)
The child process kept running and printing "hello" to stdout. This commit also removes the dependency on reqwest and instead switches to the re-export from the fetch crate. Brings back commit 1a2e7741c33490d2a91147966019853c6b1d6a48.
Diffstat (limited to 'cli/tests/integration_tests.rs')
-rw-r--r--cli/tests/integration_tests.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 9400db4ad..9dc4df7cb 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -1,7 +1,9 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use deno_core::futures;
use deno_core::futures::prelude::*;
+use deno_core::serde_json;
use deno_core::url;
+use deno_runtime::deno_fetch::reqwest;
use std::io::{BufRead, Write};
use std::process::Command;
use tempfile::TempDir;
@@ -4345,6 +4347,64 @@ async fn inspector_runtime_evaluate_does_not_crash() {
child.wait().unwrap();
}
+#[tokio::test]
+async fn inspector_json() {
+ let script = util::tests_path().join("inspector1.js");
+ let mut child = util::deno_cmd()
+ .arg("run")
+ .arg(inspect_flag_with_unique_port("--inspect"))
+ .arg(script)
+ .stderr(std::process::Stdio::piped())
+ .spawn()
+ .unwrap();
+
+ let stderr = child.stderr.as_mut().unwrap();
+ let mut stderr_lines =
+ std::io::BufReader::new(stderr).lines().map(|r| r.unwrap());
+ let ws_url = extract_ws_url_from_stderr(&mut stderr_lines);
+ let mut url = ws_url.clone();
+ let _ = url.set_scheme("http");
+ url.set_path("/json");
+ let resp = reqwest::get(url).await.unwrap();
+ assert_eq!(resp.status(), reqwest::StatusCode::OK);
+ let endpoint_list: Vec<deno_core::serde_json::Value> =
+ serde_json::from_str(&resp.text().await.unwrap()).unwrap();
+ let matching_endpoint = endpoint_list
+ .iter()
+ .find(|e| e["webSocketDebuggerUrl"] == ws_url.as_str());
+ assert!(matching_endpoint.is_some());
+ child.kill().unwrap();
+}
+
+#[tokio::test]
+async fn inspector_json_list() {
+ let script = util::tests_path().join("inspector1.js");
+ let mut child = util::deno_cmd()
+ .arg("run")
+ .arg(inspect_flag_with_unique_port("--inspect"))
+ .arg(script)
+ .stderr(std::process::Stdio::piped())
+ .spawn()
+ .unwrap();
+
+ let stderr = child.stderr.as_mut().unwrap();
+ let mut stderr_lines =
+ std::io::BufReader::new(stderr).lines().map(|r| r.unwrap());
+ let ws_url = extract_ws_url_from_stderr(&mut stderr_lines);
+ let mut url = ws_url.clone();
+ let _ = url.set_scheme("http");
+ url.set_path("/json/list");
+ let resp = reqwest::get(url).await.unwrap();
+ assert_eq!(resp.status(), reqwest::StatusCode::OK);
+ let endpoint_list: Vec<deno_core::serde_json::Value> =
+ serde_json::from_str(&resp.text().await.unwrap()).unwrap();
+ let matching_endpoint = endpoint_list
+ .iter()
+ .find(|e| e["webSocketDebuggerUrl"] == ws_url.as_str());
+ assert!(matching_endpoint.is_some());
+ child.kill().unwrap();
+}
+
#[test]
fn websocket() {
let _g = util::http_server();