diff options
-rw-r--r-- | cli/tests/integration_tests.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index dc225e6fd..cd2252681 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -1328,6 +1328,17 @@ fn info_with_compiled_source() { assert_eq!(output.stderr, b""); } +// Helper function to skip watcher output that doesn't contain +// "Process finished" phrase. +fn wait_for_process_finished(stderr_lines: &mut impl Iterator<Item = String>) { + loop { + let msg = stderr_lines.next().unwrap(); + if msg.contains("Process finished") { + break; + } + } +} + #[test] fn run_watch() { let t = TempDir::new().expect("tempdir fail"); @@ -1355,7 +1366,7 @@ fn run_watch() { std::io::BufReader::new(stderr).lines().map(|r| r.unwrap()); assert!(stdout_lines.next().unwrap().contains("Hello world")); - assert!(stderr_lines.next().unwrap().contains("Process finished")); + wait_for_process_finished(&mut stderr_lines); // TODO(lucacasonato): remove this timeout. It seems to be needed on Linux. std::thread::sleep(std::time::Duration::from_secs(1)); @@ -1368,7 +1379,7 @@ fn run_watch() { assert!(stderr_lines.next().unwrap().contains("Restarting")); assert!(stdout_lines.next().unwrap().contains("Hello world2")); - assert!(stderr_lines.next().unwrap().contains("Process finished")); + wait_for_process_finished(&mut stderr_lines); // Add dependency let another_file = t.path().join("another_file.js"); @@ -1382,7 +1393,7 @@ fn run_watch() { std::thread::sleep(std::time::Duration::from_secs(1)); assert!(stderr_lines.next().unwrap().contains("Restarting")); assert!(stdout_lines.next().unwrap().contains('0')); - assert!(stderr_lines.next().unwrap().contains("Process finished")); + wait_for_process_finished(&mut stderr_lines); // Confirm that restarting occurs when a new file is updated std::fs::write(&another_file, "export const foo = 42;") @@ -1390,7 +1401,7 @@ fn run_watch() { std::thread::sleep(std::time::Duration::from_secs(1)); assert!(stderr_lines.next().unwrap().contains("Restarting")); assert!(stdout_lines.next().unwrap().contains("42")); - assert!(stderr_lines.next().unwrap().contains("Process finished")); + wait_for_process_finished(&mut stderr_lines); // Confirm that the watcher keeps on working even if the file is updated and has invalid syntax std::fs::write(&file_to_watch, "syntax error ^^") @@ -1398,7 +1409,7 @@ fn run_watch() { std::thread::sleep(std::time::Duration::from_secs(1)); assert!(stderr_lines.next().unwrap().contains("Restarting")); assert!(stderr_lines.next().unwrap().contains("error:")); - assert!(stderr_lines.next().unwrap().contains("Process finished")); + wait_for_process_finished(&mut stderr_lines); // Then restore the file std::fs::write( @@ -1409,7 +1420,7 @@ fn run_watch() { std::thread::sleep(std::time::Duration::from_secs(1)); assert!(stderr_lines.next().unwrap().contains("Restarting")); assert!(stdout_lines.next().unwrap().contains("42")); - assert!(stderr_lines.next().unwrap().contains("Process finished")); + wait_for_process_finished(&mut stderr_lines); child.kill().unwrap(); drop(t); |