-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(watch): support watching external files #13087
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ae4f843
feat(watch): support watching external files
jespertheend e58cf42
test(watch) add external watch files test
jespertheend 0fc1d44
lint
jespertheend b026f46
Change —help text
jespertheend 316a5ea
Lint
jespertheend 5146e77
Only take values in `--watch` for `run` command
jespertheend 7b9d622
Cleanup watch arg parsing
jespertheend c1d6655
test(watch): add run_watch_with_external test
jespertheend f1d0009
Format
jespertheend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -575,6 +575,47 @@ fn run_watch() { | |
check_alive_then_kill(child); | ||
} | ||
|
||
#[test] | ||
fn run_watch_external_watch_files() { | ||
let t = TempDir::new().unwrap(); | ||
let file_to_watch = t.path().join("file_to_watch.js"); | ||
write(&file_to_watch, "console.log('Hello world');").unwrap(); | ||
|
||
let external_file_to_watch = t.path().join("external_file_to_watch.txt"); | ||
write(&external_file_to_watch, "Hello world").unwrap(); | ||
|
||
let mut watch_arg = "--watch=".to_owned(); | ||
let external_file_to_watch_str = external_file_to_watch | ||
.clone() | ||
.into_os_string() | ||
.into_string() | ||
.unwrap(); | ||
watch_arg.push_str(&external_file_to_watch_str); | ||
|
||
let mut child = util::deno_cmd() | ||
.current_dir(util::testdata_path()) | ||
.arg("run") | ||
.arg(watch_arg) | ||
.arg("--unstable") | ||
.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); | ||
|
||
assert_contains!(stdout_lines.next().unwrap(), "Hello world"); | ||
wait_for("Process finished", &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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to see what happens with the test if watching doesn't work correctly, it seems like the test will hang forever in this case. Not sure if this is an issue. |
||
check_alive_then_kill(child); | ||
} | ||
|
||
#[test] | ||
fn run_watch_load_unload_events() { | ||
let t = TempDir::new().unwrap(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this still work with
deno run --watch
? Is there a unit test that covers this case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I see no unit test that covers
deno run --watch=file1,file2
, could you add it @jespertheend?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
deno/cli/tests/integration/watcher_tests.rs
Line 734 in 6c324ac
deno run --watch
. But now that I think about it, it seems like this shouldn't work. I'll investigate.I'll also add the extra test 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah this works because
matches.values_of
returns an empty vec when used as--watch
without any files.I've added the extra unit test.