1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00

fix: don't error if Deno.bench() or Deno.test() are used in run subcommand (#14946)

This commit is contained in:
Bartek Iwańczuk 2022-06-24 12:00:53 +02:00 committed by David Sherret
parent 9f9941c03b
commit 22bd1fee85
6 changed files with 42 additions and 0 deletions

View file

@ -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!(),

View file

@ -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(""),
});

View file

@ -0,0 +1,5 @@
Deno.test(function foo() {
});
Deno.bench(function bar() {
});

View file

@ -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?;

View file

@ -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
{

View file

@ -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,
};