From 20babd9bfaf0ee78c462ab8a28eb67660d858b94 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Mon, 4 Jan 2021 15:52:22 +0100 Subject: 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. --- cli/tests/integration_tests.rs | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'cli') 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 = + 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 = + 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(); -- cgit v1.2.3