From 71ea4ef2746d7d75623a821d4832d3531a8e1654 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Tue, 10 Jan 2023 15:28:10 +0000 Subject: fix(watch): preserve `ProcState::file_fetcher` between restarts (#15466) This commit changes "ProcState" to store "file_fetcher" field in an "Arc", allowing it to be preserved between restarts and thus keeping the state alive between the restarts. File watchers for "deno test" and "deno bench" now reset "ProcState" between restarts. --- cli/tests/watcher_tests.rs | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'cli/tests') diff --git a/cli/tests/watcher_tests.rs b/cli/tests/watcher_tests.rs index 0b9749e48..a300f3953 100644 --- a/cli/tests/watcher_tests.rs +++ b/cli/tests/watcher_tests.rs @@ -1098,6 +1098,44 @@ mod watcher { check_alive_then_kill(child); } + // Regression test for https://github.com/denoland/deno/issues/15465. + #[test] + fn run_watch_reload_once() { + let _g = util::http_server(); + let t = TempDir::new(); + let file_to_watch = t.path().join("file_to_watch.js"); + let file_content = r#" + import { time } from "http://localhost:4545/dynamic_module.ts"; + console.log(time); + "#; + write(&file_to_watch, file_content).unwrap(); + + let mut child = util::deno_cmd() + .current_dir(util::testdata_path()) + .arg("run") + .arg("--watch") + .arg("--reload") + .arg(&file_to_watch) + .env("NO_COLOR", "1") + .stdout(std::process::Stdio::piped()) + .stderr(std::process::Stdio::piped()) + .spawn() + .unwrap(); + let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child); + + wait_contains("finished", &mut stderr_lines); + let first_output = stdout_lines.next().unwrap(); + + write(&file_to_watch, file_content).unwrap(); + // The remote dynamic module should not have been reloaded again. + + wait_contains("finished", &mut stderr_lines); + let second_output = stdout_lines.next().unwrap(); + assert_eq!(second_output, first_output); + + check_alive_then_kill(child); + } + #[test] fn run_watch_dynamic_imports() { let t = TempDir::new(); @@ -1159,11 +1197,11 @@ mod watcher { &mut stdout_lines, ); - wait_contains("finished", &mut stderr_lines); wait_for( |m| m.contains("Watching paths") && m.contains("imported2.js"), &mut stderr_lines, ); + wait_contains("finished", &mut stderr_lines); write( &file_to_watch3, -- cgit v1.2.3