diff options
author | Casper Beyer <caspervonb@pm.me> | 2021-04-29 02:17:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-28 20:17:04 +0200 |
commit | c455c28b834683f6516422dbf1b020fbb2c1bbb6 (patch) | |
tree | 96e1484f4853969ae46539c26ffd8d716f409eb7 /cli/program_state.rs | |
parent | 0260b488fbba9a43c64641428d3603b8761067a4 (diff) |
feat(test): run test modules in parallel (#9815)
This commit adds support for running test in parallel.
Entire test runner functionality has been rewritten
from JavaScript to Rust and a set of ops was added to support reporting in Rust.
A new "--jobs" flag was added to "deno test" that allows to configure
how many threads will be used. When given no value it defaults to 2.
Diffstat (limited to 'cli/program_state.rs')
-rw-r--r-- | cli/program_state.rs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/cli/program_state.rs b/cli/program_state.rs index c52f4efef..de6331b89 100644 --- a/cli/program_state.rs +++ b/cli/program_state.rs @@ -133,6 +133,72 @@ impl ProgramState { Ok(Arc::new(program_state)) } + /// Prepares a set of module specifiers for loading in one shot. + /// + pub async fn prepare_module_graph( + self: &Arc<Self>, + specifiers: Vec<ModuleSpecifier>, + lib: TypeLib, + runtime_permissions: Permissions, + maybe_import_map: Option<ImportMap>, + ) -> Result<(), AnyError> { + let handler = Arc::new(Mutex::new(FetchHandler::new( + self, + runtime_permissions.clone(), + )?)); + + let mut builder = + GraphBuilder::new(handler, maybe_import_map, self.lockfile.clone()); + + for specifier in specifiers { + builder.add(&specifier, false).await?; + } + + let mut graph = builder.get_graph(); + let debug = self.flags.log_level == Some(log::Level::Debug); + let maybe_config_path = self.flags.config_path.clone(); + + let result_modules = if self.flags.no_check { + let result_info = graph.transpile(TranspileOptions { + debug, + maybe_config_path, + reload: self.flags.reload, + })?; + debug!("{}", result_info.stats); + if let Some(ignored_options) = result_info.maybe_ignored_options { + warn!("{}", ignored_options); + } + result_info.loadable_modules + } else { + let result_info = graph.check(CheckOptions { + debug, + emit: true, + lib, + maybe_config_path, + reload: self.flags.reload, + })?; + + debug!("{}", result_info.stats); + if let Some(ignored_options) = result_info.maybe_ignored_options { + eprintln!("{}", ignored_options); + } + if !result_info.diagnostics.is_empty() { + return Err(anyhow!(result_info.diagnostics)); + } + result_info.loadable_modules + }; + + let mut loadable_modules = self.modules.lock().unwrap(); + loadable_modules.extend(result_modules); + + if let Some(ref lockfile) = self.lockfile { + let g = lockfile.lock().unwrap(); + g.write()?; + } + + Ok(()) + } + /// This function is called when new module load is /// initialized by the JsRuntime. Its resposibility is to collect /// all dependencies and if it is required then also perform TS typecheck |