Skip to content

Commit

Permalink
fix: support watch flag to enable watching other files than the main …
Browse files Browse the repository at this point in the history
…module on serve subcommand (#26622)

Closes #26618
  • Loading branch information
HasanAlrimawi authored and bartlomieju committed Oct 29, 2024
1 parent 36b7f9d commit 1019184
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cli/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1672,6 +1672,10 @@ impl CliOptions {
if let DenoSubcommand::Run(RunFlags {
watch: Some(WatchFlagsWithPaths { paths, .. }),
..
})
| DenoSubcommand::Serve(ServeFlags {
watch: Some(WatchFlagsWithPaths { paths, .. }),
..
}) = &self.flags.subcommand
{
full_paths.extend(paths.iter().map(|path| self.initial_cwd.join(path)));
Expand Down
70 changes: 70 additions & 0 deletions tests/integration/watcher_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1019184

Please sign in to comment.