1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 16:42:21 -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"); return core.opSync("op_get_test_origin");
} }
function dispatchTestEvent(event) { function reportTestPlan(plan) {
return core.opSync("op_dispatch_test_event", event); 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({ async function runTests({
@ -234,13 +254,7 @@ finishing test case.`;
const origin = getTestOrigin(); const origin = getTestOrigin();
const originalConsole = globalThis.console; const originalConsole = globalThis.console;
globalThis.console = new Console((line) => { globalThis.console = new Console(reportTestConsoleOutput);
dispatchTestEvent({
output: {
console: line,
},
});
});
const only = ArrayPrototypeFilter(tests, (test) => test.only); const only = ArrayPrototypeFilter(tests, (test) => test.only);
const filtered = ArrayPrototypeFilter( const filtered = ArrayPrototypeFilter(
@ -248,13 +262,11 @@ finishing test case.`;
createTestFilter(filter), createTestFilter(filter),
); );
dispatchTestEvent({ reportTestPlan({
plan: { origin,
origin, total: filtered.length,
total: filtered.length, filteredOut: tests.length - filtered.length,
filteredOut: tests.length - filtered.length, usedOnly: only.length > 0,
usedOnly: only.length > 0,
},
}); });
if (shuffle !== null) { if (shuffle !== null) {
@ -282,12 +294,12 @@ finishing test case.`;
}; };
const earlier = DateNow(); const earlier = DateNow();
dispatchTestEvent({ wait: description }); reportTestWait(description);
const result = await runTest(test); const result = await runTest(test);
const elapsed = DateNow() - earlier; const elapsed = DateNow() - earlier;
dispatchTestEvent({ result: [description, result, elapsed] }); reportTestResult(description, result, elapsed);
} }
globalThis.console = originalConsole; globalThis.console = originalConsole;