1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-23 15:49:44 -05:00

refactor(testing): use discrete report functions (#11917)

This commit is contained in:
Casper Beyer 2021-09-06 04:42:35 +08:00 committed by GitHub
parent bb99d5da4c
commit 01bfb7d913
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -223,8 +223,28 @@ finishing test case.`;
return core.opSync("op_get_test_origin");
}
function dispatchTestEvent(event) {
return core.opSync("op_dispatch_test_event", event);
function reportTestPlan(plan) {
core.opSync("op_dispatch_test_event", {
plan,
});
}
function reportTestConsoleOutput(console) {
core.opSync("op_dispatch_test_event", {
output: { console },
});
}
function reportTestWait(test) {
core.opSync("op_dispatch_test_event", {
wait: test,
});
}
function reportTestResult(test, result, elapsed) {
core.opSync("op_dispatch_test_event", {
result: [test, result, elapsed],
});
}
async function runTests({
@ -234,13 +254,7 @@ finishing test case.`;
const origin = getTestOrigin();
const originalConsole = globalThis.console;
globalThis.console = new Console((line) => {
dispatchTestEvent({
output: {
console: line,
},
});
});
globalThis.console = new Console(reportTestConsoleOutput);
const only = ArrayPrototypeFilter(tests, (test) => test.only);
const filtered = ArrayPrototypeFilter(
@ -248,13 +262,11 @@ finishing test case.`;
createTestFilter(filter),
);
dispatchTestEvent({
plan: {
origin,
total: filtered.length,
filteredOut: tests.length - filtered.length,
usedOnly: only.length > 0,
},
reportTestPlan({
origin,
total: filtered.length,
filteredOut: tests.length - filtered.length,
usedOnly: only.length > 0,
});
if (shuffle !== null) {
@ -282,12 +294,12 @@ finishing test case.`;
};
const earlier = DateNow();
dispatchTestEvent({ wait: description });
reportTestWait(description);
const result = await runTest(test);
const elapsed = DateNow() - earlier;
dispatchTestEvent({ result: [description, result, elapsed] });
reportTestResult(description, result, elapsed);
}
globalThis.console = originalConsole;