diff options
-rw-r--r-- | cli/lsp/testing/execution.rs | 5 | ||||
-rw-r--r-- | cli/tests/integration/run_tests.rs | 5 | ||||
-rw-r--r-- | cli/tests/testdata/test_and_bench_in_run.js | 5 | ||||
-rw-r--r-- | cli/tools/bench.rs | 5 | ||||
-rw-r--r-- | cli/tools/test.rs | 5 | ||||
-rw-r--r-- | runtime/js/40_testing.js | 17 |
6 files changed, 42 insertions, 0 deletions
diff --git a/cli/lsp/testing/execution.rs b/cli/lsp/testing/execution.rs index 4f4b9bf1f..03fdba63c 100644 --- a/cli/lsp/testing/execution.rs +++ b/cli/lsp/testing/execution.rs @@ -199,6 +199,11 @@ async fn test_specifier( }, ); + worker.js_runtime.execute_script( + &located_script_name!(), + r#"Deno[Deno.internal].enableTestAndBench()"#, + )?; + worker .execute_script( &located_script_name!(), diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index fb0d6313b..09a1ba500 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -2728,3 +2728,8 @@ fn running_declaration_files() { assert!(output.status.success()); } } + +itest!(test_and_bench_are_noops_in_run { + args: "run test_and_bench_in_run.js", + output_str: Some(""), +}); diff --git a/cli/tests/testdata/test_and_bench_in_run.js b/cli/tests/testdata/test_and_bench_in_run.js new file mode 100644 index 000000000..108ae937a --- /dev/null +++ b/cli/tests/testdata/test_and_bench_in_run.js @@ -0,0 +1,5 @@ +Deno.test(function foo() { +}); + +Deno.bench(function bar() { +}); diff --git a/cli/tools/bench.rs b/cli/tools/bench.rs index e88151648..b51938d13 100644 --- a/cli/tools/bench.rs +++ b/cli/tools/bench.rs @@ -369,6 +369,11 @@ async fn bench_specifier( Default::default(), ); + worker.js_runtime.execute_script( + &located_script_name!(), + r#"Deno[Deno.internal].enableTestAndBench()"#, + )?; + if options.compat_mode { worker.execute_side_module(&compat::GLOBAL_URL).await?; worker.execute_side_module(&compat::MODULE_URL).await?; diff --git a/cli/tools/test.rs b/cli/tools/test.rs index 170c1a12d..94412a3ae 100644 --- a/cli/tools/test.rs +++ b/cli/tools/test.rs @@ -743,6 +743,11 @@ 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 { diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js index 3850e411d..13cdcd32e 100644 --- a/runtime/js/40_testing.js +++ b/runtime/js/40_testing.js @@ -554,6 +554,7 @@ const tests = []; /** @type {BenchDescription[]} */ const benchDescs = []; + let isTestOrBenchSubcommand = false; // Main test function provided by Deno. function test( @@ -561,6 +562,10 @@ optionsOrFn, maybeFn, ) { + if (!isTestOrBenchSubcommand) { + return; + } + let testDef; const defaults = { ignore: false, @@ -669,6 +674,10 @@ optionsOrFn, maybeFn, ) { + if (!isTestOrBenchSubcommand) { + return; + } + core.opSync("op_bench_check_unstable"); let benchDesc; const defaults = { @@ -1043,6 +1052,13 @@ return core.opSync("op_bench_now"); } + // This function is called by Rust side if we're in `deno test` or + // `deno bench` subcommand. If this function is not called then `Deno.test()` + // and `Deno.bench()` become noops. + function enableTestAndBench() { + isTestOrBenchSubcommand = true; + } + async function runTests({ filter = null, shuffle = null, @@ -1507,6 +1523,7 @@ window.__bootstrap.internals = { ...window.__bootstrap.internals ?? {}, + enableTestAndBench, runTests, runBenchmarks, }; |