summaryrefslogtreecommitdiff
path: root/cli/tests/integration/inspector_tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/integration/inspector_tests.rs')
-rw-r--r--cli/tests/integration/inspector_tests.rs73
1 files changed, 73 insertions, 0 deletions
diff --git a/cli/tests/integration/inspector_tests.rs b/cli/tests/integration/inspector_tests.rs
index 520a5b4f7..e901e2633 100644
--- a/cli/tests/integration/inspector_tests.rs
+++ b/cli/tests/integration/inspector_tests.rs
@@ -519,3 +519,76 @@ async fn inspector_connect_non_ws() {
child.kill().unwrap();
child.wait().unwrap();
}
+
+#[tokio::test]
+async fn inspector_break_on_first_line_in_test() {
+ let script = util::testdata_path().join("inspector_test.js");
+ let mut child = util::deno_cmd()
+ .arg("test")
+ .arg(inspect_flag_with_unique_port("--inspect-brk"))
+ .arg(script)
+ .stdout(std::process::Stdio::piped())
+ .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 (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":"Runtime.evaluate","params":{"expression":"Deno.core.print(\"hello from the inspector\\n\")","contextId":1,"includeCommandLineAPI":true,"silent":false,"returnByValue":true}}"#,
+ ),
+ WsRecv(r#"{"id":4,"result":{"result":{"type":"undefined"}}}"#),
+ StdOut("hello from the inspector"),
+ WsSend(r#"{"id":5,"method":"Debugger.resume"}"#),
+ WsRecv(r#"{"id":5,"result":{}}"#),
+ StdOut("running 1 test from"),
+ StdOut("test has finished running"),
+ ];
+
+ for step in test_steps {
+ match step {
+ StdOut(s) => assert!(
+ &stdout_lines.next().unwrap().contains(s),
+ "Doesn't contain {}",
+ s
+ ),
+ WsRecv(s) => assert!(socket_rx.next().await.unwrap().starts_with(s)),
+ WsSend(s) => socket_tx.send(s.into()).await.unwrap(),
+ _ => unreachable!(),
+ }
+ }
+
+ child.kill().unwrap();
+ child.wait().unwrap();
+}