mirror of
https://github.com/denoland/deno.git
synced 2025-09-28 05:04:48 +00: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:
parent
7d8f0ae038
commit
89424f8e4a
7 changed files with 1269 additions and 1233 deletions
|
@ -320,8 +320,16 @@ impl DenoSubcommand {
|
||||||
matches!(self, Self::Run(_))
|
matches!(self, Self::Run(_))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_test_or_jupyter(&self) -> bool {
|
// Returns `true` if the subcommand depends on testing infrastructure.
|
||||||
matches!(self, Self::Test(_) | Self::Jupyter(_))
|
pub fn needs_test(&self) -> bool {
|
||||||
|
matches!(
|
||||||
|
self,
|
||||||
|
Self::Test(_)
|
||||||
|
| Self::Jupyter(_)
|
||||||
|
| Self::Repl(_)
|
||||||
|
| Self::Bench(_)
|
||||||
|
| Self::Lsp
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -331,7 +331,6 @@ deno_core::extension!(
|
||||||
esm_entry_point = "ext:cli/99_main.js",
|
esm_entry_point = "ext:cli/99_main.js",
|
||||||
esm = [
|
esm = [
|
||||||
dir "js",
|
dir "js",
|
||||||
"40_testing.js",
|
|
||||||
"99_main.js"
|
"99_main.js"
|
||||||
],
|
],
|
||||||
customizer = |ext: &mut deno_core::Extension| {
|
customizer = |ext: &mut deno_core::Extension| {
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
* }, { raw: true });
|
* }, { raw: true });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
{
|
(() => {
|
||||||
const internals = Deno[Deno.internal];
|
const internals = Deno[Deno.internal];
|
||||||
const core = internals.core;
|
const core = internals.core;
|
||||||
|
|
||||||
|
@ -428,4 +428,4 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
internals.enableJupyter = enableJupyter;
|
internals.enableJupyter = enableJupyter;
|
||||||
}
|
})();
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
// Do not use primordials because we do not want to depend on the __bootstrap
|
// Do not use primordials because we do not want to depend on the __bootstrap
|
||||||
// namespace.
|
// namespace.
|
||||||
//
|
//
|
||||||
// deno-lint-ignore-file prefer-primordials
|
// deno-lint-ignore-file
|
||||||
|
(() => {
|
||||||
const core = globalThis.Deno.core;
|
const internals = Deno[Deno.internal];
|
||||||
|
const core = internals.core;
|
||||||
const ops = core.ops;
|
const ops = core.ops;
|
||||||
|
|
||||||
const internals = globalThis.__bootstrap.internals;
|
|
||||||
const {
|
const {
|
||||||
setExitHandler,
|
setExitHandler,
|
||||||
Console,
|
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) {
|
if (usesSanitizer(desc) && runningStepDescs.length > 0) {
|
||||||
return {
|
return {
|
||||||
failed: { hasSanitizersAndOverlaps: runningStepDescs.map(getFullName) },
|
failed: {
|
||||||
|
hasSanitizersAndOverlaps: runningStepDescs.map(getFullName),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
await fn(testStates.get(desc.id).context);
|
await fn(testStates.get(desc.id).context);
|
||||||
|
@ -928,7 +932,15 @@ function compareMeasurements(a, b) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function benchStats(n, highPrecision, usedExplicitTimers, avg, min, max, all) {
|
function benchStats(
|
||||||
|
n,
|
||||||
|
highPrecision,
|
||||||
|
usedExplicitTimers,
|
||||||
|
avg,
|
||||||
|
min,
|
||||||
|
max,
|
||||||
|
all,
|
||||||
|
) {
|
||||||
return {
|
return {
|
||||||
n,
|
n,
|
||||||
min,
|
min,
|
||||||
|
@ -1118,7 +1130,9 @@ function createBenchContext(desc) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (currentBenchUserExplicitStart != null) {
|
if (currentBenchUserExplicitStart != null) {
|
||||||
throw new TypeError("BenchContext::start() has already been invoked.");
|
throw new TypeError(
|
||||||
|
"BenchContext::start() has already been invoked.",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
currentBenchUserExplicitStart = benchNow();
|
currentBenchUserExplicitStart = benchNow();
|
||||||
},
|
},
|
||||||
|
@ -1164,7 +1178,12 @@ function wrapBenchmark(desc) {
|
||||||
|
|
||||||
const benchTimeInMs = 500;
|
const benchTimeInMs = 500;
|
||||||
const context = createBenchContext(desc);
|
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 };
|
return { ok: stats };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -1254,7 +1273,9 @@ function createTestContext(desc) {
|
||||||
|
|
||||||
let stepDesc;
|
let stepDesc;
|
||||||
if (typeof nameOrFnOrOptions === "string") {
|
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.");
|
throw new TypeError("Expected function for second argument.");
|
||||||
}
|
}
|
||||||
stepDesc = {
|
stepDesc = {
|
||||||
|
@ -1350,6 +1371,6 @@ function wrapTest(desc) {
|
||||||
return wrapOuter(testFn, desc);
|
return wrapOuter(testFn, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
import { denoNs } from "ext:runtime/90_deno_ns.js";
|
globalThis.Deno.bench = bench;
|
||||||
denoNs.bench = bench;
|
globalThis.Deno.test = test;
|
||||||
denoNs.test = test;
|
})();
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
// 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";
|
import "ext:cli/runtime/js/99_main.js";
|
||||||
|
|
|
@ -639,9 +639,13 @@ impl CliMainWorkerFactory {
|
||||||
options,
|
options,
|
||||||
);
|
);
|
||||||
|
|
||||||
if self.shared.subcommand.is_test_or_jupyter() {
|
if self.shared.subcommand.needs_test() {
|
||||||
worker.js_runtime.execute_script_static(
|
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"),
|
include_str!("js/40_jupyter.js"),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -448,6 +448,11 @@ const finalDenoNs = {
|
||||||
resources: core.resources,
|
resources: core.resources,
|
||||||
close: core.close,
|
close: core.close,
|
||||||
...denoNs,
|
...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 {
|
const {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue