diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2023-04-13 18:43:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-13 19:43:23 +0200 |
commit | 6e8618ae0f55bcaa4cfaaa579b4e21f9f74b117d (patch) | |
tree | dc0facd89b255b2bffe51b33920e46cb2a5d55d1 /cli/lsp/testing | |
parent | 4e53bc5a94a66858e9c141c7d807a8c9caa93403 (diff) |
refactor(cli): move runTests() and runBenchmarks() to rust (#18563)
Stores the test/bench functions in rust op state during registration.
The functions are wrapped in JS first so that they return a directly
convertible `TestResult`/`BenchResult`. Test steps are still mostly
handled in JS since they are pretty much invoked by the user. Allows
removing a bunch of infrastructure for communicating between JS and
rust. Allows using rust utilities for things like shuffling tests
(`Vec::shuffle`). We can progressively move op and resource sanitization
to rust as well.
Fixes #17122.
Fixes #17312.
Diffstat (limited to 'cli/lsp/testing')
-rw-r--r-- | cli/lsp/testing/execution.rs | 77 |
1 files changed, 14 insertions, 63 deletions
diff --git a/cli/lsp/testing/execution.rs b/cli/lsp/testing/execution.rs index 466c0d942..020dd5c08 100644 --- a/cli/lsp/testing/execution.rs +++ b/cli/lsp/testing/execution.rs @@ -10,13 +10,11 @@ use crate::lsp::client::Client; use crate::lsp::client::TestingNotification; use crate::lsp::config; use crate::lsp::logging::lsp_log; -use crate::ops; use crate::proc_state; use crate::tools::test; use crate::tools::test::FailFastTracker; use crate::tools::test::TestEventSender; use crate::util::checksum; -use crate::worker::create_main_worker_for_test_or_bench; use deno_core::anyhow::anyhow; use deno_core::error::AnyError; @@ -27,10 +25,7 @@ use deno_core::futures::StreamExt; use deno_core::parking_lot::Mutex; use deno_core::parking_lot::RwLock; use deno_core::ModuleSpecifier; -use deno_runtime::deno_io::Stdio; -use deno_runtime::deno_io::StdioPipe; use deno_runtime::permissions::Permissions; -use deno_runtime::permissions::PermissionsContainer; use deno_runtime::tokio_util::run_local; use indexmap::IndexMap; use std::collections::HashMap; @@ -147,42 +142,6 @@ impl LspTestFilter { } } -#[allow(clippy::too_many_arguments)] -async fn test_specifier( - ps: proc_state::ProcState, - permissions: Permissions, - specifier: ModuleSpecifier, - mode: test::TestMode, - sender: TestEventSender, - fail_fast_tracker: FailFastTracker, - token: CancellationToken, - filter: test::TestFilter, -) -> Result<(), AnyError> { - if !token.is_cancelled() { - let stdout = StdioPipe::File(sender.stdout()); - let stderr = StdioPipe::File(sender.stderr()); - let mut worker = create_main_worker_for_test_or_bench( - &ps, - specifier.clone(), - PermissionsContainer::new(permissions), - vec![ops::testing::deno_test::init_ops( - sender, - fail_fast_tracker, - filter, - )], - Stdio { - stdin: StdioPipe::Inherit, - stdout, - stderr, - }, - ) - .await?; - worker.run_lsp_test_specifier(mode).await?; - } - - Ok(()) -} - #[derive(Debug, Clone)] pub struct TestRun { id: u32, @@ -300,7 +259,6 @@ impl TestRun { Arc::new(RwLock::new(IndexMap::new())); let mut test_steps = IndexMap::new(); - let tests_ = tests.clone(); let join_handles = queue.into_iter().map(move |specifier| { let specifier = specifier.clone(); let ps = ps.clone(); @@ -321,38 +279,30 @@ impl TestRun { .unwrap_or_default(), }; let token = self.token.clone(); - let tests = tests_.clone(); tokio::task::spawn_blocking(move || { if fail_fast_tracker.should_stop() { return Ok(()); } let origin = specifier.to_string(); - let file_result = run_local(test_specifier( - ps, - permissions, - specifier, - test::TestMode::Executable, - sender.clone(), - fail_fast_tracker, - token, - filter, - )); + let file_result = if token.is_cancelled() { + Ok(()) + } else { + run_local(test::test_specifier( + &ps, + permissions, + specifier, + sender.clone(), + fail_fast_tracker, + filter, + )) + }; if let Err(error) = file_result { if error.is::<JsError>() { sender.send(test::TestEvent::UncaughtError( - origin.clone(), + origin, Box::new(error.downcast::<JsError>().unwrap()), ))?; - for desc in tests.read().values() { - if desc.origin == origin { - sender.send(test::TestEvent::Result( - desc.id, - test::TestResult::Cancelled, - 0, - ))? - } - } } else { return Err(error); } @@ -489,6 +439,7 @@ impl TestRun { .iter() .map(|s| s.as_str()), ); + args.push("--trace-ops"); if self.workspace_settings.unstable && !args.contains(&"--unstable") { args.push("--unstable"); } |