summaryrefslogtreecommitdiff
path: root/cli/tests
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests')
-rw-r--r--cli/tests/integration/watcher_tests.rs259
1 files changed, 173 insertions, 86 deletions
diff --git a/cli/tests/integration/watcher_tests.rs b/cli/tests/integration/watcher_tests.rs
index a74b7a6d3..ec2588911 100644
--- a/cli/tests/integration/watcher_tests.rs
+++ b/cli/tests/integration/watcher_tests.rs
@@ -48,15 +48,22 @@ fn read_all_lints(stderr_lines: &mut impl Iterator<Item = String>) -> String {
str
}
-fn wait_for(s: &str, lines: &mut impl Iterator<Item = String>) {
+fn wait_for(
+ condition: impl Fn(&str) -> bool,
+ lines: &mut impl Iterator<Item = String>,
+) {
loop {
let msg = lines.next().unwrap();
- if msg.contains(s) {
+ if condition(&msg) {
break;
}
}
}
+fn wait_contains(s: &str, lines: &mut impl Iterator<Item = String>) {
+ wait_for(|msg| msg.contains(s), lines)
+}
+
fn read_line(s: &str, lines: &mut impl Iterator<Item = String>) -> String {
lines.find(|m| m.contains(s)).unwrap()
}
@@ -408,7 +415,7 @@ fn bundle_js_watch() {
assert_contains!(stderr_lines.next().unwrap(), "mod6.bundle.js");
let file = PathBuf::from(&bundle);
assert!(file.is_file());
- wait_for("Bundle finished", &mut stderr_lines);
+ wait_contains("Bundle finished", &mut stderr_lines);
write(&file_to_watch, "console.log('Hello world2');").unwrap();
@@ -420,14 +427,14 @@ fn bundle_js_watch() {
assert_contains!(stderr_lines.next().unwrap(), "mod6.bundle.js");
let file = PathBuf::from(&bundle);
assert!(file.is_file());
- wait_for("Bundle finished", &mut stderr_lines);
+ wait_contains("Bundle finished", &mut stderr_lines);
// Confirm that the watcher keeps on working even if the file is updated and has invalid syntax
write(&file_to_watch, "syntax error ^^").unwrap();
assert_contains!(stderr_lines.next().unwrap(), "File change detected!");
assert_contains!(stderr_lines.next().unwrap(), "error: ");
- wait_for("Bundle failed", &mut stderr_lines);
+ wait_contains("Bundle failed", &mut stderr_lines);
check_alive_then_kill(deno);
}
@@ -470,15 +477,15 @@ fn bundle_watch_not_exit() {
assert_contains!(stderr_lines.next().unwrap(), "file_to_watch.ts");
assert_contains!(stderr_lines.next().unwrap(), "target.js");
- wait_for("Bundle finished", &mut stderr_lines);
+ wait_contains("Bundle finished", &mut stderr_lines);
// bundled file is created
assert!(target_file.is_file());
check_alive_then_kill(deno);
}
-#[flaky_test::flaky_test]
-fn run_watch() {
+#[test]
+fn run_watch_no_dynamic() {
let t = TempDir::new();
let file_to_watch = t.path().join("file_to_watch.js");
write(&file_to_watch, "console.log('Hello world');").unwrap();
@@ -488,6 +495,8 @@ fn run_watch() {
.arg("run")
.arg("--watch")
.arg("--unstable")
+ .arg("-L")
+ .arg("debug")
.arg(&file_to_watch)
.env("NO_COLOR", "1")
.stdout(std::process::Stdio::piped())
@@ -496,15 +505,21 @@ fn run_watch() {
.unwrap();
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
- assert_contains!(stdout_lines.next().unwrap(), "Hello world");
- wait_for("Process finished", &mut stderr_lines);
+ wait_contains("Hello world", &mut stdout_lines);
+ wait_for(
+ |m| m.contains("Watching paths") && m.contains("file_to_watch.js"),
+ &mut stderr_lines,
+ );
// Change content of the file
write(&file_to_watch, "console.log('Hello world2');").unwrap();
- assert_contains!(stderr_lines.next().unwrap(), "Restarting");
- assert_contains!(stdout_lines.next().unwrap(), "Hello world2");
- wait_for("Process finished", &mut stderr_lines);
+ wait_contains("Restarting", &mut stderr_lines);
+ wait_contains("Hello world2", &mut stdout_lines);
+ wait_for(
+ |m| m.contains("Watching paths") && m.contains("file_to_watch.js"),
+ &mut stderr_lines,
+ );
// Add dependency
let another_file = t.path().join("another_file.js");
@@ -515,23 +530,32 @@ fn run_watch() {
)
.unwrap();
- assert_contains!(stderr_lines.next().unwrap(), "Restarting");
- assert_contains!(stdout_lines.next().unwrap(), '0');
- wait_for("Process finished", &mut stderr_lines);
+ wait_contains("Restarting", &mut stderr_lines);
+ wait_contains("0", &mut stdout_lines);
+ wait_for(
+ |m| m.contains("Watching paths") && m.contains("another_file.js"),
+ &mut stderr_lines,
+ );
// Confirm that restarting occurs when a new file is updated
write(&another_file, "export const foo = 42;").unwrap();
- assert_contains!(stderr_lines.next().unwrap(), "Restarting");
- assert_contains!(stdout_lines.next().unwrap(), "42");
- wait_for("Process finished", &mut stderr_lines);
+ wait_contains("Restarting", &mut stderr_lines);
+ wait_contains("42", &mut stdout_lines);
+ wait_for(
+ |m| m.contains("Watching paths") && m.contains("file_to_watch.js"),
+ &mut stderr_lines,
+ );
// Confirm that the watcher keeps on working even if the file is updated and has invalid syntax
write(&file_to_watch, "syntax error ^^").unwrap();
- assert_contains!(stderr_lines.next().unwrap(), "Restarting");
- assert_contains!(stderr_lines.next().unwrap(), "error:");
- wait_for("Process failed", &mut stderr_lines);
+ wait_contains("Restarting", &mut stderr_lines);
+ wait_contains("error:", &mut stderr_lines);
+ wait_for(
+ |m| m.contains("Watching paths") && m.contains("file_to_watch.js"),
+ &mut stderr_lines,
+ );
// Then restore the file
write(
@@ -540,23 +564,29 @@ fn run_watch() {
)
.unwrap();
- assert_contains!(stderr_lines.next().unwrap(), "Restarting");
- assert_contains!(stdout_lines.next().unwrap(), "42");
- wait_for("Process finished", &mut stderr_lines);
+ wait_contains("Restarting", &mut stderr_lines);
+ wait_contains("42", &mut stdout_lines);
+ wait_for(
+ |m| m.contains("Watching paths") && m.contains("another_file.js"),
+ &mut stderr_lines,
+ );
// Update the content of the imported file with invalid syntax
write(&another_file, "syntax error ^^").unwrap();
- assert_contains!(stderr_lines.next().unwrap(), "Restarting");
- assert_contains!(stderr_lines.next().unwrap(), "error:");
- wait_for("Process failed", &mut stderr_lines);
+ wait_contains("Restarting", &mut stderr_lines);
+ wait_contains("error:", &mut stderr_lines);
+ wait_for(
+ |m| m.contains("Watching paths") && m.contains("another_file.js"),
+ &mut stderr_lines,
+ );
// Modify the imported file and make sure that restarting occurs
write(&another_file, "export const foo = 'modified!';").unwrap();
- assert_contains!(stderr_lines.next().unwrap(), "Restarting");
- assert_contains!(stdout_lines.next().unwrap(), "modified!");
- wait_for("Process finished", &mut stderr_lines);
+ wait_contains("Restarting", &mut stderr_lines);
+ wait_contains("modified!", &mut stdout_lines);
+ wait_contains("Watching paths", &mut stderr_lines);
check_alive_then_kill(child);
}
@@ -581,6 +611,8 @@ fn run_watch_external_watch_files() {
.current_dir(util::testdata_path())
.arg("run")
.arg(watch_arg)
+ .arg("-L")
+ .arg("debug")
.arg("--unstable")
.arg(&file_to_watch)
.env("NO_COLOR", "1")
@@ -589,15 +621,20 @@ fn run_watch_external_watch_files() {
.spawn()
.unwrap();
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
-
- assert_contains!(stdout_lines.next().unwrap(), "Hello world");
- wait_for("Process finished", &mut stderr_lines);
+ wait_contains("Process started", &mut stderr_lines);
+ wait_contains("Hello world", &mut stdout_lines);
+ wait_for(
+ |m| {
+ m.contains("Watching paths") && m.contains("external_file_to_watch.txt")
+ },
+ &mut stderr_lines,
+ );
// Change content of the external file
write(&external_file_to_watch, "Hello world2").unwrap();
- assert_contains!(stderr_lines.next().unwrap(), "Restarting");
- wait_for("Process finished", &mut stderr_lines);
+ wait_contains("Restarting", &mut stderr_lines);
+ wait_contains("Process finished", &mut stderr_lines);
check_alive_then_kill(child);
}
@@ -625,6 +662,8 @@ fn run_watch_load_unload_events() {
.arg("run")
.arg("--watch")
.arg("--unstable")
+ .arg("-L")
+ .arg("debug")
.arg(&file_to_watch)
.env("NO_COLOR", "1")
.env("DENO_FUTURE_CHECK", "1")
@@ -635,7 +674,11 @@ fn run_watch_load_unload_events() {
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
// Wait for the first load event to fire
- assert_contains!(stdout_lines.next().unwrap(), "load");
+ wait_contains("load", &mut stdout_lines);
+ wait_for(
+ |m| m.contains("Watching paths") && m.contains("file_to_watch.js"),
+ &mut stderr_lines,
+ );
// Change content of the file, this time without an interval to keep it alive.
write(
@@ -653,18 +696,16 @@ fn run_watch_load_unload_events() {
.unwrap();
// Wait for the restart
- let next_line = stderr_lines.next().unwrap();
- assert_contains!(&next_line, "Process started");
- assert_contains!(stderr_lines.next().unwrap(), "Restarting");
+ wait_contains("Restarting", &mut stderr_lines);
// Confirm that the unload event was dispatched from the first run
- assert_contains!(stdout_lines.next().unwrap(), "unload");
+ wait_contains("unload", &mut stdout_lines);
// Followed by the load event of the second run
- assert_contains!(stdout_lines.next().unwrap(), "load");
+ wait_contains("load", &mut stdout_lines);
// Which is then unloaded as there is nothing keeping it alive.
- assert_contains!(stdout_lines.next().unwrap(), "unload");
+ wait_contains("unload", &mut stdout_lines);
check_alive_then_kill(child);
}
@@ -680,6 +721,8 @@ fn run_watch_not_exit() {
.arg("run")
.arg("--watch")
.arg("--unstable")
+ .arg("-L")
+ .arg("debug")
.arg(&file_to_watch)
.env("NO_COLOR", "1")
.env("DENO_FUTURE_CHECK", "1")
@@ -689,19 +732,19 @@ fn run_watch_not_exit() {
.unwrap();
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
- let next_line = stderr_lines.next().unwrap();
- assert_contains!(&next_line, "Process started");
- assert_contains!(stderr_lines.next().unwrap(), "error:");
- assert_contains!(stderr_lines.next().unwrap(), "Process failed");
+ wait_contains("Process started", &mut stderr_lines);
+ wait_contains("error:", &mut stderr_lines);
+ wait_for(
+ |m| m.contains("Watching paths") && m.contains("file_to_watch.js"),
+ &mut stderr_lines,
+ );
// Make sure the watcher actually restarts and works fine with the proper syntax
write(&file_to_watch, "console.log(42);").unwrap();
- let next_line = stderr_lines.next().unwrap();
- assert_contains!(&next_line, CLEAR_SCREEN);
- assert_contains!(&next_line, "Restarting");
- assert_contains!(stdout_lines.next().unwrap(), "42");
- wait_for("Process finished", &mut stderr_lines);
+ wait_contains("Restarting", &mut stderr_lines);
+ wait_contains("42", &mut stdout_lines);
+ wait_contains("Process finished", &mut stderr_lines);
check_alive_then_kill(child);
}
@@ -756,7 +799,7 @@ fn run_watch_with_import_map_and_relative_paths() {
check_alive_then_kill(child);
}
-#[flaky_test]
+#[test]
fn test_watch() {
let t = TempDir::new();
@@ -779,7 +822,7 @@ fn test_watch() {
stdout_lines.next().unwrap(),
"0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out"
);
- wait_for("Test finished", &mut stderr_lines);
+ wait_contains("Test finished", &mut stderr_lines);
let foo_file = t.path().join("foo.js");
let bar_file = t.path().join("bar.js");
@@ -806,7 +849,7 @@ fn test_watch() {
stdout_lines.next();
stdout_lines.next();
stdout_lines.next();
- wait_for("Test finished", &mut stderr_lines);
+ wait_contains("Test finished", &mut stderr_lines);
// Change content of the file
write(
@@ -821,7 +864,7 @@ fn test_watch() {
stdout_lines.next();
stdout_lines.next();
stdout_lines.next();
- wait_for("Test finished", &mut stderr_lines);
+ wait_contains("Test finished", &mut stderr_lines);
// Add test
let another_test = t.path().join("new_test.js");
@@ -832,7 +875,7 @@ fn test_watch() {
stdout_lines.next();
stdout_lines.next();
stdout_lines.next();
- wait_for("Test finished", &mut stderr_lines);
+ wait_contains("Test finished", &mut stderr_lines);
// Confirm that restarting occurs when a new file is updated
write(&another_test, "Deno.test('another one', () => 3 + 3); Deno.test('another another one', () => 4 + 4)")
@@ -844,7 +887,7 @@ fn test_watch() {
stdout_lines.next();
stdout_lines.next();
stdout_lines.next();
- wait_for("Test finished", &mut stderr_lines);
+ wait_contains("Test finished", &mut stderr_lines);
// Confirm that the watcher keeps on working even if the file is updated and has invalid syntax
write(&another_test, "syntax error ^^").unwrap();
@@ -860,7 +903,7 @@ fn test_watch() {
stdout_lines.next();
stdout_lines.next();
stdout_lines.next();
- wait_for("Test finished", &mut stderr_lines);
+ wait_contains("Test finished", &mut stderr_lines);
// Confirm that the watcher keeps on working even if the file is updated and the test fails
// This also confirms that it restarts when dependencies change
@@ -872,9 +915,9 @@ fn test_watch() {
assert_contains!(stderr_lines.next().unwrap(), "Restarting");
assert_contains!(stdout_lines.next().unwrap(), "running 1 test");
assert_contains!(stdout_lines.next().unwrap(), "FAILED");
- wait_for("test result", &mut stdout_lines);
+ wait_contains("test result", &mut stdout_lines);
stdout_lines.next();
- wait_for("Test finished", &mut stderr_lines);
+ wait_contains("Test finished", &mut stderr_lines);
// Then restore the file
write(&foo_file, "export default function foo() { 1 + 1 }").unwrap();
@@ -884,7 +927,7 @@ fn test_watch() {
stdout_lines.next();
stdout_lines.next();
stdout_lines.next();
- wait_for("Test finished", &mut stderr_lines);
+ wait_contains("Test finished", &mut stderr_lines);
// Test that circular dependencies work fine
write(
@@ -923,7 +966,7 @@ fn test_watch_doc() {
stdout_lines.next().unwrap(),
"0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out"
);
- wait_for("Test finished", &mut stderr_lines);
+ wait_contains("Test finished", &mut stderr_lines);
let foo_file = t.path().join("foo.ts");
write(
@@ -979,23 +1022,48 @@ fn test_watch_module_graph_error_referrer() {
let line3 = stderr_lines.next().unwrap();
assert_contains!(&line3, " at ");
assert_contains!(&line3, "file_to_watch.js");
- wait_for("Process failed", &mut stderr_lines);
+ wait_contains("Process finished", &mut stderr_lines);
check_alive_then_kill(child);
}
#[test]
-fn watch_with_no_clear_screen_flag() {
+fn run_watch_dynamic_imports() {
let t = TempDir::new();
let file_to_watch = t.path().join("file_to_watch.js");
- write(&file_to_watch, "export const foo = 0;").unwrap();
+ write(
+ &file_to_watch,
+ r#"
+ console.log("Hopefully dynamic import will be watched...");
+ await import("./imported.js");
+ "#,
+ )
+ .unwrap();
+ let file_to_watch2 = t.path().join("imported.js");
+ write(
+ &file_to_watch2,
+ r#"
+ import "./imported2.js";
+ console.log("I'm dynamically imported and I cause restarts!");
+ "#,
+ )
+ .unwrap();
+ let file_to_watch3 = t.path().join("imported2.js");
+ write(
+ &file_to_watch3,
+ r#"
+ console.log("I'm statically imported from the dynamic import");
+ "#,
+ )
+ .unwrap();
- // choose deno run subcommand to test --no-clear-screen flag
let mut child = util::deno_cmd()
.current_dir(util::testdata_path())
.arg("run")
.arg("--watch")
- .arg("--no-clear-screen")
.arg("--unstable")
+ .arg("--allow-read")
+ .arg("-L")
+ .arg("debug")
.arg(&file_to_watch)
.env("NO_COLOR", "1")
.env("DENO_FUTURE_CHECK", "1")
@@ -1003,30 +1071,49 @@ fn watch_with_no_clear_screen_flag() {
.stderr(std::process::Stdio::piped())
.spawn()
.unwrap();
- let (_, mut stderr_lines) = child_lines(&mut child);
+ let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
- let next_line = stderr_lines.next().unwrap();
+ assert_contains!(stderr_lines.next().unwrap(), "Process started");
- // no clear screen
- assert!(!&next_line.contains(CLEAR_SCREEN));
- assert_contains!(&next_line, "Process started");
- assert_contains!(
- stderr_lines.next().unwrap(),
- "Process finished. Restarting on file change..."
+ wait_contains(
+ "Hopefully dynamic import will be watched...",
+ &mut stdout_lines,
+ );
+ wait_contains(
+ "I'm statically imported from the dynamic import",
+ &mut stdout_lines,
+ );
+ wait_contains(
+ "I'm dynamically imported and I cause restarts!",
+ &mut stdout_lines,
);
- // Change content of the file
- write(&file_to_watch, "export const bar = 0;").unwrap();
-
- let next_line = stderr_lines.next().unwrap();
+ wait_contains("finished", &mut stderr_lines);
+ wait_for(
+ |m| m.contains("Watching paths") && m.contains("imported2.js"),
+ &mut stderr_lines,
+ );
- // no clear screen
- assert!(!&next_line.contains(CLEAR_SCREEN));
+ write(
+ &file_to_watch3,
+ r#"
+ console.log("I'm statically imported from the dynamic import and I've changed");
+ "#,
+ )
+ .unwrap();
- assert_contains!(&next_line, "Watcher File change detected! Restarting!");
- assert_contains!(
- stderr_lines.next().unwrap(),
- "Process finished. Restarting on file change..."
+ wait_contains("Restarting", &mut stderr_lines);
+ wait_contains(
+ "Hopefully dynamic import will be watched...",
+ &mut stdout_lines,
+ );
+ wait_contains(
+ "I'm statically imported from the dynamic import and I've changed",
+ &mut stdout_lines,
+ );
+ wait_contains(
+ "I'm dynamically imported and I cause restarts!",
+ &mut stdout_lines,
);
check_alive_then_kill(child);