summaryrefslogtreecommitdiff
path: root/cli/js
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2023-09-26 11:21:18 +0900
committerGitHub <noreply@github.com>2023-09-26 02:21:18 +0000
commit8e1304ced4e04e8fac20948ea8ea89362a06ac47 (patch)
treeb289509f9778d47effcb33effcd340b65facb268 /cli/js
parenta879f8c9fa5a2dd6da00b67711c025c300e9b600 (diff)
perf(test): use fast ops for deno test register (#20670)
Use fast ops for test registration. This speeds up `Deno.test` and `t.step()` significantly (2x over Deno 1.37.0).
Diffstat (limited to 'cli/js')
-rw-r--r--cli/js/40_testing.js41
1 files changed, 33 insertions, 8 deletions
diff --git a/cli/js/40_testing.js b/cli/js/40_testing.js
index cf779ee07..8139635f9 100644
--- a/cli/js/40_testing.js
+++ b/cli/js/40_testing.js
@@ -675,6 +675,9 @@ let currentBenchUserExplicitStart = null;
/** @type {number | null} */
let currentBenchUserExplicitEnd = null;
+const registerTestIdRetBuf = new Uint32Array(1);
+const registerTestIdRetBufU8 = new Uint8Array(registerTestIdRetBuf.buffer);
+
function testInner(
nameOrFnOrOptions,
optionsOrFn,
@@ -774,8 +777,17 @@ function testInner(
testDesc.fn = wrapTest(testDesc);
testDesc.name = escapeName(testDesc.name);
- const { id, origin } = ops.op_register_test(testDesc);
- testDesc.id = id;
+ const origin = ops.op_register_test(
+ testDesc.fn,
+ testDesc.name,
+ testDesc.ignore,
+ testDesc.only,
+ testDesc.location.fileName,
+ testDesc.location.lineNumber,
+ testDesc.location.columnNumber,
+ registerTestIdRetBufU8,
+ );
+ testDesc.id = registerTestIdRetBuf[0];
testDesc.origin = origin;
MapPrototypeSet(testStates, testDesc.id, {
context: createTestContext(testDesc),
@@ -1212,9 +1224,13 @@ function stepReportResult(desc, result, elapsed) {
for (const childDesc of state.children) {
stepReportResult(childDesc, { failed: "incomplete" }, 0);
}
- ops.op_dispatch_test_event({
- stepResult: [desc.id, result, elapsed],
- });
+ if (result === "ok") {
+ ops.op_test_event_step_result_ok(desc.id, elapsed);
+ } else if (result === "ignored") {
+ ops.op_test_event_step_result_ignored(desc.id, elapsed);
+ } else {
+ ops.op_test_event_step_result_failed(desc.id, result.failed, elapsed);
+ }
}
/** @param desc {TestDescription | TestStepDescription} */
@@ -1300,9 +1316,18 @@ function createTestContext(desc) {
stepDesc.name = escapeName(stepDesc.name);
stepDesc.rootName = escapeName(rootName);
stepDesc.fn = wrapTest(stepDesc);
- const { id, origin } = ops.op_register_test_step(stepDesc);
+ const id = ops.op_register_test_step(
+ stepDesc.name,
+ stepDesc.location.fileName,
+ stepDesc.location.lineNumber,
+ stepDesc.location.columnNumber,
+ stepDesc.level,
+ stepDesc.parent.id,
+ stepDesc.rootId,
+ stepDesc.rootName,
+ );
stepDesc.id = id;
- stepDesc.origin = origin;
+ stepDesc.origin = desc.origin;
const state = {
context: createTestContext(stepDesc),
children: [],
@@ -1315,7 +1340,7 @@ function createTestContext(desc) {
stepDesc,
);
- ops.op_dispatch_test_event({ stepWait: stepDesc.id });
+ ops.op_test_event_step_wait(stepDesc.id);
const earlier = DateNow();
const result = await stepDesc.fn(stepDesc);
const elapsed = DateNow() - earlier;