summaryrefslogtreecommitdiff
path: root/cli/tests/integration
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/integration')
-rw-r--r--cli/tests/integration/watcher_tests.rs100
1 files changed, 98 insertions, 2 deletions
diff --git a/cli/tests/integration/watcher_tests.rs b/cli/tests/integration/watcher_tests.rs
index feda1bac7..ce7848527 100644
--- a/cli/tests/integration/watcher_tests.rs
+++ b/cli/tests/integration/watcher_tests.rs
@@ -55,6 +55,10 @@ fn wait_for(s: &str, lines: &mut impl Iterator<Item = String>) {
}
}
+fn read_line(s: &str, lines: &mut impl Iterator<Item = String>) -> String {
+ lines.find(|m| m.contains(s)).unwrap()
+}
+
fn check_alive_then_kill(mut child: std::process::Child) {
assert!(child.try_wait().unwrap().is_none());
child.kill().unwrap();
@@ -77,6 +81,8 @@ 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_output =
+ util::testdata_path().join("lint/watch/badly_linted.js.out");
let badly_linted_fixed1 =
util::testdata_path().join("lint/watch/badly_linted_fixed1.js");
let badly_linted_fixed1_output =
@@ -86,8 +92,6 @@ fn lint_watch_test() {
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");
@@ -140,6 +144,54 @@ fn lint_watch_test() {
}
#[test]
+fn lint_all_files_on_each_change_test() {
+ let t = TempDir::new().expect("tempdir fail");
+ let badly_linted_fixed0 =
+ 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_fixed2 =
+ util::testdata_path().join("lint/watch/badly_linted_fixed2.js");
+
+ let badly_linted_1 = t.path().join("badly_linted_1.js");
+ let badly_linted_2 = t.path().join("badly_linted_2.js");
+ std::fs::copy(&badly_linted_fixed0, &badly_linted_1)
+ .expect("Failed to copy file");
+ std::fs::copy(&badly_linted_fixed1, &badly_linted_2)
+ .expect("Failed to copy file");
+
+ let mut child = util::deno_cmd()
+ .current_dir(util::testdata_path())
+ .arg("lint")
+ .arg(&t.path())
+ .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());
+
+ std::thread::sleep(std::time::Duration::from_secs(1));
+
+ assert_contains!(read_line("Checked", &mut stderr_lines), "Checked 2 files");
+
+ std::fs::copy(&badly_linted_fixed2, &badly_linted_2)
+ .expect("Failed to copy file");
+ std::thread::sleep(std::time::Duration::from_secs(1));
+
+ assert_contains!(read_line("Checked", &mut stderr_lines), "Checked 2 files");
+
+ 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");
@@ -181,6 +233,50 @@ fn fmt_watch_test() {
}
#[test]
+fn fmt_check_all_files_on_each_change_test() {
+ let t = TempDir::new().unwrap();
+ let badly_formatted_original =
+ util::testdata_path().join("badly_formatted.mjs");
+ let badly_formatted_1 = t.path().join("badly_formatted_1.js");
+ let badly_formatted_2 = t.path().join("badly_formatted_2.js");
+ std::fs::copy(&badly_formatted_original, &badly_formatted_1).unwrap();
+ std::fs::copy(&badly_formatted_original, &badly_formatted_2).unwrap();
+
+ let mut child = util::deno_cmd()
+ .current_dir(util::testdata_path())
+ .arg("fmt")
+ .arg(&t.path())
+ .arg("--watch")
+ .arg("--check")
+ .arg("--unstable")
+ .stdout(std::process::Stdio::piped())
+ .stderr(std::process::Stdio::piped())
+ .spawn()
+ .unwrap();
+ let (_stdout_lines, mut stderr_lines) = child_lines(&mut child);
+
+ // TODO(lucacasonato): remove this timeout. It seems to be needed on Linux.
+ std::thread::sleep(std::time::Duration::from_secs(1));
+
+ assert_contains!(
+ read_line("error", &mut stderr_lines),
+ "Found 2 not formatted files in 2 files"
+ );
+
+ // Change content of the file again to be badly formatted
+ std::fs::copy(&badly_formatted_original, &badly_formatted_1).unwrap();
+
+ std::thread::sleep(std::time::Duration::from_secs(1));
+
+ assert_contains!(
+ read_line("error", &mut stderr_lines),
+ "Found 2 not formatted files in 2 files"
+ );
+
+ check_alive_then_kill(child);
+}
+
+#[test]
fn bundle_js_watch() {
use std::path::PathBuf;
// Test strategy extends this of test bundle_js by adding watcher