Skip to content

Commit

Permalink
Add test time spent count (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
Justinidlerz authored Mar 11, 2023
1 parent a8eccfd commit 6d332ec
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions test/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ async function startEsmServer(onStart: () => void, single: boolean) {
await p.status();
}

async function runTest(name: string, retry?: boolean) {
async function runTest(name: string, retry?: boolean): Promise<number> {
const execBegin = Date.now();
const cmd = [
Deno.execPath(),
"test",
Expand All @@ -50,11 +51,12 @@ async function runTest(name: string, retry?: boolean) {
if (!retry) {
console.log("something wrong, retry...");
await new Promise((resolve) => setTimeout(resolve, 100));
await runTest(name, true);
return await runTest(name, true);
} else {
Deno.exit(code);
}
}
return Date.now() - execBegin
}

async function runCliTest() {
Expand Down Expand Up @@ -140,17 +142,18 @@ export async function existsFile(path: string): Promise<boolean> {
if (import.meta.main) {
const [testDir] = Deno.args;
startEsmServer(async () => {
let spentTimeCount = 0;
if (testDir) {
await runTest(testDir, true);
spentTimeCount += await runTest(testDir, true);
} else {
await runCliTest();
for await (const entry of Deno.readDir("./test")) {
if (entry.isDirectory && !entry.name.startsWith("_")) {
await runTest(entry.name);
spentTimeCount += await runTest(entry.name);
}
}
}
console.log("Done!");
console.log(`Done! Total time spent: ${spentTimeCount}`);
Deno.exit(0);
}, Boolean(testDir));
}

0 comments on commit 6d332ec

Please sign in to comment.