summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2021-09-18 22:12:50 +0800
committerGitHub <noreply@github.com>2021-09-18 16:12:50 +0200
commite1144fd63569a79afc211d1f981029d67bf8f5ed (patch)
tree3668cd59520de08364aa161797b3ed4cc024dd2d
parent75ca013f076f443dce3d38f31a168295351ed0e5 (diff)
refactor(cli): don't generate a module for side loading tests (#12129)
-rw-r--r--cli/tools/test.rs27
1 files changed, 6 insertions, 21 deletions
diff --git a/cli/tools/test.rs b/cli/tools/test.rs
index 0113f1e38..976855893 100644
--- a/cli/tools/test.rs
+++ b/cli/tools/test.rs
@@ -47,7 +47,6 @@ use std::sync::mpsc::Sender;
use std::sync::Arc;
use std::time::Duration;
use std::time::Instant;
-use uuid::Uuid;
/// The test mode is used to determine how a specifier is to be tested.
#[derive(Debug, Clone, PartialEq)]
@@ -256,25 +255,6 @@ async fn test_specifier(
shuffle: Option<u64>,
channel: Sender<TestEvent>,
) -> Result<(), AnyError> {
- let test_specifier =
- deno_core::resolve_path(&format!("{}$deno$test.js", Uuid::new_v4()))?;
-
- let mut test_source = String::new();
- if mode != TestMode::Documentation {
- test_source.push_str(&format!("import \"{}\";\n", specifier));
- }
-
- let test_file = File {
- local: test_specifier.to_file_path().unwrap(),
- maybe_types: None,
- media_type: MediaType::JavaScript,
- source: Arc::new(test_source),
- specifier: test_specifier.clone(),
- maybe_headers: None,
- };
-
- program_state.file_fetcher.insert_cached(test_file);
-
let init_ops = |js_runtime: &mut JsRuntime| {
ops::testing::init(js_runtime);
@@ -306,7 +286,12 @@ async fn test_specifier(
None
};
- worker.execute_main_module(&test_specifier).await?;
+ // We only execute the specifier as a module if it is tagged with TestMode::Module or
+ // TestMode::Both.
+ if mode != TestMode::Documentation {
+ // We execute the module module as a side module so that import.meta.main is not set.
+ worker.execute_side_module(&specifier).await?;
+ }
worker.js_runtime.execute_script(
&located_script_name!(),