mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 08:09:08 -05:00
refactor(testing): use discrete report functions (#11917)
This commit is contained in:
parent
bb99d5da4c
commit
01bfb7d913
1 changed files with 30 additions and 18 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue