From 3b28446000d8d063c07ef320314ef493a9e0bffa Mon Sep 17 00:00:00 2001 From: HasanAlrimawi <141642411+HasanAlrimawi@users.noreply.github.com> Date: Tue, 29 Oct 2024 23:55:41 +0200 Subject: fix: support watch flag to enable watching other files than the main module on serve subcommand (#26622) Closes #26618 --- tests/integration/watcher_tests.rs | 70 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'tests/integration/watcher_tests.rs') diff --git a/tests/integration/watcher_tests.rs b/tests/integration/watcher_tests.rs index 122353bba..d4705b8d5 100644 --- a/tests/integration/watcher_tests.rs +++ b/tests/integration/watcher_tests.rs @@ -566,6 +566,76 @@ async fn run_watch_no_dynamic() { check_alive_then_kill(child); } +#[flaky_test(tokio)] +async fn serve_watch_all() { + let t = TempDir::new(); + let main_file_to_watch = t.path().join("main_file_to_watch.js"); + main_file_to_watch.write( + "export default { + fetch(_request: Request) { + return new Response(\"aaaaaaqqq!\"); + }, + };", + ); + + let mut child = util::deno_cmd() + .current_dir(t.path()) + .arg("serve") + .arg("--watch=another_file.js") + .arg("-L") + .arg("debug") + .arg(&main_file_to_watch) + .env("NO_COLOR", "1") + .piped_output() + .spawn() + .unwrap(); + let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child); + + wait_for_watcher("main_file_to_watch.js", &mut stderr_lines).await; + + // Change content of the file + main_file_to_watch.write( + "export default { + fetch(_request: Request) { + return new Response(\"aaaaaaqqq123!\"); + }, + };", + ); + wait_contains("Restarting", &mut stderr_lines).await; + wait_for_watcher("main_file_to_watch.js", &mut stderr_lines).await; + + let another_file = t.path().join("another_file.js"); + another_file.write("export const foo = 0;"); + // Confirm that the added file is watched as well + wait_contains("Restarting", &mut stderr_lines).await; + + main_file_to_watch + .write("import { foo } from './another_file.js'; console.log(foo);"); + wait_contains("Restarting", &mut stderr_lines).await; + wait_contains("0", &mut stdout_lines).await; + + another_file.write("export const foo = 42;"); + wait_contains("Restarting", &mut stderr_lines).await; + wait_contains("42", &mut stdout_lines).await; + + // Confirm that watch continues even with wrong syntax error + another_file.write("syntax error ^^"); + + wait_contains("Restarting", &mut stderr_lines).await; + wait_contains("error:", &mut stderr_lines).await; + + main_file_to_watch.write( + "export default { + fetch(_request: Request) { + return new Response(\"aaaaaaqqq!\"); + }, + };", + ); + wait_contains("Restarting", &mut stderr_lines).await; + wait_for_watcher("main_file_to_watch.js", &mut stderr_lines).await; + check_alive_then_kill(child); +} + #[flaky_test(tokio)] async fn run_watch_npm_specifier() { let _g = util::http_server(); -- cgit v1.2.3 From 44eca0505c35201c6b67ba073834402b7681914f Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:09:17 -0800 Subject: chore: fix serve_watch_all test (#26725) It's been failing a ton lately, it looks like the test is just incorrectly using TS syntax in a JS file https://github.com/denoland/deno/actions/runs/11672972415/job/32502710624?pr=26724#step:43:2791 I'm not really sure how this ever passes --- tests/integration/watcher_tests.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'tests/integration/watcher_tests.rs') diff --git a/tests/integration/watcher_tests.rs b/tests/integration/watcher_tests.rs index d4705b8d5..e8f264632 100644 --- a/tests/integration/watcher_tests.rs +++ b/tests/integration/watcher_tests.rs @@ -572,16 +572,19 @@ async fn serve_watch_all() { let main_file_to_watch = t.path().join("main_file_to_watch.js"); main_file_to_watch.write( "export default { - fetch(_request: Request) { + fetch(_request) { return new Response(\"aaaaaaqqq!\"); }, };", ); + let another_file = t.path().join("another_file.js"); + another_file.write(""); + let mut child = util::deno_cmd() .current_dir(t.path()) .arg("serve") - .arg("--watch=another_file.js") + .arg(format!("--watch={another_file}")) .arg("-L") .arg("debug") .arg(&main_file_to_watch) @@ -596,7 +599,7 @@ async fn serve_watch_all() { // Change content of the file main_file_to_watch.write( "export default { - fetch(_request: Request) { + fetch(_request) { return new Response(\"aaaaaaqqq123!\"); }, };", @@ -604,18 +607,20 @@ async fn serve_watch_all() { wait_contains("Restarting", &mut stderr_lines).await; wait_for_watcher("main_file_to_watch.js", &mut stderr_lines).await; - let another_file = t.path().join("another_file.js"); another_file.write("export const foo = 0;"); // Confirm that the added file is watched as well wait_contains("Restarting", &mut stderr_lines).await; + wait_for_watcher("main_file_to_watch.js", &mut stderr_lines).await; main_file_to_watch .write("import { foo } from './another_file.js'; console.log(foo);"); wait_contains("Restarting", &mut stderr_lines).await; + wait_for_watcher("main_file_to_watch.js", &mut stderr_lines).await; wait_contains("0", &mut stdout_lines).await; another_file.write("export const foo = 42;"); wait_contains("Restarting", &mut stderr_lines).await; + wait_for_watcher("main_file_to_watch.js", &mut stderr_lines).await; wait_contains("42", &mut stdout_lines).await; // Confirm that watch continues even with wrong syntax error @@ -623,10 +628,11 @@ async fn serve_watch_all() { wait_contains("Restarting", &mut stderr_lines).await; wait_contains("error:", &mut stderr_lines).await; + wait_for_watcher("main_file_to_watch.js", &mut stderr_lines).await; main_file_to_watch.write( "export default { - fetch(_request: Request) { + fetch(_request) { return new Response(\"aaaaaaqqq!\"); }, };", -- cgit v1.2.3 From abf06eb87f10ebed93b39948213dccfe086bd0fa Mon Sep 17 00:00:00 2001 From: HasanAlrimawi <141642411+HasanAlrimawi@users.noreply.github.com> Date: Sat, 16 Nov 2024 16:59:31 +0200 Subject: feat(watch): log which file changed on HMR or watch change (#25801) Closes #25504 --- tests/integration/watcher_tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/integration/watcher_tests.rs') diff --git a/tests/integration/watcher_tests.rs b/tests/integration/watcher_tests.rs index e8f264632..055e46af9 100644 --- a/tests/integration/watcher_tests.rs +++ b/tests/integration/watcher_tests.rs @@ -55,7 +55,7 @@ where let mut str = String::new(); while let Some(t) = next_line(stderr_lines).await { let t = util::strip_ansi_codes(&t); - if t.starts_with("Watcher File change detected") { + if t.starts_with("Watcher Restarting! File change detected") { continue; } if t.starts_with("Watcher") { -- cgit v1.2.3