summaryrefslogtreecommitdiff
path: root/cli/tests/integration_tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/integration_tests.rs')
-rw-r--r--cli/tests/integration_tests.rs117
1 files changed, 96 insertions, 21 deletions
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 0847c1806..d4c58a685 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -2152,10 +2152,7 @@ fn extract_ws_url_from_stderr(
#[tokio::test]
async fn inspector_connect() {
- let script = deno::test_util::root_path()
- .join("cli")
- .join("tests")
- .join("inspector1.js");
+ let script = util::tests_path().join("inspector1.js");
let mut child = util::deno_cmd()
.arg("run")
// Warning: each inspector test should be on its own port to avoid
@@ -2174,6 +2171,7 @@ async fn inspector_connect() {
.expect("Can't connect");
assert_eq!("101 Switching Protocols", response.status().to_string());
child.kill().unwrap();
+ child.wait().unwrap();
}
enum TestStep {
@@ -2184,10 +2182,7 @@ enum TestStep {
#[tokio::test]
async fn inspector_break_on_first_line() {
- let script = deno::test_util::root_path()
- .join("cli")
- .join("tests")
- .join("inspector2.js");
+ let script = util::tests_path().join("inspector2.js");
let mut child = util::deno_cmd()
.arg("run")
// Warning: each inspector test should be on its own port to avoid
@@ -2224,12 +2219,12 @@ async fn inspector_break_on_first_line() {
WsRecv(r#"{"id":3,"result":{}}"#),
WsRecv(r#"{"method":"Debugger.paused","#),
WsSend(
- r#"{"id":5,"method":"Runtime.evaluate","params":{"expression":"Deno.core.print(\"hello from the inspector\\n\")","contextId":1,"includeCommandLineAPI":true,"silent":false,"returnByValue":true}}"#,
+ r#"{"id":4,"method":"Runtime.evaluate","params":{"expression":"Deno.core.print(\"hello from the inspector\\n\")","contextId":1,"includeCommandLineAPI":true,"silent":false,"returnByValue":true}}"#,
),
- WsRecv(r#"{"id":5,"result":{"result":{"type":"undefined"}}}"#),
+ WsRecv(r#"{"id":4,"result":{"result":{"type":"undefined"}}}"#),
StdOut("hello from the inspector"),
- WsSend(r#"{"id":6,"method":"Debugger.resume"}"#),
- WsRecv(r#"{"id":6,"result":{}}"#),
+ WsSend(r#"{"id":5,"method":"Debugger.resume"}"#),
+ WsRecv(r#"{"id":5,"result":{}}"#),
StdOut("hello from the script"),
];
@@ -2254,14 +2249,12 @@ async fn inspector_break_on_first_line() {
}
child.kill().unwrap();
+ child.wait().unwrap();
}
#[tokio::test]
async fn inspector_pause() {
- let script = deno::test_util::root_path()
- .join("cli")
- .join("tests")
- .join("inspector1.js");
+ let script = util::tests_path().join("inspector1.js");
let mut child = util::deno_cmd()
.arg("run")
// Warning: each inspector test should be on its own port to avoid
@@ -2317,10 +2310,7 @@ async fn inspector_pause() {
#[tokio::test]
async fn inspector_port_collision() {
- let script = deno::test_util::root_path()
- .join("cli")
- .join("tests")
- .join("inspector1.js");
+ let script = util::tests_path().join("inspector1.js");
let mut child1 = util::deno_cmd()
.arg("run")
.arg("--inspect=127.0.0.1:9231")
@@ -2348,8 +2338,93 @@ async fn inspector_port_collision() {
.read_to_string(&mut stderr_str_2)
.unwrap();
assert!(stderr_str_2.contains("Cannot start inspector server"));
+
child1.kill().unwrap();
- let _ = child2.kill();
+ child1.wait().unwrap();
+ child2.wait().unwrap();
+}
+
+#[tokio::test]
+async fn inspector_does_not_hang() {
+ let script = util::tests_path().join("inspector3.js");
+ let mut child = util::deno_cmd()
+ .arg("run")
+ // Warning: each inspector test should be on its own port to avoid
+ // conflicting with another inspector test.
+ .arg("--inspect-brk=127.0.0.1:9232")
+ .arg(script)
+ .stdout(std::process::Stdio::piped())
+ .stderr(std::process::Stdio::piped())
+ .spawn()
+ .unwrap();
+
+ let stderr = child.stderr.as_mut().unwrap();
+ let ws_url = extract_ws_url_from_stderr(stderr);
+ let (socket, response) = tokio_tungstenite::connect_async(ws_url)
+ .await
+ .expect("Can't connect");
+ assert_eq!(response.status(), 101); // Switching protocols.
+
+ let (mut socket_tx, socket_rx) = socket.split();
+ let mut socket_rx =
+ socket_rx.map(|msg| msg.unwrap().to_string()).filter(|msg| {
+ let pass = !msg.starts_with(r#"{"method":"Debugger.scriptParsed","#);
+ futures::future::ready(pass)
+ });
+
+ let stdout = child.stdout.as_mut().unwrap();
+ let mut stdout_lines =
+ std::io::BufReader::new(stdout).lines().map(|r| r.unwrap());
+
+ use TestStep::*;
+ let test_steps = vec![
+ WsSend(r#"{"id":1,"method":"Runtime.enable"}"#),
+ WsSend(r#"{"id":2,"method":"Debugger.enable"}"#),
+ WsRecv(
+ r#"{"method":"Runtime.executionContextCreated","params":{"context":{"id":1,"#,
+ ),
+ WsRecv(r#"{"id":1,"result":{}}"#),
+ WsRecv(r#"{"id":2,"result":{"debuggerId":"#),
+ WsSend(r#"{"id":3,"method":"Runtime.runIfWaitingForDebugger"}"#),
+ WsRecv(r#"{"id":3,"result":{}}"#),
+ WsRecv(r#"{"method":"Debugger.paused","#),
+ WsSend(r#"{"id":4,"method":"Debugger.resume"}"#),
+ WsRecv(r#"{"id":4,"result":{}}"#),
+ WsRecv(r#"{"method":"Debugger.resumed","params":{}}"#),
+ ];
+
+ for step in test_steps {
+ match step {
+ WsRecv(s) => assert!(socket_rx.next().await.unwrap().starts_with(s)),
+ WsSend(s) => socket_tx.send(s.into()).await.unwrap(),
+ _ => unreachable!(),
+ }
+ }
+
+ for i in 0..128u32 {
+ let request_id = i + 10;
+ // Expect the number {i} on stdout.
+ let s = format!("{}", i);
+ assert_eq!(stdout_lines.next().unwrap(), s);
+ // Expect hitting the `debugger` statement.
+ let s = r#"{"method":"Debugger.paused","#;
+ assert!(socket_rx.next().await.unwrap().starts_with(s));
+ // Send the 'Debugger.resume' request.
+ let s = format!(r#"{{"id":{},"method":"Debugger.resume"}}"#, request_id);
+ socket_tx.send(s.into()).await.unwrap();
+ // Expect confirmation of the 'Debugger.resume' request.
+ let s = format!(r#"{{"id":{},"result":{{}}}}"#, request_id);
+ assert_eq!(socket_rx.next().await.unwrap(), s);
+ let s = r#"{"method":"Debugger.resumed","params":{}}"#;
+ assert_eq!(socket_rx.next().await.unwrap(), s);
+ }
+
+ // Check that we can gracefully close the websocket connection.
+ socket_tx.close().await.unwrap();
+ socket_rx.for_each(|_| async {}).await;
+
+ assert_eq!(&stdout_lines.next().unwrap(), "done");
+ assert!(child.wait().unwrap().success());
}
mod util {