summaryrefslogtreecommitdiff
path: root/cli/tools/test.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tools/test.rs')
-rw-r--r--cli/tools/test.rs69
1 files changed, 41 insertions, 28 deletions
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index 0bdcb8860..429bee71b 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -7,7 +7,9 @@ use crate::args::TypeCheckMode;
use crate::colors;
use crate::display;
use crate::file_fetcher::File;
+use crate::file_fetcher::FileFetcher;
use crate::graph_util::graph_valid_with_cli_options;
+use crate::module_loader::ModuleLoadPreparer;
use crate::ops;
use crate::proc_state::ProcState;
use crate::util::checksum;
@@ -49,7 +51,6 @@ use rand::seq::SliceRandom;
use rand::SeedableRng;
use regex::Regex;
use serde::Deserialize;
-use std::cell::RefCell;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::HashMap;
@@ -1200,13 +1201,13 @@ fn extract_files_from_fenced_blocks(
}
async fn fetch_inline_files(
- ps: &ProcState,
+ file_fetcher: &FileFetcher,
specifiers: Vec<ModuleSpecifier>,
) -> Result<Vec<File>, AnyError> {
let mut files = Vec::new();
for specifier in specifiers {
let fetch_permissions = PermissionsContainer::allow_all();
- let file = ps.file_fetcher.fetch(&specifier, fetch_permissions).await?;
+ let file = file_fetcher.fetch(&specifier, fetch_permissions).await?;
let inline_files = if file.media_type == MediaType::Unknown {
extract_files_from_fenced_blocks(
@@ -1230,12 +1231,14 @@ async fn fetch_inline_files(
/// Type check a collection of module and document specifiers.
pub async fn check_specifiers(
- ps: &ProcState,
+ cli_options: &CliOptions,
+ file_fetcher: &FileFetcher,
+ module_load_preparer: &ModuleLoadPreparer,
specifiers: Vec<(ModuleSpecifier, TestMode)>,
) -> Result<(), AnyError> {
- let lib = ps.options.ts_type_lib_window();
+ let lib = cli_options.ts_type_lib_window();
let inline_files = fetch_inline_files(
- ps,
+ file_fetcher,
specifiers
.iter()
.filter_map(|(specifier, mode)| {
@@ -1256,10 +1259,10 @@ pub async fn check_specifiers(
.collect();
for file in inline_files {
- ps.file_fetcher.insert_cached(file);
+ file_fetcher.insert_cached(file);
}
- ps.module_load_preparer
+ module_load_preparer
.prepare_module_load(
specifiers,
false,
@@ -1280,7 +1283,7 @@ pub async fn check_specifiers(
})
.collect();
- ps.module_load_preparer
+ module_load_preparer
.prepare_module_load(
module_specifiers,
false,
@@ -1601,15 +1604,14 @@ fn collect_specifiers_with_test_mode(
/// cannot be run, and therefore need to be marked as `TestMode::Documentation`
/// as well.
async fn fetch_specifiers_with_test_mode(
- ps: &ProcState,
+ file_fetcher: &FileFetcher,
files: &FilesConfig,
doc: &bool,
) -> Result<Vec<(ModuleSpecifier, TestMode)>, AnyError> {
let mut specifiers_with_mode = collect_specifiers_with_test_mode(files, doc)?;
for (specifier, mode) in &mut specifiers_with_mode {
- let file = ps
- .file_fetcher
+ let file = file_fetcher
.fetch(specifier, PermissionsContainer::allow_all())
.await?;
@@ -1636,7 +1638,7 @@ pub async fn run_tests(
let log_level = ps.options.log_level();
let specifiers_with_mode = fetch_specifiers_with_test_mode(
- &ps,
+ &ps.file_fetcher,
&test_options.files,
&test_options.doc,
)
@@ -1646,13 +1648,19 @@ pub async fn run_tests(
return Err(generic_error("No test modules found"));
}
- check_specifiers(&ps, specifiers_with_mode.clone()).await?;
+ check_specifiers(
+ &ps.options,
+ &ps.file_fetcher,
+ &ps.module_load_preparer,
+ specifiers_with_mode.clone(),
+ )
+ .await?;
if test_options.no_run {
return Ok(());
}
- let worker_factory = Arc::new(ps.into_cli_main_worker_factory());
+ let worker_factory = Arc::new(ps.create_cli_main_worker_factory());
test_specifiers(
worker_factory,
@@ -1693,14 +1701,13 @@ pub async fn run_tests_with_watch(
let no_check = ps.options.type_check_mode() == TypeCheckMode::None;
let log_level = ps.options.log_level();
- let ps = RefCell::new(ps);
-
let resolver = |changed: Option<Vec<PathBuf>>| {
let paths_to_watch = test_options.files.include.clone();
let paths_to_watch_clone = paths_to_watch.clone();
let files_changed = changed.is_some();
let test_options = &test_options;
- let ps = ps.borrow().clone();
+ let cli_options = ps.options.clone();
+ let module_graph_builder = ps.module_graph_builder.clone();
async move {
let test_modules = if test_options.doc {
@@ -1715,11 +1722,10 @@ pub async fn run_tests_with_watch(
} else {
test_modules.clone()
};
- let graph = ps
- .module_graph_builder
+ let graph = module_graph_builder
.create_graph(test_modules.clone())
.await?;
- graph_valid_with_cli_options(&graph, &test_modules, &ps.options)?;
+ graph_valid_with_cli_options(&graph, &test_modules, &cli_options)?;
// TODO(@kitsonk) - This should be totally derivable from the graph.
for specifier in test_modules {
@@ -1812,12 +1818,15 @@ pub async fn run_tests_with_watch(
let operation = |modules_to_reload: Vec<ModuleSpecifier>| {
let permissions = &permissions;
let test_options = &test_options;
- ps.borrow_mut().reset_for_file_watcher();
- let ps = ps.borrow().clone();
+ ps.reset_for_file_watcher();
+ let cli_options = ps.options.clone();
+ let file_fetcher = ps.file_fetcher.clone();
+ let module_load_preparer = ps.module_load_preparer.clone();
+ let worker_factory = Arc::new(ps.create_cli_main_worker_factory());
async move {
let specifiers_with_mode = fetch_specifiers_with_test_mode(
- &ps,
+ &file_fetcher,
&test_options.files,
&test_options.doc,
)
@@ -1826,14 +1835,18 @@ pub async fn run_tests_with_watch(
.filter(|(specifier, _)| modules_to_reload.contains(specifier))
.collect::<Vec<(ModuleSpecifier, TestMode)>>();
- check_specifiers(&ps, specifiers_with_mode.clone()).await?;
+ check_specifiers(
+ &cli_options,
+ &file_fetcher,
+ &module_load_preparer,
+ specifiers_with_mode.clone(),
+ )
+ .await?;
if test_options.no_run {
return Ok(());
}
- let worker_factory = Arc::new(ps.into_cli_main_worker_factory());
-
test_specifiers(
worker_factory,
permissions,
@@ -1874,7 +1887,7 @@ pub async fn run_tests_with_watch(
}
});
- let clear_screen = !ps.borrow().options.no_clear_screen();
+ let clear_screen = !ps.options.no_clear_screen();
file_watcher::watch_func(
resolver,
operation,