From d39094913e91e5193f63459d9c5ca6ddc7779477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Fri, 24 Jun 2022 12:00:53 +0200 Subject: fix: don't error if Deno.bench() or Deno.test() are used in run subcommand (#14946) --- runtime/js/40_testing.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'runtime/js') 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, }; -- cgit v1.2.3