2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
use flaky_test::flaky_test;
|
|
|
|
use test_util as util;
|
|
|
|
use test_util::assert_contains;
|
2024-08-14 09:21:11 -04:00
|
|
|
use test_util::env_vars_for_npm_tests;
|
2023-01-12 20:59:13 -05:00
|
|
|
use test_util::TempDir;
|
2023-04-17 09:49:03 -04:00
|
|
|
use tokio::io::AsyncBufReadExt;
|
feat(core): initialize SQLite off-main-thread (#18401)
This gets SQLite off the flamegraph and reduces initialization time by
somewhere between 0.2ms and 0.5ms. In addition, I took the opportunity
to move all the cache management code to a single place and reduce
duplication. While the PR has a net gain of lines, much of that is just
being a bit more deliberate with how we're recovering from errors.
The existing caches had various policies for dealing with cache
corruption, so I've unified them and tried to isolate the decisions we
make for recovery in a single place (see `open_connection` in
`CacheDB`). The policy I chose was:
1. Retry twice to open on-disk caches
2. If that fails, try to delete the file and recreate it on-disk
3. If we fail to delete the file or re-create a new cache, use a
fallback strategy that can be chosen per-cache: InMemory (temporary
cache for the process run), BlackHole (ignore writes, return empty
reads), or Error (fail on every operation).
The caches all use the same general code now, and share the cache
failure recovery policy.
In addition, it cleans up a TODO in the `NodeAnalysisCache`.
2023-03-27 18:01:52 -04:00
|
|
|
use util::DenoChild;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
use util::assert_not_contains;
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
/// Logs to stderr every time next_line() is called
|
|
|
|
struct LoggingLines<R>
|
|
|
|
where
|
|
|
|
R: tokio::io::AsyncBufRead + Unpin,
|
|
|
|
{
|
|
|
|
pub lines: tokio::io::Lines<R>,
|
|
|
|
pub stream_name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<R> LoggingLines<R>
|
|
|
|
where
|
|
|
|
R: tokio::io::AsyncBufRead + Unpin,
|
|
|
|
{
|
|
|
|
pub async fn next_line(&mut self) -> tokio::io::Result<Option<String>> {
|
|
|
|
let line = self.lines.next_line().await;
|
|
|
|
eprintln!(
|
|
|
|
"{}: {}",
|
|
|
|
self.stream_name,
|
|
|
|
line.as_ref().unwrap().clone().unwrap()
|
|
|
|
);
|
|
|
|
line
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
// Helper function to skip watcher output that contains "Restarting"
|
|
|
|
// phrase.
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn skip_restarting_line<R>(stderr_lines: &mut LoggingLines<R>) -> String
|
|
|
|
where
|
|
|
|
R: tokio::io::AsyncBufRead + Unpin,
|
|
|
|
{
|
2023-01-12 20:59:13 -05:00
|
|
|
loop {
|
2023-04-17 09:49:03 -04:00
|
|
|
let msg = next_line(stderr_lines).await.unwrap();
|
2023-01-12 20:59:13 -05:00
|
|
|
if !msg.contains("Restarting") {
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn read_all_lints<R>(stderr_lines: &mut LoggingLines<R>) -> String
|
|
|
|
where
|
|
|
|
R: tokio::io::AsyncBufRead + Unpin,
|
|
|
|
{
|
2023-01-12 20:59:13 -05:00
|
|
|
let mut str = String::new();
|
2023-04-17 09:49:03 -04:00
|
|
|
while let Some(t) = next_line(stderr_lines).await {
|
2023-01-12 20:59:13 -05:00
|
|
|
let t = util::strip_ansi_codes(&t);
|
|
|
|
if t.starts_with("Watcher File change detected") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if t.starts_with("Watcher") {
|
|
|
|
break;
|
|
|
|
}
|
2024-01-23 10:37:43 -05:00
|
|
|
if t.starts_with("error[") {
|
2023-01-12 20:59:13 -05:00
|
|
|
str.push_str(&t);
|
|
|
|
str.push('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
str
|
|
|
|
}
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn next_line<R>(lines: &mut LoggingLines<R>) -> Option<String>
|
|
|
|
where
|
|
|
|
R: tokio::io::AsyncBufRead + Unpin,
|
|
|
|
{
|
|
|
|
let timeout = tokio::time::Duration::from_secs(60);
|
|
|
|
|
|
|
|
tokio::time::timeout(timeout, lines.next_line())
|
|
|
|
.await
|
|
|
|
.unwrap_or_else(|_| {
|
|
|
|
panic!(
|
|
|
|
"Output did not contain a new line after {} seconds",
|
|
|
|
timeout.as_secs()
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the matched line or None if there are no more lines in this stream
|
|
|
|
async fn wait_for<R>(
|
2023-01-12 20:59:13 -05:00
|
|
|
condition: impl Fn(&str) -> bool,
|
2023-04-17 09:49:03 -04:00
|
|
|
lines: &mut LoggingLines<R>,
|
|
|
|
) -> Option<String>
|
|
|
|
where
|
|
|
|
R: tokio::io::AsyncBufRead + Unpin,
|
|
|
|
{
|
|
|
|
while let Some(line) = lines.next_line().await.unwrap() {
|
|
|
|
if condition(line.as_str()) {
|
|
|
|
return Some(line);
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
}
|
2023-04-17 09:49:03 -04:00
|
|
|
|
|
|
|
None
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn wait_contains<R>(s: &str, lines: &mut LoggingLines<R>) -> String
|
|
|
|
where
|
|
|
|
R: tokio::io::AsyncBufRead + Unpin,
|
|
|
|
{
|
|
|
|
let timeout = tokio::time::Duration::from_secs(60);
|
|
|
|
|
|
|
|
tokio::time::timeout(timeout, wait_for(|line| line.contains(s), lines))
|
|
|
|
.await
|
|
|
|
.unwrap_or_else(|_| {
|
|
|
|
panic!(
|
|
|
|
"Output did not contain \"{}\" after {} seconds",
|
|
|
|
s,
|
|
|
|
timeout.as_secs()
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.unwrap_or_else(|| panic!("Output ended without containing \"{}\"", s))
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
2023-03-22 10:15:53 -04:00
|
|
|
/// Before test cases touch files, they need to wait for the watcher to be
|
|
|
|
/// ready. Waiting for subcommand output is insufficient.
|
|
|
|
/// The file watcher takes a moment to start watching files due to
|
|
|
|
/// asynchronicity. It is possible for the watched subcommand to finish before
|
|
|
|
/// any files are being watched.
|
|
|
|
/// deno must be running with --log-level=debug
|
|
|
|
/// file_name should be the file name and, optionally, extension. file_name
|
|
|
|
/// may not be a full path, as it is not portable.
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn wait_for_watcher<R>(
|
2023-03-22 10:15:53 -04:00
|
|
|
file_name: &str,
|
2023-04-17 09:49:03 -04:00
|
|
|
stderr_lines: &mut LoggingLines<R>,
|
|
|
|
) -> String
|
|
|
|
where
|
|
|
|
R: tokio::io::AsyncBufRead + Unpin,
|
|
|
|
{
|
|
|
|
let timeout = tokio::time::Duration::from_secs(60);
|
|
|
|
|
|
|
|
tokio::time::timeout(
|
|
|
|
timeout,
|
|
|
|
wait_for(
|
|
|
|
|line| line.contains("Watching paths") && line.contains(file_name),
|
|
|
|
stderr_lines,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.unwrap_or_else(|_| {
|
|
|
|
panic!(
|
|
|
|
"Watcher did not start for file \"{}\" after {} seconds",
|
|
|
|
file_name,
|
|
|
|
timeout.as_secs()
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.unwrap_or_else(|| {
|
|
|
|
panic!(
|
|
|
|
"Output ended without before the watcher started watching file \"{}\"",
|
|
|
|
file_name
|
|
|
|
)
|
|
|
|
})
|
2023-01-12 20:59:13 -05:00
|
|
|
}
|
|
|
|
|
feat(core): initialize SQLite off-main-thread (#18401)
This gets SQLite off the flamegraph and reduces initialization time by
somewhere between 0.2ms and 0.5ms. In addition, I took the opportunity
to move all the cache management code to a single place and reduce
duplication. While the PR has a net gain of lines, much of that is just
being a bit more deliberate with how we're recovering from errors.
The existing caches had various policies for dealing with cache
corruption, so I've unified them and tried to isolate the decisions we
make for recovery in a single place (see `open_connection` in
`CacheDB`). The policy I chose was:
1. Retry twice to open on-disk caches
2. If that fails, try to delete the file and recreate it on-disk
3. If we fail to delete the file or re-create a new cache, use a
fallback strategy that can be chosen per-cache: InMemory (temporary
cache for the process run), BlackHole (ignore writes, return empty
reads), or Error (fail on every operation).
The caches all use the same general code now, and share the cache
failure recovery policy.
In addition, it cleans up a TODO in the `NodeAnalysisCache`.
2023-03-27 18:01:52 -04:00
|
|
|
fn check_alive_then_kill(mut child: DenoChild) {
|
2023-01-12 20:59:13 -05:00
|
|
|
assert!(child.try_wait().unwrap().is_none());
|
|
|
|
child.kill().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn child_lines(
|
|
|
|
child: &mut std::process::Child,
|
2023-04-17 09:49:03 -04:00
|
|
|
) -> (
|
|
|
|
LoggingLines<tokio::io::BufReader<tokio::process::ChildStdout>>,
|
|
|
|
LoggingLines<tokio::io::BufReader<tokio::process::ChildStderr>>,
|
|
|
|
) {
|
|
|
|
let stdout_lines = LoggingLines {
|
|
|
|
lines: tokio::io::BufReader::new(
|
|
|
|
tokio::process::ChildStdout::from_std(child.stdout.take().unwrap())
|
|
|
|
.unwrap(),
|
|
|
|
)
|
|
|
|
.lines(),
|
|
|
|
stream_name: "STDOUT".to_string(),
|
|
|
|
};
|
|
|
|
let stderr_lines = LoggingLines {
|
|
|
|
lines: tokio::io::BufReader::new(
|
|
|
|
tokio::process::ChildStderr::from_std(child.stderr.take().unwrap())
|
|
|
|
.unwrap(),
|
|
|
|
)
|
|
|
|
.lines(),
|
|
|
|
stream_name: "STDERR".to_string(),
|
|
|
|
};
|
2023-01-12 20:59:13 -05:00
|
|
|
(stdout_lines, stderr_lines)
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn lint_watch_test() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let t = TempDir::new();
|
|
|
|
let badly_linted_original =
|
|
|
|
util::testdata_path().join("lint/watch/badly_linted.js");
|
|
|
|
let badly_linted_output =
|
|
|
|
util::testdata_path().join("lint/watch/badly_linted.js.out");
|
|
|
|
let badly_linted_fixed1 =
|
|
|
|
util::testdata_path().join("lint/watch/badly_linted_fixed1.js");
|
|
|
|
let badly_linted_fixed1_output =
|
|
|
|
util::testdata_path().join("lint/watch/badly_linted_fixed1.js.out");
|
|
|
|
let badly_linted_fixed2 =
|
|
|
|
util::testdata_path().join("lint/watch/badly_linted_fixed2.js");
|
|
|
|
let badly_linted_fixed2_output =
|
|
|
|
util::testdata_path().join("lint/watch/badly_linted_fixed2.js.out");
|
|
|
|
let badly_linted = t.path().join("badly_linted.js");
|
|
|
|
|
2024-05-03 17:31:12 -04:00
|
|
|
badly_linted_original.copy(&badly_linted);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.arg("lint")
|
|
|
|
.arg(&badly_linted)
|
|
|
|
.arg("--watch")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (_stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
2023-04-17 09:49:03 -04:00
|
|
|
let next_line = next_line(&mut stderr_lines).await.unwrap();
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_contains!(&next_line, "Lint started");
|
2023-04-17 09:49:03 -04:00
|
|
|
let mut output = read_all_lints(&mut stderr_lines).await;
|
2024-05-03 17:31:12 -04:00
|
|
|
let expected = badly_linted_output.read_to_string();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_eq!(output, expected);
|
|
|
|
|
|
|
|
// Change content of the file again to be badly-linted
|
2024-05-03 17:31:12 -04:00
|
|
|
badly_linted_fixed1.copy(&badly_linted);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
output = read_all_lints(&mut stderr_lines).await;
|
2024-05-03 17:31:12 -04:00
|
|
|
let expected = badly_linted_fixed1_output.read_to_string();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_eq!(output, expected);
|
|
|
|
|
|
|
|
// Change content of the file again to be badly-linted
|
2024-05-03 17:31:12 -04:00
|
|
|
badly_linted_fixed2.copy(&badly_linted);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
output = read_all_lints(&mut stderr_lines).await;
|
2024-05-03 17:31:12 -04:00
|
|
|
let expected = badly_linted_fixed2_output.read_to_string();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_eq!(output, expected);
|
|
|
|
|
|
|
|
// the watcher process is still alive
|
|
|
|
assert!(child.try_wait().unwrap().is_none());
|
|
|
|
|
|
|
|
child.kill().unwrap();
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn lint_watch_without_args_test() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let t = TempDir::new();
|
|
|
|
let badly_linted_original =
|
|
|
|
util::testdata_path().join("lint/watch/badly_linted.js");
|
|
|
|
let badly_linted_output =
|
|
|
|
util::testdata_path().join("lint/watch/badly_linted.js.out");
|
|
|
|
let badly_linted_fixed1 =
|
|
|
|
util::testdata_path().join("lint/watch/badly_linted_fixed1.js");
|
|
|
|
let badly_linted_fixed1_output =
|
|
|
|
util::testdata_path().join("lint/watch/badly_linted_fixed1.js.out");
|
|
|
|
let badly_linted_fixed2 =
|
|
|
|
util::testdata_path().join("lint/watch/badly_linted_fixed2.js");
|
|
|
|
let badly_linted_fixed2_output =
|
|
|
|
util::testdata_path().join("lint/watch/badly_linted_fixed2.js.out");
|
|
|
|
let badly_linted = t.path().join("badly_linted.js");
|
|
|
|
|
2024-05-03 17:31:12 -04:00
|
|
|
badly_linted_original.copy(&badly_linted);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
|
|
|
.current_dir(t.path())
|
|
|
|
.arg("lint")
|
|
|
|
.arg("--watch")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (_stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
let next_line = next_line(&mut stderr_lines).await.unwrap();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_contains!(&next_line, "Lint started");
|
2023-04-17 09:49:03 -04:00
|
|
|
let mut output = read_all_lints(&mut stderr_lines).await;
|
2024-05-03 17:31:12 -04:00
|
|
|
let expected = badly_linted_output.read_to_string();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_eq!(output, expected);
|
|
|
|
|
|
|
|
// Change content of the file again to be badly-linted
|
2024-05-03 17:31:12 -04:00
|
|
|
badly_linted_fixed1.copy(&badly_linted);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
output = read_all_lints(&mut stderr_lines).await;
|
2024-05-03 17:31:12 -04:00
|
|
|
let expected = badly_linted_fixed1_output.read_to_string();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_eq!(output, expected);
|
|
|
|
|
|
|
|
// Change content of the file again to be badly-linted
|
2024-05-03 17:31:12 -04:00
|
|
|
badly_linted_fixed2.copy(&badly_linted);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
output = read_all_lints(&mut stderr_lines).await;
|
2024-05-03 17:31:12 -04:00
|
|
|
let expected = badly_linted_fixed2_output.read_to_string();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_eq!(output, expected);
|
|
|
|
|
|
|
|
// the watcher process is still alive
|
|
|
|
assert!(child.try_wait().unwrap().is_none());
|
|
|
|
|
|
|
|
child.kill().unwrap();
|
|
|
|
drop(t);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn lint_all_files_on_each_change_test() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let t = TempDir::new();
|
|
|
|
let badly_linted_fixed0 =
|
|
|
|
util::testdata_path().join("lint/watch/badly_linted.js");
|
|
|
|
let badly_linted_fixed1 =
|
|
|
|
util::testdata_path().join("lint/watch/badly_linted_fixed1.js");
|
|
|
|
let badly_linted_fixed2 =
|
|
|
|
util::testdata_path().join("lint/watch/badly_linted_fixed2.js");
|
|
|
|
|
|
|
|
let badly_linted_1 = t.path().join("badly_linted_1.js");
|
|
|
|
let badly_linted_2 = t.path().join("badly_linted_2.js");
|
2024-05-03 17:31:12 -04:00
|
|
|
badly_linted_fixed0.copy(&badly_linted_1);
|
|
|
|
badly_linted_fixed1.copy(&badly_linted_2);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.arg("lint")
|
|
|
|
.arg(t.path())
|
|
|
|
.arg("--watch")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (_stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_contains!(
|
|
|
|
wait_contains("Checked", &mut stderr_lines).await,
|
|
|
|
"Checked 2 files"
|
|
|
|
);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2024-05-03 17:31:12 -04:00
|
|
|
badly_linted_fixed2.copy(&badly_linted_2);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_contains!(
|
|
|
|
wait_contains("Checked", &mut stderr_lines).await,
|
|
|
|
"Checked 2 files"
|
|
|
|
);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
assert!(child.try_wait().unwrap().is_none());
|
|
|
|
|
|
|
|
child.kill().unwrap();
|
|
|
|
drop(t);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn fmt_watch_test() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let fmt_testdata_path = util::testdata_path().join("fmt");
|
|
|
|
let t = TempDir::new();
|
|
|
|
let fixed = fmt_testdata_path.join("badly_formatted_fixed.js");
|
|
|
|
let badly_formatted_original = fmt_testdata_path.join("badly_formatted.mjs");
|
|
|
|
let badly_formatted = t.path().join("badly_formatted.js");
|
2024-05-03 17:31:12 -04:00
|
|
|
badly_formatted_original.copy(&badly_formatted);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.arg("fmt")
|
|
|
|
.arg(&badly_formatted)
|
|
|
|
.arg("--watch")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (_stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
let next_line = next_line(&mut stderr_lines).await.unwrap();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_contains!(&next_line, "Fmt started");
|
|
|
|
assert_contains!(
|
2023-04-17 09:49:03 -04:00
|
|
|
skip_restarting_line(&mut stderr_lines).await,
|
2023-01-12 20:59:13 -05:00
|
|
|
"badly_formatted.js"
|
|
|
|
);
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_contains!(
|
|
|
|
wait_contains("Checked", &mut stderr_lines).await,
|
|
|
|
"Checked 1 file"
|
|
|
|
);
|
2023-06-15 13:09:37 -04:00
|
|
|
wait_contains("Fmt finished", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2024-05-03 17:31:12 -04:00
|
|
|
let expected = fixed.read_to_string();
|
|
|
|
let actual = badly_formatted.read_to_string();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_eq!(actual, expected);
|
|
|
|
|
|
|
|
// Change content of the file again to be badly formatted
|
2024-05-03 17:31:12 -04:00
|
|
|
badly_formatted_original.copy(&badly_formatted);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
assert_contains!(
|
2023-04-17 09:49:03 -04:00
|
|
|
skip_restarting_line(&mut stderr_lines).await,
|
2023-01-12 20:59:13 -05:00
|
|
|
"badly_formatted.js"
|
|
|
|
);
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_contains!(
|
|
|
|
wait_contains("Checked", &mut stderr_lines).await,
|
|
|
|
"Checked 1 file"
|
|
|
|
);
|
2023-06-15 13:09:37 -04:00
|
|
|
wait_contains("Fmt finished", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Check if file has been automatically formatted by watcher
|
2024-05-03 17:31:12 -04:00
|
|
|
let expected = fixed.read_to_string();
|
|
|
|
let actual = badly_formatted.read_to_string();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_eq!(actual, expected);
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn fmt_watch_without_args_test() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let fmt_testdata_path = util::testdata_path().join("fmt");
|
|
|
|
let t = TempDir::new();
|
|
|
|
let fixed = fmt_testdata_path.join("badly_formatted_fixed.js");
|
|
|
|
let badly_formatted_original = fmt_testdata_path.join("badly_formatted.mjs");
|
|
|
|
let badly_formatted = t.path().join("badly_formatted.js");
|
2024-05-03 17:31:12 -04:00
|
|
|
badly_formatted_original.copy(&badly_formatted);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
|
|
|
.current_dir(t.path())
|
|
|
|
.arg("fmt")
|
|
|
|
.arg("--watch")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (_stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
let next_line = next_line(&mut stderr_lines).await.unwrap();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_contains!(&next_line, "Fmt started");
|
|
|
|
assert_contains!(
|
2023-04-17 09:49:03 -04:00
|
|
|
skip_restarting_line(&mut stderr_lines).await,
|
2023-01-12 20:59:13 -05:00
|
|
|
"badly_formatted.js"
|
|
|
|
);
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_contains!(
|
|
|
|
wait_contains("Checked", &mut stderr_lines).await,
|
|
|
|
"Checked 1 file"
|
|
|
|
);
|
2024-05-03 17:31:12 -04:00
|
|
|
wait_contains("Fmt finished.", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2024-05-03 17:31:12 -04:00
|
|
|
let expected = fixed.read_to_string();
|
|
|
|
let actual = badly_formatted.read_to_string();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_eq!(actual, expected);
|
|
|
|
|
|
|
|
// Change content of the file again to be badly formatted
|
2024-05-03 17:31:12 -04:00
|
|
|
badly_formatted_original.copy(&badly_formatted);
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_contains!(
|
2023-04-17 09:49:03 -04:00
|
|
|
skip_restarting_line(&mut stderr_lines).await,
|
2023-01-12 20:59:13 -05:00
|
|
|
"badly_formatted.js"
|
|
|
|
);
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_contains!(
|
|
|
|
wait_contains("Checked", &mut stderr_lines).await,
|
|
|
|
"Checked 1 file"
|
|
|
|
);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Check if file has been automatically formatted by watcher
|
2024-05-03 17:31:12 -04:00
|
|
|
let expected = fixed.read_to_string();
|
|
|
|
let actual = badly_formatted.read_to_string();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_eq!(actual, expected);
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn fmt_check_all_files_on_each_change_test() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let t = TempDir::new();
|
|
|
|
let fmt_testdata_path = util::testdata_path().join("fmt");
|
|
|
|
let badly_formatted_original = fmt_testdata_path.join("badly_formatted.mjs");
|
|
|
|
let badly_formatted_1 = t.path().join("badly_formatted_1.js");
|
|
|
|
let badly_formatted_2 = t.path().join("badly_formatted_2.js");
|
2024-05-03 17:31:12 -04:00
|
|
|
badly_formatted_original.copy(&badly_formatted_1);
|
|
|
|
badly_formatted_original.copy(&badly_formatted_2);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.arg("fmt")
|
|
|
|
.arg(t.path())
|
|
|
|
.arg("--watch")
|
|
|
|
.arg("--check")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (_stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
|
|
|
assert_contains!(
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("error", &mut stderr_lines).await,
|
2023-01-12 20:59:13 -05:00
|
|
|
"Found 2 not formatted files in 2 files"
|
|
|
|
);
|
2024-05-05 18:09:45 -04:00
|
|
|
wait_contains("Fmt failed.", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Change content of the file again to be badly formatted
|
2024-05-03 17:31:12 -04:00
|
|
|
badly_formatted_original.copy(&badly_formatted_1);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
assert_contains!(
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("error", &mut stderr_lines).await,
|
2023-01-12 20:59:13 -05:00
|
|
|
"Found 2 not formatted files in 2 files"
|
|
|
|
);
|
|
|
|
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn run_watch_no_dynamic() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write("console.log('Hello world');");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.arg("run")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg("-L")
|
|
|
|
.arg("debug")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Hello world", &mut stdout_lines).await;
|
|
|
|
wait_for_watcher("file_to_watch.js", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Change content of the file
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write("console.log('Hello world2');");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Restarting", &mut stderr_lines).await;
|
|
|
|
wait_contains("Hello world2", &mut stdout_lines).await;
|
|
|
|
wait_for_watcher("file_to_watch.js", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Add dependency
|
|
|
|
let another_file = t.path().join("another_file.js");
|
2023-06-14 18:29:19 -04:00
|
|
|
another_file.write("export const foo = 0;");
|
|
|
|
file_to_watch
|
|
|
|
.write("import { foo } from './another_file.js'; console.log(foo);");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Restarting", &mut stderr_lines).await;
|
|
|
|
wait_contains("0", &mut stdout_lines).await;
|
|
|
|
wait_for_watcher("another_file.js", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Confirm that restarting occurs when a new file is updated
|
2023-06-14 18:29:19 -04:00
|
|
|
another_file.write("export const foo = 42;");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Restarting", &mut stderr_lines).await;
|
|
|
|
wait_contains("42", &mut stdout_lines).await;
|
|
|
|
wait_for_watcher("file_to_watch.js", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Confirm that the watcher keeps on working even if the file is updated and has invalid syntax
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write("syntax error ^^");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Restarting", &mut stderr_lines).await;
|
|
|
|
wait_contains("error:", &mut stderr_lines).await;
|
|
|
|
wait_for_watcher("file_to_watch.js", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Then restore the file
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch
|
|
|
|
.write("import { foo } from './another_file.js'; console.log(foo);");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Restarting", &mut stderr_lines).await;
|
|
|
|
wait_contains("42", &mut stdout_lines).await;
|
|
|
|
wait_for_watcher("another_file.js", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Update the content of the imported file with invalid syntax
|
2023-06-14 18:29:19 -04:00
|
|
|
another_file.write("syntax error ^^");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Restarting", &mut stderr_lines).await;
|
|
|
|
wait_contains("error:", &mut stderr_lines).await;
|
|
|
|
wait_for_watcher("another_file.js", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Modify the imported file and make sure that restarting occurs
|
2023-06-14 18:29:19 -04:00
|
|
|
another_file.write("export const foo = 'modified!';");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Restarting", &mut stderr_lines).await;
|
|
|
|
wait_contains("modified!", &mut stdout_lines).await;
|
|
|
|
wait_contains("Watching paths", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-14 09:21:11 -04:00
|
|
|
#[flaky_test(tokio)]
|
|
|
|
async fn run_watch_npm_specifier() {
|
|
|
|
let _g = util::http_server();
|
|
|
|
let t = TempDir::new();
|
|
|
|
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.txt");
|
|
|
|
file_to_watch.write("Hello world");
|
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
|
|
|
.current_dir(t.path())
|
|
|
|
.envs(env_vars_for_npm_tests())
|
|
|
|
.arg("run")
|
|
|
|
.arg("--watch=file_to_watch.txt")
|
|
|
|
.arg("-L")
|
|
|
|
.arg("debug")
|
|
|
|
.arg("npm:@denotest/bin/cli-cjs")
|
|
|
|
.arg("Hello world")
|
|
|
|
.env("NO_COLOR", "1")
|
|
|
|
.piped_output()
|
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
|
|
|
wait_contains("Hello world", &mut stdout_lines).await;
|
|
|
|
wait_for_watcher("file_to_watch.txt", &mut stderr_lines).await;
|
|
|
|
|
|
|
|
// Change content of the file
|
|
|
|
file_to_watch.write("Hello world2");
|
|
|
|
|
|
|
|
wait_contains("Restarting", &mut stderr_lines).await;
|
|
|
|
wait_contains("Hello world", &mut stdout_lines).await;
|
|
|
|
wait_for_watcher("file_to_watch.txt", &mut stderr_lines).await;
|
|
|
|
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
// TODO(bartlomieju): this test became flaky on macOS runner; it is unclear
|
|
|
|
// if that's because of a bug in code or the runner itself. We should reenable
|
|
|
|
// it once we upgrade to XL runners for macOS.
|
|
|
|
#[cfg(not(target_os = "macos"))]
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn run_watch_external_watch_files() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write("console.log('Hello world');");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let external_file_to_watch = t.path().join("external_file_to_watch.txt");
|
2023-06-14 18:29:19 -04:00
|
|
|
external_file_to_watch.write("Hello world");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let mut watch_arg = "--watch=".to_owned();
|
2023-06-10 11:09:45 -04:00
|
|
|
let external_file_to_watch_str = external_file_to_watch.to_string();
|
2023-01-12 20:59:13 -05:00
|
|
|
watch_arg.push_str(&external_file_to_watch_str);
|
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.arg("run")
|
|
|
|
.arg(watch_arg)
|
|
|
|
.arg("-L")
|
|
|
|
.arg("debug")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Process started", &mut stderr_lines).await;
|
|
|
|
wait_contains("Hello world", &mut stdout_lines).await;
|
|
|
|
wait_for_watcher("external_file_to_watch.txt", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Change content of the external file
|
2023-06-14 18:29:19 -04:00
|
|
|
external_file_to_watch.write("Hello world2");
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Restarting", &mut stderr_lines).await;
|
|
|
|
wait_contains("Process finished", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-02-03 14:15:16 -05:00
|
|
|
// Again (https://github.com/denoland/deno/issues/17584)
|
2023-06-14 18:29:19 -04:00
|
|
|
external_file_to_watch.write("Hello world3");
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Restarting", &mut stderr_lines).await;
|
|
|
|
wait_contains("Process finished", &mut stderr_lines).await;
|
2023-02-03 14:15:16 -05:00
|
|
|
|
2023-01-12 20:59:13 -05:00
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn run_watch_load_unload_events() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write(
|
2023-01-12 20:59:13 -05:00
|
|
|
r#"
|
|
|
|
setInterval(() => {}, 0);
|
2024-08-30 13:58:58 -04:00
|
|
|
globalThis.addEventListener("load", () => {
|
2023-01-12 20:59:13 -05:00
|
|
|
console.log("load");
|
|
|
|
});
|
|
|
|
|
2024-08-30 13:58:58 -04:00
|
|
|
globalThis.addEventListener("unload", () => {
|
2023-01-12 20:59:13 -05:00
|
|
|
console.log("unload");
|
|
|
|
});
|
|
|
|
"#,
|
2023-06-14 18:29:19 -04:00
|
|
|
);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.arg("run")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg("-L")
|
|
|
|
.arg("debug")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
|
|
|
// Wait for the first load event to fire
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("load", &mut stdout_lines).await;
|
|
|
|
wait_for_watcher("file_to_watch.js", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Change content of the file, this time without an interval to keep it alive.
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write(
|
2023-01-12 20:59:13 -05:00
|
|
|
r#"
|
2024-08-30 13:58:58 -04:00
|
|
|
globalThis.addEventListener("load", () => {
|
2023-01-12 20:59:13 -05:00
|
|
|
console.log("load");
|
|
|
|
});
|
|
|
|
|
2024-08-30 13:58:58 -04:00
|
|
|
globalThis.addEventListener("unload", () => {
|
2023-01-12 20:59:13 -05:00
|
|
|
console.log("unload");
|
|
|
|
});
|
|
|
|
"#,
|
2023-06-14 18:29:19 -04:00
|
|
|
);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Wait for the restart
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Restarting", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Confirm that the unload event was dispatched from the first run
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("unload", &mut stdout_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Followed by the load event of the second run
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("load", &mut stdout_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Which is then unloaded as there is nothing keeping it alive.
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("unload", &mut stdout_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Confirm that the watcher continues to work even if module resolution fails at the *first* attempt
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn run_watch_not_exit() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write("syntax error ^^");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.arg("run")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg("-L")
|
|
|
|
.arg("debug")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Process started", &mut stderr_lines).await;
|
|
|
|
wait_contains("error:", &mut stderr_lines).await;
|
|
|
|
wait_for_watcher("file_to_watch.js", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Make sure the watcher actually restarts and works fine with the proper syntax
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write("console.log(42);");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Restarting", &mut stderr_lines).await;
|
|
|
|
wait_contains("42", &mut stdout_lines).await;
|
|
|
|
wait_contains("Process finished", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn run_watch_with_import_map_and_relative_paths() {
|
2023-01-12 20:59:13 -05:00
|
|
|
fn create_relative_tmp_file(
|
|
|
|
directory: &TempDir,
|
|
|
|
filename: &'static str,
|
|
|
|
filecontent: &'static str,
|
|
|
|
) -> std::path::PathBuf {
|
|
|
|
let absolute_path = directory.path().join(filename);
|
2023-06-14 18:29:19 -04:00
|
|
|
absolute_path.write(filecontent);
|
2023-01-12 20:59:13 -05:00
|
|
|
let relative_path = absolute_path
|
2023-06-10 11:09:45 -04:00
|
|
|
.as_path()
|
|
|
|
.strip_prefix(directory.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.unwrap()
|
|
|
|
.to_owned();
|
|
|
|
assert!(relative_path.is_relative());
|
|
|
|
relative_path
|
|
|
|
}
|
2023-06-10 11:09:45 -04:00
|
|
|
|
|
|
|
let temp_directory = TempDir::new();
|
2023-01-12 20:59:13 -05:00
|
|
|
let file_to_watch = create_relative_tmp_file(
|
|
|
|
&temp_directory,
|
|
|
|
"file_to_watch.js",
|
|
|
|
"console.log('Hello world');",
|
|
|
|
);
|
|
|
|
let import_map_path = create_relative_tmp_file(
|
|
|
|
&temp_directory,
|
|
|
|
"import_map.json",
|
|
|
|
"{\"imports\": {}}",
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2023-06-10 11:09:45 -04:00
|
|
|
.current_dir(temp_directory.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.arg("run")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg("--import-map")
|
|
|
|
.arg(&import_map_path)
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
2023-04-17 09:49:03 -04:00
|
|
|
let line = next_line(&mut stderr_lines).await.unwrap();
|
|
|
|
assert_contains!(&line, "Process started");
|
|
|
|
assert_contains!(
|
|
|
|
next_line(&mut stderr_lines).await.unwrap(),
|
|
|
|
"Process finished"
|
|
|
|
);
|
|
|
|
assert_contains!(next_line(&mut stdout_lines).await.unwrap(), "Hello world");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn run_watch_with_ext_flag() {
|
2023-03-22 10:15:53 -04:00
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch");
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write("interface I{}; console.log(42);");
|
2023-03-22 10:15:53 -04:00
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-03-22 10:15:53 -04:00
|
|
|
.arg("run")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg("--log-level")
|
|
|
|
.arg("debug")
|
|
|
|
.arg("--ext")
|
|
|
|
.arg("ts")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-03-22 10:15:53 -04:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("42", &mut stdout_lines).await;
|
2023-03-22 10:15:53 -04:00
|
|
|
|
|
|
|
// Make sure the watcher actually restarts and works fine with the proper language
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_for_watcher("file_to_watch", &mut stderr_lines).await;
|
|
|
|
wait_contains("Process finished", &mut stderr_lines).await;
|
2023-03-22 10:15:53 -04:00
|
|
|
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write("type Bear = 'polar' | 'grizzly'; console.log(123);");
|
2023-03-22 10:15:53 -04:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Restarting!", &mut stderr_lines).await;
|
|
|
|
wait_contains("123", &mut stdout_lines).await;
|
|
|
|
wait_contains("Process finished", &mut stderr_lines).await;
|
2023-03-22 10:15:53 -04:00
|
|
|
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn run_watch_error_messages() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch
|
|
|
|
.write("throw SyntaxError(`outer`, {cause: TypeError(`inner`)})");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.arg("run")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (_, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Process started", &mut stderr_lines).await;
|
2023-12-06 19:02:52 -05:00
|
|
|
wait_contains(
|
|
|
|
"error: Uncaught (in promise) SyntaxError: outer",
|
|
|
|
&mut stderr_lines,
|
|
|
|
)
|
|
|
|
.await;
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Caused by: TypeError: inner", &mut stderr_lines).await;
|
2023-06-14 18:29:19 -04:00
|
|
|
wait_contains("Process failed", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-06-14 18:29:19 -04:00
|
|
|
async fn test_watch_basic() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let t = TempDir::new();
|
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.arg("test")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg("--no-check")
|
|
|
|
.arg(t.path())
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_eq!(next_line(&mut stdout_lines).await.unwrap(), "");
|
|
|
|
assert_contains!(
|
|
|
|
next_line(&mut stdout_lines).await.unwrap(),
|
|
|
|
"0 passed | 0 failed"
|
|
|
|
);
|
|
|
|
wait_contains("Test finished", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let foo_file = t.path().join("foo.js");
|
|
|
|
let bar_file = t.path().join("bar.js");
|
|
|
|
let foo_test = t.path().join("foo_test.js");
|
|
|
|
let bar_test = t.path().join("bar_test.js");
|
2023-06-14 18:29:19 -04:00
|
|
|
foo_file.write("export default function foo() { 1 + 1 }");
|
|
|
|
bar_file.write("export default function bar() { 2 + 2 }");
|
|
|
|
foo_test.write("import foo from './foo.js'; Deno.test('foo', foo);");
|
|
|
|
bar_test.write("import bar from './bar.js'; Deno.test('bar', bar);");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_eq!(next_line(&mut stdout_lines).await.unwrap(), "");
|
|
|
|
assert_contains!(
|
|
|
|
next_line(&mut stdout_lines).await.unwrap(),
|
|
|
|
"running 1 test"
|
|
|
|
);
|
|
|
|
assert_contains!(next_line(&mut stdout_lines).await.unwrap(), "foo", "bar");
|
|
|
|
assert_contains!(
|
|
|
|
next_line(&mut stdout_lines).await.unwrap(),
|
|
|
|
"running 1 test"
|
|
|
|
);
|
|
|
|
assert_contains!(next_line(&mut stdout_lines).await.unwrap(), "foo", "bar");
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
wait_contains("Test finished", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Change content of the file
|
2023-06-14 18:29:19 -04:00
|
|
|
foo_test.write("import foo from './foo.js'; Deno.test('foobar', foo);");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_contains!(next_line(&mut stderr_lines).await.unwrap(), "Restarting");
|
|
|
|
assert_contains!(
|
|
|
|
next_line(&mut stdout_lines).await.unwrap(),
|
|
|
|
"running 1 test"
|
|
|
|
);
|
|
|
|
assert_contains!(next_line(&mut stdout_lines).await.unwrap(), "foobar");
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
wait_contains("Test finished", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Add test
|
|
|
|
let another_test = t.path().join("new_test.js");
|
2023-06-14 18:29:19 -04:00
|
|
|
another_test.write("Deno.test('another one', () => 3 + 3)");
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_contains!(next_line(&mut stderr_lines).await.unwrap(), "Restarting");
|
|
|
|
assert_contains!(
|
|
|
|
next_line(&mut stdout_lines).await.unwrap(),
|
|
|
|
"running 1 test"
|
|
|
|
);
|
|
|
|
assert_contains!(next_line(&mut stdout_lines).await.unwrap(), "another one");
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
wait_contains("Test finished", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Confirm that restarting occurs when a new file is updated
|
2023-06-14 18:29:19 -04:00
|
|
|
another_test.write("Deno.test('another one', () => 3 + 3); Deno.test('another another one', () => 4 + 4)");
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_contains!(next_line(&mut stderr_lines).await.unwrap(), "Restarting");
|
|
|
|
assert_contains!(
|
|
|
|
next_line(&mut stdout_lines).await.unwrap(),
|
|
|
|
"running 2 tests"
|
|
|
|
);
|
|
|
|
assert_contains!(next_line(&mut stdout_lines).await.unwrap(), "another one");
|
|
|
|
assert_contains!(
|
|
|
|
next_line(&mut stdout_lines).await.unwrap(),
|
|
|
|
"another another one"
|
|
|
|
);
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
wait_contains("Test finished", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Confirm that the watcher keeps on working even if the file is updated and has invalid syntax
|
2023-06-14 18:29:19 -04:00
|
|
|
another_test.write("syntax error ^^");
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_contains!(next_line(&mut stderr_lines).await.unwrap(), "Restarting");
|
|
|
|
assert_contains!(next_line(&mut stderr_lines).await.unwrap(), "error:");
|
|
|
|
assert_eq!(next_line(&mut stderr_lines).await.unwrap(), "");
|
|
|
|
assert_eq!(
|
|
|
|
next_line(&mut stderr_lines).await.unwrap(),
|
|
|
|
" syntax error ^^"
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
next_line(&mut stderr_lines).await.unwrap(),
|
|
|
|
" ~~~~~"
|
|
|
|
);
|
|
|
|
assert_contains!(next_line(&mut stderr_lines).await.unwrap(), "Test failed");
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Then restore the file
|
2023-06-14 18:29:19 -04:00
|
|
|
another_test.write("Deno.test('another one', () => 3 + 3)");
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_contains!(next_line(&mut stderr_lines).await.unwrap(), "Restarting");
|
|
|
|
assert_contains!(
|
|
|
|
next_line(&mut stdout_lines).await.unwrap(),
|
|
|
|
"running 1 test"
|
|
|
|
);
|
|
|
|
assert_contains!(next_line(&mut stdout_lines).await.unwrap(), "another one");
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
wait_contains("Test finished", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Confirm that the watcher keeps on working even if the file is updated and the test fails
|
|
|
|
// This also confirms that it restarts when dependencies change
|
2023-06-14 18:29:19 -04:00
|
|
|
foo_file
|
|
|
|
.write("export default function foo() { throw new Error('Whoops!'); }");
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_contains!(next_line(&mut stderr_lines).await.unwrap(), "Restarting");
|
|
|
|
assert_contains!(
|
|
|
|
next_line(&mut stdout_lines).await.unwrap(),
|
|
|
|
"running 1 test"
|
|
|
|
);
|
|
|
|
assert_contains!(next_line(&mut stdout_lines).await.unwrap(), "FAILED");
|
|
|
|
wait_contains("FAILED", &mut stdout_lines).await;
|
|
|
|
next_line(&mut stdout_lines).await;
|
2023-06-14 18:29:19 -04:00
|
|
|
wait_contains("Test failed", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Then restore the file
|
2023-06-14 18:29:19 -04:00
|
|
|
foo_file.write("export default function foo() { 1 + 1 }");
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_contains!(next_line(&mut stderr_lines).await.unwrap(), "Restarting");
|
|
|
|
assert_contains!(
|
|
|
|
next_line(&mut stdout_lines).await.unwrap(),
|
|
|
|
"running 1 test"
|
|
|
|
);
|
|
|
|
assert_contains!(next_line(&mut stdout_lines).await.unwrap(), "foo");
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
next_line(&mut stdout_lines).await;
|
|
|
|
wait_contains("Test finished", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// Test that circular dependencies work fine
|
2023-06-14 18:29:19 -04:00
|
|
|
foo_file.write("import './bar.js'; export default function foo() { 1 + 1 }");
|
|
|
|
bar_file.write("import './foo.js'; export default function bar() { 2 + 2 }");
|
2023-01-12 20:59:13 -05:00
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn test_watch_doc() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let t = TempDir::new();
|
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.arg("test")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg("--doc")
|
|
|
|
.arg(t.path())
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_eq!(next_line(&mut stdout_lines).await.unwrap(), "");
|
|
|
|
assert_contains!(
|
|
|
|
next_line(&mut stdout_lines).await.unwrap(),
|
|
|
|
"0 passed | 0 failed"
|
|
|
|
);
|
|
|
|
wait_contains("Test finished", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let foo_file = t.path().join("foo.ts");
|
2023-06-14 18:29:19 -04:00
|
|
|
foo_file.write(
|
2023-01-12 20:59:13 -05:00
|
|
|
r#"
|
|
|
|
export default function foo() {}
|
|
|
|
"#,
|
2023-06-14 18:29:19 -04:00
|
|
|
);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-06-14 18:29:19 -04:00
|
|
|
foo_file.write(
|
2023-01-12 20:59:13 -05:00
|
|
|
r#"
|
|
|
|
/**
|
|
|
|
* ```ts
|
|
|
|
* import foo from "./foo.ts";
|
|
|
|
* ```
|
|
|
|
*/
|
|
|
|
export default function foo() {}
|
|
|
|
"#,
|
2023-06-14 18:29:19 -04:00
|
|
|
);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
// We only need to scan for a Check file://.../foo.ts$3-6 line that
|
|
|
|
// corresponds to the documentation block being type-checked.
|
2023-04-17 09:49:03 -04:00
|
|
|
assert_contains!(skip_restarting_line(&mut stderr_lines).await, "foo.ts$3-6");
|
2023-01-12 20:59:13 -05:00
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn test_watch_module_graph_error_referrer() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write("import './nonexistent.js';");
|
2023-01-12 20:59:13 -05:00
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.arg("run")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (_, mut stderr_lines) = child_lines(&mut child);
|
2023-04-17 09:49:03 -04:00
|
|
|
let line1 = next_line(&mut stderr_lines).await.unwrap();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_contains!(&line1, "Process started");
|
2023-04-17 09:49:03 -04:00
|
|
|
let line2 = next_line(&mut stderr_lines).await.unwrap();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_contains!(&line2, "error: Module not found");
|
|
|
|
assert_contains!(&line2, "nonexistent.js");
|
2023-04-17 09:49:03 -04:00
|
|
|
let line3 = next_line(&mut stderr_lines).await.unwrap();
|
2023-01-12 20:59:13 -05:00
|
|
|
assert_contains!(&line3, " at ");
|
|
|
|
assert_contains!(&line3, "file_to_watch.js");
|
2023-06-14 18:29:19 -04:00
|
|
|
wait_contains("Process failed", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Regression test for https://github.com/denoland/deno/issues/15428.
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn test_watch_unload_handler_error_on_drop() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write(
|
2023-01-12 20:59:13 -05:00
|
|
|
r#"
|
|
|
|
addEventListener("unload", () => {
|
|
|
|
throw new Error("foo");
|
|
|
|
});
|
|
|
|
setTimeout(() => {
|
|
|
|
throw new Error("bar");
|
|
|
|
});
|
|
|
|
"#,
|
2023-06-14 18:29:19 -04:00
|
|
|
);
|
2023-01-12 20:59:13 -05:00
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.arg("run")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (_, mut stderr_lines) = child_lines(&mut child);
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Process started", &mut stderr_lines).await;
|
|
|
|
wait_contains("Uncaught Error: bar", &mut stderr_lines).await;
|
2023-06-14 18:29:19 -04:00
|
|
|
wait_contains("Process failed", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-07-01 18:52:30 -04:00
|
|
|
async fn run_watch_blob_urls_reset() {
|
|
|
|
let _g = util::http_server();
|
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
|
|
|
let file_content = r#"
|
|
|
|
const prevUrl = localStorage.getItem("url");
|
|
|
|
if (prevUrl == null) {
|
|
|
|
console.log("first run, storing blob url");
|
|
|
|
const url = URL.createObjectURL(
|
|
|
|
new Blob(["export {}"], { type: "application/javascript" }),
|
|
|
|
);
|
|
|
|
await import(url); // this shouldn't insert into the fs module cache
|
|
|
|
localStorage.setItem("url", url);
|
|
|
|
} else {
|
|
|
|
await import(prevUrl)
|
|
|
|
.then(() => console.log("importing old blob url incorrectly works"))
|
|
|
|
.catch(() => console.log("importing old blob url correctly failed"));
|
|
|
|
}
|
|
|
|
"#;
|
|
|
|
file_to_watch.write(file_content);
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-07-01 18:52:30 -04:00
|
|
|
.arg("run")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-07-01 18:52:30 -04:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
wait_contains("first run, storing blob url", &mut stdout_lines).await;
|
|
|
|
wait_contains("finished", &mut stderr_lines).await;
|
|
|
|
file_to_watch.write(file_content);
|
|
|
|
wait_contains("importing old blob url correctly failed", &mut stdout_lines)
|
|
|
|
.await;
|
|
|
|
wait_contains("finished", &mut stderr_lines).await;
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2023-04-12 18:51:04 -04:00
|
|
|
#[cfg(unix)]
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn test_watch_sigint() {
|
2023-04-12 18:51:04 -04:00
|
|
|
use nix::sys::signal;
|
|
|
|
use nix::sys::signal::Signal;
|
|
|
|
use nix::unistd::Pid;
|
2023-11-17 10:05:42 -05:00
|
|
|
use util::TestContext;
|
2023-04-12 18:51:04 -04:00
|
|
|
|
2023-11-17 10:05:42 -05:00
|
|
|
let context = TestContext::default();
|
|
|
|
let t = context.temp_dir();
|
2023-04-12 18:51:04 -04:00
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write(r#"Deno.test("foo", () => {});"#);
|
2023-11-17 10:05:42 -05:00
|
|
|
let mut child = context
|
|
|
|
.new_command()
|
|
|
|
.args_vec(["test", "--watch", &file_to_watch.to_string_lossy()])
|
2023-04-12 18:51:04 -04:00
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.spawn_with_piped_output();
|
2023-04-12 18:51:04 -04:00
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Test started", &mut stderr_lines).await;
|
|
|
|
wait_contains("ok | 1 passed | 0 failed", &mut stdout_lines).await;
|
|
|
|
wait_contains("Test finished", &mut stderr_lines).await;
|
2023-04-12 18:51:04 -04:00
|
|
|
signal::kill(Pid::from_raw(child.id() as i32), Signal::SIGINT).unwrap();
|
|
|
|
let exit_status = child.wait().unwrap();
|
|
|
|
assert_eq!(exit_status.code(), Some(130));
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-06-14 18:29:19 -04:00
|
|
|
async fn bench_watch_basic() {
|
|
|
|
let t = TempDir::new();
|
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-06-14 18:29:19 -04:00
|
|
|
.arg("bench")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg("--no-check")
|
|
|
|
.arg(t.path())
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-06-14 18:29:19 -04:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
|
|
|
assert_contains!(
|
|
|
|
next_line(&mut stderr_lines).await.unwrap(),
|
|
|
|
"Bench started"
|
|
|
|
);
|
|
|
|
assert_contains!(
|
|
|
|
next_line(&mut stderr_lines).await.unwrap(),
|
|
|
|
"Bench finished"
|
|
|
|
);
|
|
|
|
|
|
|
|
let foo_file = t.path().join("foo.js");
|
|
|
|
let bar_file = t.path().join("bar.js");
|
|
|
|
let foo_bench = t.path().join("foo_bench.js");
|
|
|
|
let bar_bench = t.path().join("bar_bench.js");
|
|
|
|
foo_file.write("export default function foo() { 1 + 1 }");
|
|
|
|
bar_file.write("export default function bar() { 2 + 2 }");
|
|
|
|
foo_bench.write("import foo from './foo.js'; Deno.bench('foo bench', foo);");
|
|
|
|
bar_bench.write("import bar from './bar.js'; Deno.bench('bar bench', bar);");
|
|
|
|
|
|
|
|
wait_contains("bar_bench.js", &mut stdout_lines).await;
|
|
|
|
wait_contains("bar bench", &mut stdout_lines).await;
|
|
|
|
wait_contains("foo_bench.js", &mut stdout_lines).await;
|
|
|
|
wait_contains("foo bench", &mut stdout_lines).await;
|
|
|
|
wait_contains("Bench finished", &mut stderr_lines).await;
|
|
|
|
|
|
|
|
// Change content of the file
|
|
|
|
foo_bench.write("import foo from './foo.js'; Deno.bench('foo asdf', foo);");
|
|
|
|
|
|
|
|
assert_contains!(next_line(&mut stderr_lines).await.unwrap(), "Restarting");
|
|
|
|
loop {
|
|
|
|
let line = next_line(&mut stdout_lines).await.unwrap();
|
|
|
|
assert_not_contains!(line, "bar");
|
|
|
|
if line.contains("foo asdf") {
|
|
|
|
break; // last line
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wait_contains("Bench finished", &mut stderr_lines).await;
|
|
|
|
|
|
|
|
// Add bench
|
|
|
|
let another_test = t.path().join("new_bench.js");
|
|
|
|
another_test.write("Deno.bench('another one', () => 3 + 3)");
|
|
|
|
loop {
|
|
|
|
let line = next_line(&mut stdout_lines).await.unwrap();
|
|
|
|
assert_not_contains!(line, "bar");
|
|
|
|
assert_not_contains!(line, "foo");
|
|
|
|
if line.contains("another one") {
|
|
|
|
break; // last line
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wait_contains("Bench finished", &mut stderr_lines).await;
|
|
|
|
|
|
|
|
// Confirm that restarting occurs when a new file is updated
|
|
|
|
another_test.write("Deno.bench('another one', () => 3 + 3); Deno.bench('another another one', () => 4 + 4)");
|
|
|
|
loop {
|
|
|
|
let line = next_line(&mut stdout_lines).await.unwrap();
|
|
|
|
assert_not_contains!(line, "bar");
|
|
|
|
assert_not_contains!(line, "foo");
|
|
|
|
if line.contains("another another one") {
|
|
|
|
break; // last line
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wait_contains("Bench finished", &mut stderr_lines).await;
|
|
|
|
|
|
|
|
// Confirm that the watcher keeps on working even if the file is updated and has invalid syntax
|
|
|
|
another_test.write("syntax error ^^");
|
|
|
|
assert_contains!(next_line(&mut stderr_lines).await.unwrap(), "Restarting");
|
|
|
|
assert_contains!(next_line(&mut stderr_lines).await.unwrap(), "error:");
|
|
|
|
assert_eq!(next_line(&mut stderr_lines).await.unwrap(), "");
|
|
|
|
assert_eq!(
|
|
|
|
next_line(&mut stderr_lines).await.unwrap(),
|
|
|
|
" syntax error ^^"
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
next_line(&mut stderr_lines).await.unwrap(),
|
|
|
|
" ~~~~~"
|
|
|
|
);
|
|
|
|
assert_contains!(next_line(&mut stderr_lines).await.unwrap(), "Bench failed");
|
|
|
|
|
|
|
|
// Then restore the file
|
|
|
|
another_test.write("Deno.bench('another one', () => 3 + 3)");
|
|
|
|
assert_contains!(next_line(&mut stderr_lines).await.unwrap(), "Restarting");
|
|
|
|
loop {
|
|
|
|
let line = next_line(&mut stdout_lines).await.unwrap();
|
|
|
|
assert_not_contains!(line, "bar");
|
|
|
|
assert_not_contains!(line, "foo");
|
|
|
|
if line.contains("another one") {
|
|
|
|
break; // last line
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wait_contains("Bench finished", &mut stderr_lines).await;
|
|
|
|
|
|
|
|
// Test that circular dependencies work fine
|
|
|
|
foo_file.write("import './bar.js'; export default function foo() { 1 + 1 }");
|
|
|
|
bar_file.write("import './foo.js'; export default function bar() { 2 + 2 }");
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2023-02-03 14:15:16 -05:00
|
|
|
// Regression test for https://github.com/denoland/deno/issues/15465.
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn run_watch_reload_once() {
|
2023-02-03 14:15:16 -05:00
|
|
|
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);
|
|
|
|
"#;
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write(file_content);
|
2023-02-03 14:15:16 -05:00
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-02-03 14:15:16 -05:00
|
|
|
.arg("run")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg("--reload")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-02-03 14:15:16 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("finished", &mut stderr_lines).await;
|
|
|
|
let first_output = next_line(&mut stdout_lines).await.unwrap();
|
2023-02-03 14:15:16 -05:00
|
|
|
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write(file_content);
|
2023-02-03 14:15:16 -05:00
|
|
|
// The remote dynamic module should not have been reloaded again.
|
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("finished", &mut stderr_lines).await;
|
|
|
|
let second_output = next_line(&mut stdout_lines).await.unwrap();
|
2023-02-03 14:15:16 -05:00
|
|
|
assert_eq!(second_output, first_output);
|
|
|
|
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2023-05-08 03:52:56 -04:00
|
|
|
/// Regression test for https://github.com/denoland/deno/issues/18960. Ensures that Deno.serve
|
|
|
|
/// operates properly after a watch restart.
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-05-08 03:52:56 -04:00
|
|
|
async fn test_watch_serve() {
|
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
|
|
|
let file_content = r#"
|
|
|
|
console.error("serving");
|
|
|
|
await Deno.serve({port: 4600, handler: () => new Response("hello")});
|
|
|
|
"#;
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write(file_content);
|
2023-05-08 03:52:56 -04:00
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-05-08 03:52:56 -04:00
|
|
|
.arg("run")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg("--allow-net")
|
|
|
|
.arg("-L")
|
|
|
|
.arg("debug")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-05-08 03:52:56 -04:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
|
|
|
wait_contains("Listening on", &mut stdout_lines).await;
|
|
|
|
// Note that we start serving very quickly, so we specifically want to wait for this message
|
|
|
|
wait_contains(r#"Watching paths: [""#, &mut stderr_lines).await;
|
|
|
|
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write(file_content);
|
2023-05-08 03:52:56 -04:00
|
|
|
|
|
|
|
wait_contains("serving", &mut stderr_lines).await;
|
|
|
|
wait_contains("Listening on", &mut stdout_lines).await;
|
|
|
|
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-04-17 09:49:03 -04:00
|
|
|
async fn run_watch_dynamic_imports() {
|
2023-01-12 20:59:13 -05:00
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch.write(
|
2023-01-12 20:59:13 -05:00
|
|
|
r#"
|
|
|
|
console.log("Hopefully dynamic import will be watched...");
|
|
|
|
await import("./imported.js");
|
|
|
|
"#,
|
2023-06-14 18:29:19 -04:00
|
|
|
);
|
2023-01-12 20:59:13 -05:00
|
|
|
let file_to_watch2 = t.path().join("imported.js");
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch2.write(
|
2023-01-12 20:59:13 -05:00
|
|
|
r#"
|
|
|
|
import "./imported2.js";
|
|
|
|
console.log("I'm dynamically imported and I cause restarts!");
|
|
|
|
"#,
|
2023-06-14 18:29:19 -04:00
|
|
|
);
|
2023-01-12 20:59:13 -05:00
|
|
|
let file_to_watch3 = t.path().join("imported2.js");
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch3.write(
|
2023-01-12 20:59:13 -05:00
|
|
|
r#"
|
|
|
|
console.log("I'm statically imported from the dynamic import");
|
|
|
|
"#,
|
2023-06-14 18:29:19 -04:00
|
|
|
);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-01-12 20:59:13 -05:00
|
|
|
.arg("run")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg("--allow-read")
|
|
|
|
.arg("-L")
|
|
|
|
.arg("debug")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-01-12 20:59:13 -05:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Process started", &mut stderr_lines).await;
|
2024-07-03 20:54:33 -04:00
|
|
|
wait_contains("Finished config loading.", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
wait_contains(
|
|
|
|
"Hopefully dynamic import will be watched...",
|
|
|
|
&mut stdout_lines,
|
2023-04-17 09:49:03 -04:00
|
|
|
)
|
|
|
|
.await;
|
2023-01-12 20:59:13 -05:00
|
|
|
wait_contains(
|
|
|
|
"I'm statically imported from the dynamic import",
|
|
|
|
&mut stdout_lines,
|
2023-04-17 09:49:03 -04:00
|
|
|
)
|
|
|
|
.await;
|
2023-01-12 20:59:13 -05:00
|
|
|
wait_contains(
|
|
|
|
"I'm dynamically imported and I cause restarts!",
|
|
|
|
&mut stdout_lines,
|
2023-04-17 09:49:03 -04:00
|
|
|
)
|
|
|
|
.await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_for_watcher("imported2.js", &mut stderr_lines).await;
|
|
|
|
wait_contains("finished", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-06-14 18:29:19 -04:00
|
|
|
file_to_watch3.write(
|
2023-01-12 20:59:13 -05:00
|
|
|
r#"
|
|
|
|
console.log("I'm statically imported from the dynamic import and I've changed");
|
|
|
|
"#,
|
2023-06-14 18:29:19 -04:00
|
|
|
);
|
2023-01-12 20:59:13 -05:00
|
|
|
|
2023-04-17 09:49:03 -04:00
|
|
|
wait_contains("Restarting", &mut stderr_lines).await;
|
2023-01-12 20:59:13 -05:00
|
|
|
wait_contains(
|
|
|
|
"Hopefully dynamic import will be watched...",
|
|
|
|
&mut stdout_lines,
|
2023-04-17 09:49:03 -04:00
|
|
|
)
|
|
|
|
.await;
|
2023-01-12 20:59:13 -05:00
|
|
|
wait_contains(
|
|
|
|
"I'm statically imported from the dynamic import and I've changed",
|
|
|
|
&mut stdout_lines,
|
2023-04-17 09:49:03 -04:00
|
|
|
)
|
|
|
|
.await;
|
2023-01-12 20:59:13 -05:00
|
|
|
wait_contains(
|
|
|
|
"I'm dynamically imported and I cause restarts!",
|
|
|
|
&mut stdout_lines,
|
2023-04-17 09:49:03 -04:00
|
|
|
)
|
|
|
|
.await;
|
2023-01-12 20:59:13 -05:00
|
|
|
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
2023-10-06 17:33:14 -04:00
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-10-06 17:33:14 -04:00
|
|
|
async fn run_watch_inspect() {
|
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
|
|
|
file_to_watch.write(
|
|
|
|
r#"
|
|
|
|
console.log("hello world");
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-10-06 17:33:14 -04:00
|
|
|
.arg("run")
|
|
|
|
.arg("--watch")
|
|
|
|
.arg("--inspect")
|
|
|
|
.arg("-L")
|
|
|
|
.arg("debug")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-10-06 17:33:14 -04:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
|
|
|
|
wait_contains("Debugger listening", &mut stderr_lines).await;
|
|
|
|
wait_for_watcher("file_to_watch.js", &mut stderr_lines).await;
|
|
|
|
wait_contains("hello world", &mut stdout_lines).await;
|
|
|
|
|
|
|
|
file_to_watch.write(
|
|
|
|
r#"
|
|
|
|
console.log("updated file");
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
wait_contains("Restarting", &mut stderr_lines).await;
|
|
|
|
wait_contains("Debugger listening", &mut stderr_lines).await;
|
|
|
|
wait_contains("updated file", &mut stdout_lines).await;
|
|
|
|
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
2023-10-30 20:25:58 -04:00
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2024-03-27 18:47:46 -04:00
|
|
|
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()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2024-03-27 18:47:46 -04:00
|
|
|
.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);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-10-30 20:25:58 -04:00
|
|
|
async fn run_hmr_server() {
|
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
|
|
|
file_to_watch.write(
|
|
|
|
r#"
|
|
|
|
globalThis.state = { i: 0 };
|
|
|
|
|
|
|
|
function bar() {
|
|
|
|
globalThis.state.i = 0;
|
|
|
|
console.log("got request", globalThis.state.i);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handler(_req) {
|
|
|
|
bar();
|
|
|
|
return new Response("Hello world!");
|
|
|
|
}
|
|
|
|
|
|
|
|
Deno.serve({ port: 11111 }, handler);
|
|
|
|
console.log("Listening...")
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-10-30 20:25:58 -04:00
|
|
|
.arg("run")
|
2024-08-11 18:10:55 -04:00
|
|
|
.arg("--watch-hmr")
|
2023-10-30 20:25:58 -04:00
|
|
|
.arg("--allow-net")
|
|
|
|
.arg("-L")
|
|
|
|
.arg("debug")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-10-30 20:25:58 -04:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
wait_contains("Process started", &mut stderr_lines).await;
|
2024-07-03 20:54:33 -04:00
|
|
|
wait_contains("Finished config loading.", &mut stderr_lines).await;
|
2023-10-30 20:25:58 -04:00
|
|
|
|
|
|
|
wait_for_watcher("file_to_watch.js", &mut stderr_lines).await;
|
|
|
|
wait_contains("Listening...", &mut stdout_lines).await;
|
|
|
|
|
|
|
|
file_to_watch.write(
|
|
|
|
r#"
|
|
|
|
globalThis.state = { i: 0 };
|
|
|
|
|
|
|
|
function bar() {
|
|
|
|
globalThis.state.i = 0;
|
2024-06-05 11:04:16 -04:00
|
|
|
console.error("got request1", globalThis.state.i);
|
2023-10-30 20:25:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function handler(_req) {
|
|
|
|
bar();
|
|
|
|
return new Response("Hello world!");
|
|
|
|
}
|
|
|
|
|
|
|
|
Deno.serve({ port: 11111 }, handler);
|
|
|
|
console.log("Listening...")
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
2024-06-05 11:04:16 -04:00
|
|
|
wait_contains("Replaced changed module", &mut stderr_lines).await;
|
|
|
|
util::deno_cmd()
|
|
|
|
.current_dir(t.path())
|
|
|
|
.arg("eval")
|
|
|
|
.arg("await fetch('http://localhost:11111');")
|
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
wait_contains("got request1", &mut stderr_lines).await;
|
2023-10-30 20:25:58 -04:00
|
|
|
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-10-30 20:25:58 -04:00
|
|
|
async fn run_hmr_jsx() {
|
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
|
|
|
file_to_watch.write(
|
|
|
|
r#"
|
|
|
|
import { foo } from "./foo.jsx";
|
|
|
|
|
|
|
|
let i = 0;
|
|
|
|
setInterval(() => {
|
|
|
|
console.log(i++, foo());
|
2024-08-01 08:35:35 -04:00
|
|
|
}, 100);
|
2023-10-30 20:25:58 -04:00
|
|
|
"#,
|
|
|
|
);
|
|
|
|
let file_to_watch2 = t.path().join("foo.jsx");
|
|
|
|
file_to_watch2.write(
|
|
|
|
r#"
|
|
|
|
export function foo() {
|
|
|
|
return `<h1>Hello</h1>`;
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-10-30 20:25:58 -04:00
|
|
|
.arg("run")
|
2024-08-11 18:10:55 -04:00
|
|
|
.arg("--watch-hmr")
|
2023-10-30 20:25:58 -04:00
|
|
|
.arg("-L")
|
|
|
|
.arg("debug")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-10-30 20:25:58 -04:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
wait_contains("Process started", &mut stderr_lines).await;
|
2024-07-03 20:54:33 -04:00
|
|
|
wait_contains("Finished config loading.", &mut stderr_lines).await;
|
2023-10-30 20:25:58 -04:00
|
|
|
|
|
|
|
wait_for_watcher("file_to_watch.js", &mut stderr_lines).await;
|
|
|
|
wait_contains("5 <h1>Hello</h1>", &mut stdout_lines).await;
|
|
|
|
|
|
|
|
file_to_watch2.write(
|
|
|
|
r#"
|
|
|
|
export function foo() {
|
|
|
|
return `<h1>Hello world</h1>`;
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
wait_contains("Replaced changed module", &mut stderr_lines).await;
|
|
|
|
wait_contains("<h1>Hello world</h1>", &mut stdout_lines).await;
|
|
|
|
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-10-30 20:25:58 -04:00
|
|
|
async fn run_hmr_uncaught_error() {
|
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
|
|
|
file_to_watch.write(
|
|
|
|
r#"
|
|
|
|
import { foo } from "./foo.jsx";
|
|
|
|
|
|
|
|
let i = 0;
|
|
|
|
setInterval(() => {
|
|
|
|
console.log(i++, foo());
|
|
|
|
}, 100);
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
let file_to_watch2 = t.path().join("foo.jsx");
|
|
|
|
file_to_watch2.write(
|
|
|
|
r#"
|
|
|
|
export function foo() {
|
|
|
|
setTimeout(() => {
|
|
|
|
throw new Error("fail");
|
|
|
|
});
|
|
|
|
return `<h1>asd1</h1>`;
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-10-30 20:25:58 -04:00
|
|
|
.arg("run")
|
2024-08-11 18:10:55 -04:00
|
|
|
.arg("--watch-hmr")
|
2023-10-30 20:25:58 -04:00
|
|
|
.arg("-L")
|
|
|
|
.arg("debug")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-10-30 20:25:58 -04:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
wait_contains("Process started", &mut stderr_lines).await;
|
2024-07-03 20:54:33 -04:00
|
|
|
wait_contains("Finished config loading.", &mut stderr_lines).await;
|
2023-10-30 20:25:58 -04:00
|
|
|
|
|
|
|
wait_for_watcher("file_to_watch.js", &mut stderr_lines).await;
|
|
|
|
wait_contains("<h1>asd1</h1>", &mut stdout_lines).await;
|
|
|
|
wait_contains("fail", &mut stderr_lines).await;
|
|
|
|
|
|
|
|
file_to_watch2.write(
|
|
|
|
r#"
|
|
|
|
export function foo() {
|
|
|
|
return `<h1>asd2</h1>`;
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
wait_contains("Process failed", &mut stderr_lines).await;
|
|
|
|
wait_contains("File change detected", &mut stderr_lines).await;
|
|
|
|
wait_contains("<h1>asd2</h1>", &mut stdout_lines).await;
|
|
|
|
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|
|
|
|
|
2024-08-01 08:35:35 -04:00
|
|
|
#[flaky_test(tokio)]
|
2023-10-30 20:25:58 -04:00
|
|
|
async fn run_hmr_unhandled_rejection() {
|
|
|
|
let t = TempDir::new();
|
|
|
|
let file_to_watch = t.path().join("file_to_watch.js");
|
|
|
|
file_to_watch.write(
|
|
|
|
r#"
|
|
|
|
import { foo } from "./foo.jsx";
|
|
|
|
|
|
|
|
// deno-lint-ignore require-await
|
|
|
|
async function rejection() {
|
|
|
|
throw new Error("boom!");
|
|
|
|
}
|
|
|
|
|
|
|
|
let i = 0;
|
|
|
|
setInterval(() => {
|
|
|
|
if (i == 3) {
|
|
|
|
rejection();
|
|
|
|
}
|
|
|
|
console.log(i++, foo());
|
|
|
|
}, 100);
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
let file_to_watch2 = t.path().join("foo.jsx");
|
|
|
|
file_to_watch2.write(
|
|
|
|
r#"
|
|
|
|
export function foo() {
|
|
|
|
return `<h1>asd1</h1>`;
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
let mut child = util::deno_cmd()
|
2024-05-03 17:31:12 -04:00
|
|
|
.current_dir(t.path())
|
2023-10-30 20:25:58 -04:00
|
|
|
.arg("run")
|
2024-08-11 18:10:55 -04:00
|
|
|
.arg("--watch-hmr")
|
2023-10-30 20:25:58 -04:00
|
|
|
.arg("-L")
|
|
|
|
.arg("debug")
|
|
|
|
.arg(&file_to_watch)
|
|
|
|
.env("NO_COLOR", "1")
|
2023-11-17 10:05:42 -05:00
|
|
|
.piped_output()
|
2023-10-30 20:25:58 -04:00
|
|
|
.spawn()
|
|
|
|
.unwrap();
|
|
|
|
let (mut stdout_lines, mut stderr_lines) = child_lines(&mut child);
|
|
|
|
wait_contains("Process started", &mut stderr_lines).await;
|
2024-07-03 20:54:33 -04:00
|
|
|
wait_contains("Finished config loading.", &mut stderr_lines).await;
|
2023-10-30 20:25:58 -04:00
|
|
|
|
|
|
|
wait_for_watcher("file_to_watch.js", &mut stderr_lines).await;
|
|
|
|
wait_contains("2 <h1>asd1</h1>", &mut stdout_lines).await;
|
|
|
|
wait_contains("boom", &mut stderr_lines).await;
|
|
|
|
|
|
|
|
file_to_watch.write(
|
|
|
|
r#"
|
|
|
|
import { foo } from "./foo.jsx";
|
|
|
|
|
|
|
|
let i = 0;
|
|
|
|
setInterval(() => {
|
|
|
|
console.log(i++, foo());
|
|
|
|
}, 100);
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
wait_contains("Process failed", &mut stderr_lines).await;
|
|
|
|
wait_contains("File change detected", &mut stderr_lines).await;
|
|
|
|
wait_contains("<h1>asd1</h1>", &mut stdout_lines).await;
|
|
|
|
|
|
|
|
check_alive_then_kill(child);
|
|
|
|
}
|