From a3282aa9ed749f2e80618c6e2f25047d9a2bb2d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 11 Sep 2020 18:19:49 +0200 Subject: feat(unstable): deno run --watch (#7382) Co-authored-by: Sebastian Seedorf --- cli/tests/integration_tests.rs | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'cli/tests/integration_tests.rs') diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index e00c7a865..ec13f7380 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -981,6 +981,50 @@ fn info_with_compiled_source() { assert_eq!(output.stderr, b""); } +#[test] +fn run_watch() { + let t = TempDir::new().expect("tempdir fail"); + let file_to_watch = t.path().join("file_to_watch.js"); + std::fs::write(&file_to_watch, "console.log('Hello world');") + .expect("error writing file"); + + let mut child = util::deno_cmd() + .current_dir(util::root_path()) + .arg("run") + .arg("--watch") + .arg("--unstable") + .arg(&file_to_watch) + .env("NO_COLOR", "1") + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::piped()) + .spawn() + .expect("failed to spawn script"); + + let stdout = child.stdout.as_mut().unwrap(); + let mut stdout_lines = + std::io::BufReader::new(stdout).lines().map(|r| r.unwrap()); + let stderr = child.stderr.as_mut().unwrap(); + let mut stderr_lines = + 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 terminated")); + + // TODO(lucacasonato): remove this timeout. It seems to be needed on Linux. + std::thread::sleep(std::time::Duration::from_secs(1)); + + // Change content of the file + std::fs::write(&file_to_watch, "console.log('Hello world2');") + .expect("error writing file"); + + assert!(stderr_lines.next().unwrap().contains("Restarting")); + assert!(stdout_lines.next().unwrap().contains("Hello world2")); + assert!(stderr_lines.next().unwrap().contains("Process terminated")); + + child.kill().unwrap(); + drop(t); +} + #[test] fn repl_test_console_log() { let (out, err) = util::run_and_collect_output( -- cgit v1.2.3