diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/inspector2.js | 1 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 88 |
2 files changed, 84 insertions, 5 deletions
diff --git a/cli/tests/inspector2.js b/cli/tests/inspector2.js new file mode 100644 index 000000000..34d8097d2 --- /dev/null +++ b/cli/tests/inspector2.js @@ -0,0 +1 @@ +console.log("hello from the script"); diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 98c564b4d..4f2847ee4 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -7,6 +7,8 @@ extern crate nix; extern crate pty; extern crate tempfile; +use futures::prelude::*; +use std::io::BufRead; use std::process::Command; use tempfile::TempDir; @@ -1999,11 +2001,9 @@ fn test_permissions_net_listen_allow_localhost() { assert!(!err.contains(util::PERMISSION_DENIED_PATTERN)); } -#[cfg(not(target_os = "linux"))] // TODO(ry) broken on github actions. fn extract_ws_url_from_stderr( stderr: &mut std::process::ChildStderr, ) -> url::Url { - use std::io::BufRead; let mut stderr = std::io::BufReader::new(stderr); let mut stderr_first_line = String::from(""); let _ = stderr.read_line(&mut stderr_first_line).unwrap(); @@ -2026,7 +2026,7 @@ async fn inspector_connect() { .arg("run") // Warning: each inspector test should be on its own port to avoid // conflicting with another inspector test. - .arg("--inspect=127.0.0.1:9229") + .arg("--inspect=127.0.0.1:9228") .arg(script) .stderr(std::process::Stdio::piped()) .spawn() @@ -2042,6 +2042,86 @@ async fn inspector_connect() { child.kill().unwrap(); } +enum TestStep { + StdOut(&'static str), + WsRecv(&'static str), + WsSend(&'static str), +} + +#[tokio::test] +async fn inspector_break_on_first_line() { + let script = deno::test_util::root_path() + .join("cli") + .join("tests") + .join("inspector2.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:9229") + .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, mut socket_rx) = socket.split(); + + let stdout = child.stdout.as_mut().unwrap(); + let mut stdout_lines = std::io::BufReader::new(stdout).lines(); + + 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":5,"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"}}}"#), + StdOut("hello from the inspector"), + WsSend(r#"{"id":6,"method":"Debugger.resume"}"#), + WsRecv(r#"{"id":6,"result":{}}"#), + StdOut("hello from the script"), + ]; + + for step in test_steps { + match step { + StdOut(s) => match stdout_lines.next() { + Some(Ok(line)) => assert_eq!(line, s), + other => panic!(other), + }, + WsRecv(s) => loop { + let msg = match socket_rx.next().await { + Some(Ok(msg)) => msg.to_string(), + other => panic!(other), + }; + if !msg.starts_with(r#"{"method":"Debugger.scriptParsed","#) { + assert!(msg.starts_with(s)); + break; + } + }, + WsSend(s) => socket_tx.send(s.into()).await.unwrap(), + } + } + + child.kill().unwrap(); +} + #[cfg(not(target_os = "linux"))] // TODO(ry) broken on github actions. #[tokio::test] async fn inspector_pause() { @@ -2059,7 +2139,6 @@ async fn inspector_pause() { .spawn() .unwrap(); let ws_url = extract_ws_url_from_stderr(child.stderr.as_mut().unwrap()); - println!("ws_url {}", ws_url); // We use tokio_tungstenite as a websocket client because warp (which is // a dependency of Deno) uses it. let (mut socket, _) = tokio_tungstenite::connect_async(ws_url) @@ -2082,7 +2161,6 @@ async fn inspector_pause() { unreachable!() } - use futures::sink::SinkExt; socket .send(r#"{"id":6,"method":"Debugger.enable"}"#.into()) .await |