summaryrefslogtreecommitdiff
path: root/cli/main.rs
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-07-10 07:15:15 +0800
committerGitHub <noreply@github.com>2021-07-10 01:15:15 +0200
commit9b89668065a5cd23f4326855980f7dd59182efaf (patch)
treee5d4f5971a5be84c448673dc8ae593f4c309592f /cli/main.rs
parent6aad9749d2b5203faf164cc33328174047c287e8 (diff)
fix(cli): make --doc work with --watch (#11183)
Diffstat (limited to 'cli/main.rs')
-rw-r--r--cli/main.rs88
1 files changed, 59 insertions, 29 deletions
diff --git a/cli/main.rs b/cli/main.rs
index 6069f4479..93bae0220 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -1026,17 +1026,19 @@ async fn test_command(
// TODO(caspervonb) clean this up.
let resolver = |changed: Option<Vec<PathBuf>>| {
- let doc_modules_result = test_runner::collect_test_module_specifiers(
- include.clone(),
- &cwd,
- fs_util::is_supported_ext,
- );
-
- let test_modules_result = test_runner::collect_test_module_specifiers(
- include.clone(),
- &cwd,
- tools::test_runner::is_supported,
- );
+ let test_modules_result = if doc {
+ test_runner::collect_test_module_specifiers(
+ include.clone(),
+ &cwd,
+ fs_util::is_supported_ext,
+ )
+ } else {
+ test_runner::collect_test_module_specifiers(
+ include.clone(),
+ &cwd,
+ tools::test_runner::is_supported,
+ )
+ };
let paths_to_watch = paths_to_watch.clone();
let paths_to_watch_clone = paths_to_watch.clone();
@@ -1045,8 +1047,6 @@ async fn test_command(
let program_state = program_state.clone();
let files_changed = changed.is_some();
async move {
- let doc_modules = if doc { doc_modules_result? } else { Vec::new() };
-
let test_modules = test_modules_result?;
let mut paths_to_watch = paths_to_watch_clone;
@@ -1072,12 +1072,6 @@ async fn test_command(
.await?;
let graph = builder.get_graph();
- for specifier in doc_modules {
- if let Ok(path) = specifier.to_file_path() {
- paths_to_watch.push(path);
- }
- }
-
for specifier in test_modules {
fn get_dependencies<'a>(
graph: &'a module_graph::Graph,
@@ -1165,15 +1159,49 @@ async fn test_command(
})
};
- file_watcher::watch_func(
- resolver,
- |modules_to_reload| {
+ let operation = |modules_to_reload: Vec<ModuleSpecifier>| {
+ let cwd = cwd.clone();
+ let filter = filter.clone();
+ let include = include.clone();
+ let lib = lib.clone();
+ let permissions = permissions.clone();
+ let program_state = program_state.clone();
+
+ async move {
+ let doc_modules = if doc {
+ test_runner::collect_test_module_specifiers(
+ include.clone(),
+ &cwd,
+ fs_util::is_supported_ext,
+ )?
+ } else {
+ Vec::new()
+ };
+
+ let doc_modules_to_reload = doc_modules
+ .iter()
+ .filter(|specifier| modules_to_reload.contains(specifier))
+ .cloned()
+ .collect();
+
+ let test_modules = test_runner::collect_test_module_specifiers(
+ include.clone(),
+ &cwd,
+ tools::test_runner::is_supported,
+ )?;
+
+ let test_modules_to_reload = test_modules
+ .iter()
+ .filter(|specifier| modules_to_reload.contains(specifier))
+ .cloned()
+ .collect();
+
test_runner::run_tests(
program_state.clone(),
permissions.clone(),
lib.clone(),
- modules_to_reload.clone(),
- modules_to_reload,
+ doc_modules_to_reload,
+ test_modules_to_reload,
no_run,
fail_fast,
quiet,
@@ -1182,11 +1210,13 @@ async fn test_command(
shuffle,
concurrent_jobs,
)
- .map(|res| res.map(|_| ()))
- },
- "Test",
- )
- .await?;
+ .await?;
+
+ Ok(())
+ }
+ };
+
+ file_watcher::watch_func(resolver, operation, "Test").await?;
} else {
let doc_modules = if doc {
test_runner::collect_test_module_specifiers(