diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-12-06 02:00:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-06 02:00:10 +0100 |
commit | 79285fa83bfbbef55d8afa8f28d11ae4a0b21927 (patch) | |
tree | 0a01c246c71c3dcf175d6d95c2746f5dd4743844 /cli/tests/inspector_tests.rs | |
parent | a7dd28a07c3d018c326636aa563ee4e9200445f8 (diff) |
npm: ensure runtime exceptions are surfaced when debugger is attached (#16943)
Currently runtime exception are only displayed at the program end in
terminal, which makes it only a partial fix, as a full fix requires
https://github.com/denoland/rusty_v8/pull/1149 which adds new bindings
to the inspector that allows to notify it about thrown exceptions.
This will be handled in a follow up commit.
Diffstat (limited to 'cli/tests/inspector_tests.rs')
-rw-r--r-- | cli/tests/inspector_tests.rs | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/cli/tests/inspector_tests.rs b/cli/tests/inspector_tests.rs index fd3e886e4..8a1bc141f 100644 --- a/cli/tests/inspector_tests.rs +++ b/cli/tests/inspector_tests.rs @@ -1303,4 +1303,89 @@ mod inspector { child.kill().unwrap(); child.wait().unwrap(); } + + #[tokio::test] + async fn inspector_error_with_npm_import() { + let script = + util::testdata_path().join("inspector/error_with_npm_import.js"); + let _server = http_server(); + + let mut child = util::deno_cmd() + .arg("run") + .arg("--quiet") + .arg("-A") + .arg(inspect_flag_with_unique_port("--inspect-brk")) + .arg(script) + .envs(util::env_vars_for_npm_tests()) + .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.unwrap(); + 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) + }) + .boxed_local(); + + assert_stderr_for_inspect_brk(&mut stderr_lines); + + assert_inspector_messages( + &mut socket_tx, + &[ + r#"{"id":1,"method":"Runtime.enable"}"#, + r#"{"id":2,"method":"Debugger.enable"}"#, + ], + &mut socket_rx, + &[ + r#"{"id":1,"result":{}}"#, + r#"{"id":2,"result":{"debuggerId":"#, + ], + &[ + r#"{"method":"Runtime.executionContextCreated","params":{"context":{"id":1,"#, + ], + ) + .await; + + assert_inspector_messages( + &mut socket_tx, + &[r#"{"id":3,"method":"Runtime.runIfWaitingForDebugger"}"#], + &mut socket_rx, + &[r#"{"id":3,"result":{}}"#], + &[r#"{"method":"Debugger.paused","#], + ) + .await; + + assert_inspector_messages( + &mut socket_tx, + &[r#"{"id":4,"method":"Debugger.resume"}"#], + &mut socket_rx, + &[r#"{"id":4,"result":{}}"#], + &[], + ) + .await; + + // TODO(bartlomieju): this is a partial fix, we should assert that + // "Runtime.exceptionThrown" notification was sent, but a bindings for this + // notification is not yet there + assert_eq!(&stderr_lines.next().unwrap(), "Debugger session started."); + assert_eq!( + &stderr_lines.next().unwrap(), + "error: Uncaught Error: boom!" + ); + + assert_eq!(child.wait().unwrap().code(), Some(1)); + } } |