diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/inspector_tests.rs | 85 | ||||
-rw-r--r-- | cli/tests/testdata/inspector/error_with_npm_import.js | 7 |
2 files changed, 92 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)); + } } diff --git a/cli/tests/testdata/inspector/error_with_npm_import.js b/cli/tests/testdata/inspector/error_with_npm_import.js new file mode 100644 index 000000000..9244f2cf2 --- /dev/null +++ b/cli/tests/testdata/inspector/error_with_npm_import.js @@ -0,0 +1,7 @@ +// deno-lint-ignore-file + +import chalk from "npm:chalk"; + +console.log("hello"); + +throw new Error("boom!"); |