Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print out the failed tests after the summary #554

Merged
merged 6 commits into from
Aug 22, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions testing/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ` +
Expand Down Expand Up @@ -254,7 +255,8 @@ async function runTestsSerial(
tests: TestDefinition[],
exitOnFail: boolean,
disableLog: boolean
): Promise<void> {
): Promise<string[]> {
const failed = [];
for (const { fn, name } of tests) {
// Displaying the currently running test if silent mode
if (disableLog) {
Expand All @@ -280,11 +282,13 @@ 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. */
Expand Down Expand Up @@ -320,6 +324,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;
}
Expand All @@ -329,7 +334,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) {
Expand All @@ -341,6 +346,11 @@ 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)}`);
}
);
Deno.exit(1);
}, 0);
}
Expand Down