diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2022-09-02 18:44:45 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-02 19:44:45 +0200 |
commit | 4f8dea100e751d550a4a40d11b142fc9a7c4a5a8 (patch) | |
tree | fb104109048c308161cf9f1c74cf900367e9b60e /runtime/js/40_testing.js | |
parent | 5262937285e72419c6576ae1595d43f23e0c7b9d (diff) |
refactor(test): grab runTests() and runBenchmarks() from __bootstrap (#15420)
Diffstat (limited to 'runtime/js/40_testing.js')
-rw-r--r-- | runtime/js/40_testing.js | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js index 276fef6a6..e3a6ce324 100644 --- a/runtime/js/40_testing.js +++ b/runtime/js/40_testing.js @@ -16,6 +16,7 @@ ArrayPrototypePush, ArrayPrototypeShift, ArrayPrototypeSort, + BigInt, DateNow, Error, FunctionPrototype, @@ -600,7 +601,8 @@ const testStates = new Map(); /** @type {BenchDescription[]} */ const benchDescs = []; - let isTestOrBenchSubcommand = false; + let isTestSubcommand = false; + let isBenchSubcommand = false; // Main test function provided by Deno. function test( @@ -608,7 +610,7 @@ optionsOrFn, maybeFn, ) { - if (!isTestOrBenchSubcommand) { + if (!isTestSubcommand) { return; } @@ -727,7 +729,7 @@ optionsOrFn, maybeFn, ) { - if (!isTestOrBenchSubcommand) { + if (!isBenchSubcommand) { return; } @@ -1032,11 +1034,12 @@ return ops.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; + function enableTest() { + isTestSubcommand = true; + } + + function enableBench() { + isBenchSubcommand = true; } async function runTests({ @@ -1062,15 +1065,16 @@ if (shuffle !== null) { // http://en.wikipedia.org/wiki/Linear_congruential_generator + // Use BigInt for everything because the random seed is u64. const nextInt = (function (state) { - const m = 0x80000000; - const a = 1103515245; - const c = 12345; + const m = 0x80000000n; + const a = 1103515245n; + const c = 12345n; return function (max) { - return state = ((a * state + c) % m) % max; + return state = ((a * state + c) % m) % BigInt(max); }; - }(shuffle)); + }(BigInt(shuffle))); for (let i = filtered.length - 1; i > 0; i--) { const j = nextInt(i); @@ -1390,15 +1394,12 @@ return testFn; } - window.__bootstrap.internals = { - ...window.__bootstrap.internals ?? {}, - enableTestAndBench, - runTests, - runBenchmarks, - }; - window.__bootstrap.testing = { - test, bench, + enableBench, + enableTest, + runBenchmarks, + runTests, + test, }; })(this); |