summaryrefslogtreecommitdiff
path: root/tests/integration/watcher_tests.rs
diff options
context:
space:
mode:
authorƁukasz Czerniawski <33061335+lczerniawski@users.noreply.github.com>2024-03-27 23:47:46 +0100
committerGitHub <noreply@github.com>2024-03-27 22:47:46 +0000
commit08d5d32dfccc4dc38c2aa95c81229bf031d3ac7f (patch)
treefea28ed1489f468e1e7b26b7c6d93117fb469eb8 /tests/integration/watcher_tests.rs
parentd31f2307eee6e2a0f96342a58159d265ea03c58e (diff)
feat: add `--watch-exclude` flag (#21935)
This PR introduces the ability to exclude certain paths from the file watcher in Deno. This is particularly useful when running scripts in watch mode, as it allows developers to prevent unnecessary restarts when changes are made to files that do not affect the running script, or when executing scripts that generate new files which results in an infinite restart loop. --------- Co-authored-by: David Sherret <dsherret@gmail.com>
Diffstat (limited to 'tests/integration/watcher_tests.rs')
-rw-r--r--tests/integration/watcher_tests.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/integration/watcher_tests.rs b/tests/integration/watcher_tests.rs
index 6a2cab08a..6d18ad2f4 100644
--- a/tests/integration/watcher_tests.rs
+++ b/tests/integration/watcher_tests.rs
@@ -1614,6 +1614,45 @@ async fn run_watch_inspect() {
}
#[tokio::test]
+async fn run_watch_with_excluded_paths() {
+ let t = TempDir::new();
+
+ let file_to_exclude = t.path().join("file_to_exclude.js");
+ file_to_exclude.write("export const foo = 0;");
+
+ let file_to_watch = t.path().join("file_to_watch.js");
+ file_to_watch
+ .write("import { foo } from './file_to_exclude.js'; console.log(foo);");
+
+ let mjs_file_to_exclude = t.path().join("file_to_exclude.mjs");
+ mjs_file_to_exclude.write("export const foo = 0;");
+
+ let mut child = util::deno_cmd()
+ .current_dir(util::testdata_path())
+ .arg("run")
+ .arg("--watch")
+ .arg("--watch-exclude=file_to_exclude.js,*.mjs")
+ .arg("-L")
+ .arg("debug")
+ .arg(&file_to_watch)
+ .env("NO_COLOR", "1")
+ .piped_output()
+ .spawn()
+ .unwrap();
+ let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
+
+ wait_contains("0", &mut stdout_lines).await;
+ wait_for_watcher("file_to_watch.js", &mut stderr_lines).await;
+
+ // Confirm that restarting doesn't occurs when a excluded file is updated
+ file_to_exclude.write("export const foo = 42;");
+ mjs_file_to_exclude.write("export const foo = 42;");
+
+ wait_contains("finished", &mut stderr_lines).await;
+ check_alive_then_kill(child);
+}
+
+#[tokio::test]
async fn run_hmr_server() {
let t = TempDir::new();
let file_to_watch = t.path().join("file_to_watch.js");