0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

perf: move "cli/js/40_testing.js" out of main snapshot (#21212)

Closes https://github.com/denoland/deno/issues/21136

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
Divy Srivastava 2023-11-24 19:46:16 -08:00 committed by GitHub
parent 7d8f0ae038
commit 89424f8e4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 1269 additions and 1233 deletions

View file

@ -320,8 +320,16 @@ impl DenoSubcommand {
matches!(self, Self::Run(_))
}
pub fn is_test_or_jupyter(&self) -> bool {
matches!(self, Self::Test(_) | Self::Jupyter(_))
// Returns `true` if the subcommand depends on testing infrastructure.
pub fn needs_test(&self) -> bool {
matches!(
self,
Self::Test(_)
| Self::Jupyter(_)
| Self::Repl(_)
| Self::Bench(_)
| Self::Lsp
)
}
}

View file

@ -331,7 +331,6 @@ deno_core::extension!(
esm_entry_point = "ext:cli/99_main.js",
esm = [
dir "js",
"40_testing.js",
"99_main.js"
],
customizer = |ext: &mut deno_core::Extension| {

View file

@ -36,7 +36,7 @@
* }, { raw: true });
* ```
*/
{
(() => {
const internals = Deno[Deno.internal];
const core = internals.core;
@ -428,4 +428,4 @@
}
internals.enableJupyter = enableJupyter;
}
})();

View file

@ -3,12 +3,12 @@
// Do not use primordials because we do not want to depend on the __bootstrap
// namespace.
//
// deno-lint-ignore-file prefer-primordials
const core = globalThis.Deno.core;
// deno-lint-ignore-file
(() => {
const internals = Deno[Deno.internal];
const core = internals.core;
const ops = core.ops;
const internals = globalThis.__bootstrap.internals;
const {
setExitHandler,
Console,
@ -262,7 +262,9 @@ function assertOps(fn) {
}
}
return { failed: { leakedOps: [details, core.isOpCallTracingEnabled()] } };
return {
failed: { leakedOps: [details, core.isOpCallTracingEnabled()] },
};
};
}
@ -520,7 +522,9 @@ function wrapInner(fn) {
if (usesSanitizer(desc) && runningStepDescs.length > 0) {
return {
failed: { hasSanitizersAndOverlaps: runningStepDescs.map(getFullName) },
failed: {
hasSanitizersAndOverlaps: runningStepDescs.map(getFullName),
},
};
}
await fn(testStates.get(desc.id).context);
@ -928,7 +932,15 @@ function compareMeasurements(a, b) {
return 0;
}
function benchStats(n, highPrecision, usedExplicitTimers, avg, min, max, all) {
function benchStats(
n,
highPrecision,
usedExplicitTimers,
avg,
min,
max,
all,
) {
return {
n,
min,
@ -1118,7 +1130,9 @@ function createBenchContext(desc) {
);
}
if (currentBenchUserExplicitStart != null) {
throw new TypeError("BenchContext::start() has already been invoked.");
throw new TypeError(
"BenchContext::start() has already been invoked.",
);
}
currentBenchUserExplicitStart = benchNow();
},
@ -1164,7 +1178,12 @@ function wrapBenchmark(desc) {
const benchTimeInMs = 500;
const context = createBenchContext(desc);
const stats = await benchMeasure(benchTimeInMs, fn, desc.async, context);
const stats = await benchMeasure(
benchTimeInMs,
fn,
desc.async,
context,
);
return { ok: stats };
} catch (error) {
@ -1254,7 +1273,9 @@ function createTestContext(desc) {
let stepDesc;
if (typeof nameOrFnOrOptions === "string") {
if (!Object.prototype.isPrototypeOf.call(Function.prototype, maybeFn)) {
if (
!Object.prototype.isPrototypeOf.call(Function.prototype, maybeFn)
) {
throw new TypeError("Expected function for second argument.");
}
stepDesc = {
@ -1350,6 +1371,6 @@ function wrapTest(desc) {
return wrapOuter(testFn, desc);
}
import { denoNs } from "ext:runtime/90_deno_ns.js";
denoNs.bench = bench;
denoNs.test = test;
globalThis.Deno.bench = bench;
globalThis.Deno.test = test;
})();

View file

@ -1,3 +1,2 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
import "ext:cli/40_testing.js";
import "ext:cli/runtime/js/99_main.js";

View file

@ -639,9 +639,13 @@ impl CliMainWorkerFactory {
options,
);
if self.shared.subcommand.is_test_or_jupyter() {
if self.shared.subcommand.needs_test() {
worker.js_runtime.execute_script_static(
"40_jupyter.js",
"ext:cli/40_testing.js",
include_str!("js/40_testing.js"),
)?;
worker.js_runtime.execute_script_static(
"ext:cli/40_jupyter.js",
include_str!("js/40_jupyter.js"),
)?;
}

View file

@ -448,6 +448,11 @@ const finalDenoNs = {
resources: core.resources,
close: core.close,
...denoNs,
// Deno.test and Deno.bench are noops here, but kept for compatibility; so
// that they don't cause errors when used outside of `deno test`/`deno bench`
// contexts.
test: () => {},
bench: () => {},
};
const {