mirror of
https://github.com/denoland/deno.git
synced 2024-12-21 23:04:45 -05:00
fix(test): wait for inspector session in side modules (#13065)
This commit fixes inspector integration with "deno test" subcommand by waiting for inspector sessions to connect if "--inspect-brk" flag is passed. Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
parent
f0e1a6b84c
commit
0f53b82cd2
3 changed files with 77 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
|
|
3
cli/tests/testdata/inspector_test.js
vendored
Normal file
3
cli/tests/testdata/inspector_test.js
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
Deno.test("basic test", () => {
|
||||
console.log("test has finished running");
|
||||
});
|
|
@ -229,6 +229,7 @@ impl MainWorker {
|
|||
module_specifier: &ModuleSpecifier,
|
||||
) -> Result<(), AnyError> {
|
||||
let id = self.preload_module(module_specifier, false).await?;
|
||||
self.wait_for_inspector_session();
|
||||
self.evaluate_module(id).await
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue