summaryrefslogtreecommitdiff
path: root/cli/tests/integration/watcher_tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/integration/watcher_tests.rs')
-rw-r--r--cli/tests/integration/watcher_tests.rs85
1 files changed, 85 insertions, 0 deletions
diff --git a/cli/tests/integration/watcher_tests.rs b/cli/tests/integration/watcher_tests.rs
index 4cccfc83f..6148bcf2b 100644
--- a/cli/tests/integration/watcher_tests.rs
+++ b/cli/tests/integration/watcher_tests.rs
@@ -28,6 +28,24 @@ fn skip_restarting_line(
}
}
+fn read_all_lints(stderr_lines: &mut impl Iterator<Item = String>) -> String {
+ let mut str = String::new();
+ for t in stderr_lines {
+ let t = util::strip_ansi_codes(&t);
+ if t.starts_with("Watcher File change detected") {
+ continue;
+ }
+ if t.starts_with("Watcher") {
+ break;
+ }
+ if t.starts_with('(') {
+ str.push_str(&t);
+ str.push('\n');
+ }
+ }
+ str
+}
+
fn wait_for(s: &str, lines: &mut impl Iterator<Item = String>) {
loop {
let msg = lines.next().unwrap();
@@ -55,6 +73,73 @@ fn child_lines(
}
#[test]
+fn lint_watch_test() {
+ let t = TempDir::new().expect("tempdir fail");
+ let badly_linted_original =
+ util::testdata_path().join("lint/watch/badly_linted.js");
+ let badly_linted_fixed1 =
+ util::testdata_path().join("lint/watch/badly_linted_fixed1.js");
+ let badly_linted_fixed1_output =
+ util::testdata_path().join("lint/watch/badly_linted_fixed1.js.out");
+ let badly_linted_fixed2 =
+ util::testdata_path().join("lint/watch/badly_linted_fixed2.js");
+ let badly_linted_fixed2_output =
+ util::testdata_path().join("lint/watch/badly_linted_fixed2.js.out");
+ let badly_linted = t.path().join("badly_linted.js");
+ let badly_linted_output =
+ util::testdata_path().join("lint/watch/badly_linted.js.out");
+
+ std::fs::copy(&badly_linted_original, &badly_linted)
+ .expect("Failed to copy file");
+
+ let mut child = util::deno_cmd()
+ .current_dir(util::testdata_path())
+ .arg("lint")
+ .arg(&badly_linted)
+ .arg("--watch")
+ .arg("--unstable")
+ .stdout(std::process::Stdio::piped())
+ .stderr(std::process::Stdio::piped())
+ .spawn()
+ .expect("Failed to spawn script");
+ let mut stderr = child.stderr.as_mut().unwrap();
+ let mut stderr_lines = std::io::BufReader::new(&mut stderr)
+ .lines()
+ .map(|r| r.unwrap());
+
+ // TODO(lucacasonato): remove this timeout. It seems to be needed on Linux.
+ std::thread::sleep(std::time::Duration::from_secs(1));
+
+ let mut output = read_all_lints(&mut stderr_lines);
+ let expected = std::fs::read_to_string(badly_linted_output).unwrap();
+ assert_eq!(expected, output);
+
+ // Change content of the file again to be badly-linted1
+ std::fs::copy(&badly_linted_fixed1, &badly_linted)
+ .expect("Failed to copy file");
+ std::thread::sleep(std::time::Duration::from_secs(1));
+
+ output = read_all_lints(&mut stderr_lines);
+ let expected = std::fs::read_to_string(badly_linted_fixed1_output).unwrap();
+ assert_eq!(expected, output);
+
+ // Change content of the file again to be badly-linted1
+ std::fs::copy(&badly_linted_fixed2, &badly_linted)
+ .expect("Failed to copy file");
+ std::thread::sleep(std::time::Duration::from_secs(1));
+
+ output = read_all_lints(&mut stderr_lines);
+ let expected = std::fs::read_to_string(badly_linted_fixed2_output).unwrap();
+ assert_eq!(expected, output);
+
+ // the watcher process is still alive
+ assert!(child.try_wait().unwrap().is_none());
+
+ child.kill().unwrap();
+ drop(t);
+}
+
+#[test]
fn fmt_watch_test() {
let t = TempDir::new().unwrap();
let fixed = util::testdata_path().join("badly_formatted_fixed.js");