1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 15:24:46 -05:00

chore: add test duration to WPT (#18680)

To make it easier to debug which tests are slowing us down.

Tests taking more than 5s have duration printed in red,
taking more than 1s in yellow and less than 1s are printed 
without color.
This commit is contained in:
Bartek Iwańczuk 2023-04-13 16:03:15 +02:00 committed by GitHub
parent 738bdebe13
commit 52d235391c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -217,7 +217,7 @@ async function run() {
await Deno.writeTextFile(wptreport, JSON.stringify(report));
}
const code = reportFinal(results);
const code = reportFinal(results, endTime - startTime);
Deno.exit(code);
}
@ -325,6 +325,7 @@ function assertAllExpectationsHaveTests(
async function update() {
assert(Array.isArray(rest), "filter must be array");
const startTime = new Date().getTime();
const tests = discoverTestsToRun(rest.length == 0 ? undefined : rest, true);
console.log(`Going to run ${tests.length} test files.`);
@ -346,6 +347,7 @@ async function update() {
return results;
});
const endTime = new Date().getTime();
if (json) {
await Deno.writeTextFile(json, JSON.stringify(results));
@ -394,7 +396,7 @@ async function update() {
saveExpectation(currentExpectation);
reportFinal(results);
reportFinal(results, endTime - startTime);
console.log(blue("Updated expectation.json to match reality."));
@ -428,6 +430,7 @@ function insertExpectation(
function reportFinal(
results: { test: TestToRun; result: TestResult }[],
duration: number,
): number {
const finalTotalCount = results.length;
let finalFailedCount = 0;
@ -509,7 +512,7 @@ function reportFinal(
console.log(
`\nfinal result: ${
failed ? red("failed") : green("ok")
}. ${finalPassedCount} passed; ${finalFailedCount} failed; ${finalExpectedFailedAndFailedCount} expected failure; total ${finalTotalCount}\n`,
}. ${finalPassedCount} passed; ${finalFailedCount} failed; ${finalExpectedFailedAndFailedCount} expected failure; total ${finalTotalCount} (${duration}ms)\n`,
);
return failed ? 1 : 0;
@ -564,7 +567,7 @@ function reportVariation(result: TestResult, expectation: boolean | string[]) {
console.log(
`\nfile result: ${
expectFail ? yellow("failed (expected)") : red("failed")
}. ${failReason}\n`,
}. ${failReason} (${formatDuration(result.duration)})\n`,
);
return;
}
@ -601,7 +604,9 @@ function reportVariation(result: TestResult, expectation: boolean | string[]) {
console.log(
`\nfile result: ${
failedCount > 0 ? red("failed") : green("ok")
}. ${passedCount} passed; ${failedCount} failed; ${expectedFailedAndFailedCount} expected failure; total ${totalCount}\n`,
}. ${passedCount} passed; ${failedCount} failed; ${expectedFailedAndFailedCount} expected failure; total ${totalCount} (${
formatDuration(result.duration)
})\n`,
);
}
@ -759,3 +764,13 @@ function partitionTests(tests: TestToRun[]): TestToRun[][] {
}
return Object.values(testsByKey);
}
function formatDuration(duration: number): string {
if (duration >= 5000) {
return red(`${duration}ms`);
} else if (duration >= 1000) {
return yellow(`${duration}ms`);
} else {
return `${duration}ms`;
}
}