From 0c9b6b63ffef41f889c34b05a32ad3787a29a536 Mon Sep 17 00:00:00 2001 From: Eugen Cazacu <32613393+oygen87@users.noreply.github.com> Date: Fri, 9 Aug 2019 00:26:39 +0200 Subject: [PATCH 1/6] print out the failed tests after the summary --- testing/mod.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/testing/mod.ts b/testing/mod.ts index 462c13fb1691..8c9d33c9a577 100644 --- a/testing/mod.ts +++ b/testing/mod.ts @@ -102,6 +102,7 @@ export function test(t: TestDefinition | TestFunction): void { const RED_FAILED = red("FAILED"); const GREEN_OK = green("OK"); +const RED_BG_FAIL = bgRed(" FAIL "); interface TestStats { filtered: number; @@ -184,7 +185,7 @@ function printResults( } // Attempting to match the output of Rust's test runner. print( - `\ntest result: ${stats.failed ? RED_FAILED : GREEN_OK}. ` + + `\ntest result: ${stats.failed ? RED_BG_FAIL : GREEN_OK} ` + `${stats.passed} passed; ${stats.failed} failed; ` + `${stats.ignored} ignored; ${stats.measured} measured; ` + `${stats.filtered} filtered out ` + @@ -254,7 +255,8 @@ async function runTestsSerial( tests: TestDefinition[], exitOnFail: boolean, disableLog: boolean -): Promise { +): Promise { + const failed = []; for (const { fn, name } of tests) { // Displaying the currently running test if silent mode if (disableLog) { @@ -280,11 +282,12 @@ async function runTestsSerial( print(`${RED_FAILED} ${name}`); print(err.stack); stats.failed++; + failed.push(name); if (exitOnFail) { break; } } - } + } return failed; } /** Defines options for controlling execution details of a test suite. */ @@ -320,6 +323,7 @@ export async function runTests({ const results: TestResults = createTestResults(tests); print(`running ${tests.length} tests`); const start = performance.now(); + let failedTests: string[]; if (Deno.args.includes("--quiet")) { disableLog = true; } @@ -329,7 +333,7 @@ export async function runTests({ if (parallel) { await runTestsParallel(stats, results, tests, exitOnFail); } else { - await runTestsSerial(stats, tests, exitOnFail, disableLog); + failedTests = await runTestsSerial(stats, tests, exitOnFail, disableLog); } const end = performance.now(); if (disableLog) { @@ -341,6 +345,7 @@ export async function runTests({ // promise rejections being swallowed. setTimeout((): void => { console.error(`There were ${stats.failed} test failures.`); + failedTests.forEach(failedTest => console.error(`${RED_BG_FAIL} ${red(failedTest)}`)); Deno.exit(1); }, 0); } From 6894720f733a37b2bb885a39ae37dcbbf086a5e2 Mon Sep 17 00:00:00 2001 From: Eugen Cazacu <32613393+oygen87@users.noreply.github.com> Date: Fri, 9 Aug 2019 00:38:07 +0200 Subject: [PATCH 2/6] formatting --- testing/mod.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/testing/mod.ts b/testing/mod.ts index 8c9d33c9a577..1fb5ab131de3 100644 --- a/testing/mod.ts +++ b/testing/mod.ts @@ -287,7 +287,8 @@ async function runTestsSerial( break; } } - } return failed; + } + return failed; } /** Defines options for controlling execution details of a test suite. */ @@ -345,7 +346,9 @@ export async function runTests({ // promise rejections being swallowed. setTimeout((): void => { console.error(`There were ${stats.failed} test failures.`); - failedTests.forEach(failedTest => console.error(`${RED_BG_FAIL} ${red(failedTest)}`)); + failedTests.forEach(failedTest => + console.error(`${RED_BG_FAIL} ${red(failedTest)}`) + ); Deno.exit(1); }, 0); } From 22407cffd0721b40f8619ff97d747d05eb858a30 Mon Sep 17 00:00:00 2001 From: Eugen Cazacu <32613393+oygen87@users.noreply.github.com> Date: Fri, 9 Aug 2019 00:47:52 +0200 Subject: [PATCH 3/6] fix eslint warning --- testing/mod.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/testing/mod.ts b/testing/mod.ts index 1fb5ab131de3..60293bbfed8b 100644 --- a/testing/mod.ts +++ b/testing/mod.ts @@ -346,8 +346,10 @@ export async function runTests({ // promise rejections being swallowed. setTimeout((): void => { console.error(`There were ${stats.failed} test failures.`); - failedTests.forEach(failedTest => - console.error(`${RED_BG_FAIL} ${red(failedTest)}`) + failedTests.forEach( + (failedTest): void => { + console.error(`${RED_BG_FAIL} ${red(failedTest)}`); + } ); Deno.exit(1); }, 0); From 94f80236f96844fecc93d366934b9149d1a2fb9c Mon Sep 17 00:00:00 2001 From: Eugen Cazacu <32613393+oygen87@users.noreply.github.com> Date: Fri, 9 Aug 2019 17:36:53 +0200 Subject: [PATCH 4/6] Populate and use TestResult. option to show error. use existing model that didnt get populated with test results. only initialized to default values. Show error message underneith aswell, but added option so we can turn it off. but usually we want to know what the error is and not only the name(just like when we run the tests and print out the error, now we see them at the bottom summary too) --- testing/mod.ts | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/testing/mod.ts b/testing/mod.ts index 60293bbfed8b..c4f28c7c36dc 100644 --- a/testing/mod.ts +++ b/testing/mod.ts @@ -104,6 +104,8 @@ const RED_FAILED = red("FAILED"); const GREEN_OK = green("OK"); const RED_BG_FAIL = bgRed(" FAIL "); +const VERBOSE = true; + interface TestStats { filtered: number; ignored: number; @@ -166,6 +168,19 @@ function report(result: TestResult): void { result.printed = true; } +function printFailedSummary(results: TestResults, verbose: boolean): void { + results.cases.forEach( + (v): void => { + if (!v.ok) { + console.error(`${RED_BG_FAIL} ${red(v.name)}`); + if (verbose) { + console.error(v.error); + } + } + } + ); +} + function printResults( stats: TestStats, results: TestResults, @@ -252,11 +267,11 @@ async function runTestsParallel( async function runTestsSerial( stats: TestStats, + results: TestResults, tests: TestDefinition[], exitOnFail: boolean, disableLog: boolean -): Promise { - const failed = []; +): Promise { for (const { fn, name } of tests) { // Displaying the currently running test if silent mode if (disableLog) { @@ -275,6 +290,14 @@ async function runTestsSerial( print( GREEN_OK + " " + name + " " + promptTestTime(end - start, true) ); + results.cases.forEach( + (v): void => { + if (v.name === name) { + v.ok = true; + v.printed = true; + } + } + ); } catch (err) { if (disableLog) { print(CLEAR_LINE, false); @@ -282,13 +305,20 @@ async function runTestsSerial( print(`${RED_FAILED} ${name}`); print(err.stack); stats.failed++; - failed.push(name); + results.cases.forEach( + (v): void => { + if (v.name === name) { + v.error = err; + v.ok = false; + v.printed = true; + } + } + ); if (exitOnFail) { break; } } } - return failed; } /** Defines options for controlling execution details of a test suite. */ @@ -324,7 +354,6 @@ export async function runTests({ const results: TestResults = createTestResults(tests); print(`running ${tests.length} tests`); const start = performance.now(); - let failedTests: string[]; if (Deno.args.includes("--quiet")) { disableLog = true; } @@ -334,7 +363,7 @@ export async function runTests({ if (parallel) { await runTestsParallel(stats, results, tests, exitOnFail); } else { - failedTests = await runTestsSerial(stats, tests, exitOnFail, disableLog); + await runTestsSerial(stats, results, tests, exitOnFail, disableLog); } const end = performance.now(); if (disableLog) { @@ -346,11 +375,7 @@ export async function runTests({ // promise rejections being swallowed. setTimeout((): void => { console.error(`There were ${stats.failed} test failures.`); - failedTests.forEach( - (failedTest): void => { - console.error(`${RED_BG_FAIL} ${red(failedTest)}`); - } - ); + printFailedSummary(results, VERBOSE); Deno.exit(1); }, 0); } From b10b1ef029325dd34b58d2c217c62dadb1b8abbc Mon Sep 17 00:00:00 2001 From: Eugen Cazacu <32613393+oygen87@users.noreply.github.com> Date: Fri, 9 Aug 2019 22:35:02 +0200 Subject: [PATCH 5/6] --verbose show errors/stacktrace in test summary --- testing/mod.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/testing/mod.ts b/testing/mod.ts index c4f28c7c36dc..4dabf5e88e51 100644 --- a/testing/mod.ts +++ b/testing/mod.ts @@ -104,8 +104,6 @@ const RED_FAILED = red("FAILED"); const GREEN_OK = green("OK"); const RED_BG_FAIL = bgRed(" FAIL "); -const VERBOSE = true; - interface TestStats { filtered: number; ignored: number; @@ -168,12 +166,12 @@ function report(result: TestResult): void { result.printed = true; } -function printFailedSummary(results: TestResults, verbose: boolean): void { +function printFailedSummary(results: TestResults): void { results.cases.forEach( (v): void => { if (!v.ok) { console.error(`${RED_BG_FAIL} ${red(v.name)}`); - if (verbose) { + if (Deno.args.includes("--verbose")) { console.error(v.error); } } @@ -375,7 +373,7 @@ export async function runTests({ // promise rejections being swallowed. setTimeout((): void => { console.error(`There were ${stats.failed} test failures.`); - printFailedSummary(results, VERBOSE); + printFailedSummary(results); Deno.exit(1); }, 0); } From 412fed8c7dc663de2c43f6b1e5ccc339d0b45785 Mon Sep 17 00:00:00 2001 From: Eugen Cazacu <32613393+oygen87@users.noreply.github.com> Date: Sat, 10 Aug 2019 10:54:31 +0200 Subject: [PATCH 6/6] remove --verbose. always print test fail details --- testing/mod.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/testing/mod.ts b/testing/mod.ts index 4dabf5e88e51..fb9b661d0517 100644 --- a/testing/mod.ts +++ b/testing/mod.ts @@ -171,9 +171,7 @@ function printFailedSummary(results: TestResults): void { (v): void => { if (!v.ok) { console.error(`${RED_BG_FAIL} ${red(v.name)}`); - if (Deno.args.includes("--verbose")) { - console.error(v.error); - } + console.error(v.error); } } );