diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-08-11 16:59:12 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-11 16:59:12 -0400 |
commit | c3b04683c55fef8929e83429ec17b7a6898c6048 (patch) | |
tree | 64190eea354854ae18f0fd993d4687b870201c6a /cli/tools/test.rs | |
parent | e4a5f9952f404e10f1b577b1477b89b155092b67 (diff) |
refactor(cli): consolidate most MainWorker related code to the same place (#15459)
Diffstat (limited to 'cli/tools/test.rs')
-rw-r--r-- | cli/tools/test.rs | 102 |
1 files changed, 2 insertions, 100 deletions
diff --git a/cli/tools/test.rs b/cli/tools/test.rs index 7df7e560d..6d24a7e4c 100644 --- a/cli/tools/test.rs +++ b/cli/tools/test.rs @@ -5,7 +5,6 @@ use crate::args::TestFlags; use crate::args::TypeCheckMode; use crate::checksum; use crate::colors; -use crate::compat; use crate::create_main_worker; use crate::display; use crate::file_fetcher::File; @@ -18,10 +17,8 @@ use crate::fs_util::is_supported_test_path; use crate::fs_util::specifier_to_file_path; use crate::graph_util::contains_specifier; use crate::graph_util::graph_valid; -use crate::located_script_name; use crate::ops; use crate::proc_state::ProcState; -use crate::tools::coverage::CoverageCollector; use deno_ast::swc::common::comments::CommentKind; use deno_ast::MediaType; @@ -34,7 +31,6 @@ use deno_core::futures::stream; use deno_core::futures::FutureExt; use deno_core::futures::StreamExt; use deno_core::parking_lot::Mutex; -use deno_core::serde_json::json; use deno_core::url::Url; use deno_core::ModuleSpecifier; use deno_graph::ModuleKind; @@ -247,12 +243,9 @@ pub struct TestSummary { #[derive(Debug, Clone)] struct TestSpecifierOptions { - compat_mode: bool, concurrent_jobs: NonZeroUsize, fail_fast: Option<NonZeroUsize>, filter: TestFilter, - shuffle: Option<u64>, - trace_ops: bool, } impl TestSummary { @@ -732,90 +725,7 @@ async fn test_specifier( }, ); - worker.js_runtime.execute_script( - &located_script_name!(), - r#"Deno[Deno.internal].enableTestAndBench()"#, - )?; - - let mut maybe_coverage_collector = if let Some(ref coverage_dir) = - ps.coverage_dir - { - let session = worker.create_inspector_session().await; - let coverage_dir = PathBuf::from(coverage_dir); - let mut coverage_collector = CoverageCollector::new(coverage_dir, session); - worker - .with_event_loop(coverage_collector.start_collecting().boxed_local()) - .await?; - - Some(coverage_collector) - } else { - None - }; - - // Enable op call tracing in core to enable better debugging of op sanitizer - // failures. - if options.trace_ops { - worker - .execute_script( - &located_script_name!(), - "Deno.core.enableOpCallTracing();", - ) - .unwrap(); - } - - // We only execute the specifier as a module if it is tagged with TestMode::Module or - // TestMode::Both. - if mode != TestMode::Documentation { - if options.compat_mode { - worker.execute_side_module(&compat::GLOBAL_URL).await?; - worker.execute_side_module(&compat::MODULE_URL).await?; - - let use_esm_loader = compat::check_if_should_use_esm_loader(&specifier)?; - - if use_esm_loader { - worker.execute_side_module(&specifier).await?; - } else { - compat::load_cjs_module( - &mut worker.js_runtime, - &specifier.to_file_path().unwrap().display().to_string(), - false, - )?; - worker.run_event_loop(false).await?; - } - } else { - // We execute the module module as a side module so that import.meta.main is not set. - worker.execute_side_module(&specifier).await?; - } - } - - worker.dispatch_load_event(&located_script_name!())?; - - let test_result = worker.js_runtime.execute_script( - &located_script_name!(), - &format!( - r#"Deno[Deno.internal].runTests({})"#, - json!({ "shuffle": options.shuffle }), - ), - )?; - - worker.js_runtime.resolve_value(test_result).await?; - - loop { - if !worker.dispatch_beforeunload_event(&located_script_name!())? { - break; - } - worker.run_event_loop(false).await?; - } - - worker.dispatch_unload_event(&located_script_name!())?; - - if let Some(coverage_collector) = maybe_coverage_collector.as_mut() { - worker - .with_event_loop(coverage_collector.stop_collecting().boxed_local()) - .await?; - } - - Ok(()) + worker.run_test_specifier(mode).await } fn extract_files_from_regex_blocks( @@ -1076,7 +986,7 @@ async fn test_specifiers( options: TestSpecifierOptions, ) -> Result<(), AnyError> { let log_level = ps.options.log_level(); - let specifiers_with_mode = if let Some(seed) = options.shuffle { + let specifiers_with_mode = if let Some(seed) = ps.options.shuffle_tests() { let mut rng = SmallRng::seed_from_u64(seed); let mut specifiers_with_mode = specifiers_with_mode.clone(); specifiers_with_mode.sort_by_key(|(specifier, _)| specifier.clone()); @@ -1405,18 +1315,14 @@ pub async fn run_tests( return Ok(()); } - let compat = ps.options.compat(); test_specifiers( ps, permissions, specifiers_with_mode, TestSpecifierOptions { - compat_mode: compat, concurrent_jobs: test_flags.concurrent_jobs, fail_fast: test_flags.fail_fast, filter: TestFilter::from_flag(&test_flags.filter), - shuffle: test_flags.shuffle, - trace_ops: test_flags.trace_ops, }, ) .await?; @@ -1561,7 +1467,6 @@ pub async fn run_tests_with_watch( let cli_options = ps.options.clone(); let operation = |modules_to_reload: Vec<(ModuleSpecifier, ModuleKind)>| { - let cli_options = cli_options.clone(); let filter = test_flags.filter.clone(); let include = include.clone(); let ignore = ignore.clone(); @@ -1595,12 +1500,9 @@ pub async fn run_tests_with_watch( permissions.clone(), specifiers_with_mode, TestSpecifierOptions { - compat_mode: cli_options.compat(), concurrent_jobs: test_flags.concurrent_jobs, fail_fast: test_flags.fail_fast, filter: TestFilter::from_flag(&filter), - shuffle: test_flags.shuffle, - trace_ops: test_flags.trace_ops, }, ) .await?; |