summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-12-12 15:33:30 +0100
committerGitHub <noreply@github.com>2022-12-12 15:33:30 +0100
commit4a17c930882c5765e5fdedb50b6493469f61e32d (patch)
tree91f7157b871ee5d2414018586fc1e3a335963d53 /cli/tests
parenta2db70a8d0820722695e9094c8dbc888bde1ffa3 (diff)
feat: add `--inspect-wait` flag (#17001)
This commit adds new "--inspect-wait" flag which works similarly to "--inspect-brk" in that it waits for inspector session to be established before running code. However it doesn't break on the first statement of user code, but instead runs it as soon as a session is established.
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/inspector_tests.rs56
-rw-r--r--cli/tests/testdata/inspector/inspect_wait.js2
2 files changed, 58 insertions, 0 deletions
diff --git a/cli/tests/inspector_tests.rs b/cli/tests/inspector_tests.rs
index 0cf8cc3bb..7044469e4 100644
--- a/cli/tests/inspector_tests.rs
+++ b/cli/tests/inspector_tests.rs
@@ -13,6 +13,7 @@ use deno_runtime::deno_websocket::tokio_tungstenite::tungstenite;
use std::io::BufRead;
use std::process::Child;
use test_util as util;
+use test_util::TempDir;
use tokio::net::TcpStream;
use util::http_server;
@@ -1319,4 +1320,59 @@ mod inspector {
assert_eq!(tester.child.wait().unwrap().code(), Some(1));
}
+
+ #[tokio::test]
+ async fn inspector_wait() {
+ let script = util::testdata_path().join("inspector/inspect_wait.js");
+ let temp_dir = TempDir::new();
+
+ let child = util::deno_cmd()
+ .current_dir(temp_dir.path())
+ .arg("run")
+ .arg("--quiet")
+ .arg("-A")
+ .arg(inspect_flag_with_unique_port("--inspect-wait"))
+ .arg(script)
+ .stdout(std::process::Stdio::piped())
+ .stderr(std::process::Stdio::piped())
+ .spawn()
+ .unwrap();
+
+ tokio::time::sleep(tokio::time::Duration::from_millis(300)).await;
+ assert!(!temp_dir.path().join("hello.txt").exists());
+
+ let mut tester = InspectorTester::create(child, ignore_script_parsed).await;
+
+ tester.assert_stderr_for_inspect_brk();
+ tester
+ .send_many(&[
+ json!({"id":1,"method":"Runtime.enable"}),
+ json!({"id":2,"method":"Debugger.enable"}),
+ ])
+ .await;
+ tester.assert_received_messages(
+ &[
+ r#"{"id":1,"result":{}}"#,
+ r#"{"id":2,"result":{"debuggerId":"#,
+ ],
+ &[
+ r#"{"method":"Runtime.executionContextCreated","params":{"context":{"id":1,"#,
+ ],
+ )
+ .await;
+ // TODO(bartlomieju): ideally this shouldn't be needed, but currently there's
+ // no way to express that in inspector code. Most clients always send this
+ // message anyway.
+ tester
+ .send(json!({"id":3,"method":"Runtime.runIfWaitingForDebugger"}))
+ .await;
+ tester
+ .assert_received_messages(&[r#"{"id":3,"result":{}}"#], &[])
+ .await;
+ assert_eq!(&tester.stderr_line(), "Debugger session started.");
+ tokio::time::sleep(tokio::time::Duration::from_millis(300)).await;
+ assert_eq!(&tester.stderr_line(), "did run");
+ assert!(temp_dir.path().join("hello.txt").exists());
+ tester.child.kill().unwrap();
+ }
}
diff --git a/cli/tests/testdata/inspector/inspect_wait.js b/cli/tests/testdata/inspector/inspect_wait.js
new file mode 100644
index 000000000..e2b10199c
--- /dev/null
+++ b/cli/tests/testdata/inspector/inspect_wait.js
@@ -0,0 +1,2 @@
+Deno.writeTextFileSync("./hello.txt", "hello world");
+console.error("did run");