diff --git a/src/cli/index.ts b/src/cli/index.ts index c88a0fd..d2e7149 100755 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -125,25 +125,31 @@ $ true return testResult } + const printDots = (r: TestResult) => { + if (r.error) { + process.stdout.write(ansis.red("F")) + return + } + const passed = r.commandCount - r.failures.length + for (let i = 0; i < passed; i++) { + process.stdout.write(ansis.green(".")) + } + for (let i = 0; i < r.failures.length; i++) { + process.stdout.write(ansis.red("F")) + } + } + if (opts.parallel) { const all = await Promise.all(files.map(runOne)) for (const r of all) { - if (r.passed) { - process.stdout.write(ansis.green(".")) - } else { - process.stdout.write(ansis.red("F")) - } + printDots(r) results.push(r) } process.stdout.write("\n") } else { for (const filePath of files) { const r = await runOne(filePath) - if (r.passed) { - process.stdout.write(ansis.green(".")) - } else { - process.stdout.write(ansis.red("F")) - } + printDots(r) results.push(r) } process.stdout.write("\n") diff --git a/src/format.ts b/src/format.ts index 85bc871..352c7b2 100644 --- a/src/format.ts +++ b/src/format.ts @@ -7,6 +7,7 @@ import { diff, matchOutput } from "./match.ts" export type TestResult = { path: string passed: boolean + commandCount: number failures: FailedCommand[] error?: string } @@ -23,7 +24,7 @@ export function evaluateFile( error?: string, ): TestResult { if (error) { - return { path, passed: false, failures: [], error } + return { path, passed: false, commandCount: results.length, failures: [], error } } const failures: FailedCommand[] = [] @@ -53,7 +54,7 @@ export function evaluateFile( } } - return { path, passed: failures.length === 0, failures } + return { path, passed: failures.length === 0, commandCount: results.length, failures } } export function formatFailure(test: TestResult): string { @@ -104,12 +105,13 @@ export function formatSummary( results: TestResult[], elapsed: number, ): string { - const passed = results.filter(r => r.passed).length - const failed = results.filter(r => !r.passed).length + const totalCommands = results.reduce((n, r) => n + r.commandCount, 0) + const failedCommands = results.reduce((n, r) => n + r.failures.length, 0) + const passedCommands = totalCommands - failedCommands const parts: string[] = [] - if (passed > 0) parts.push(ansis.green(`${passed} passed`)) - if (failed > 0) parts.push(ansis.red(`${failed} failed`)) + if (passedCommands > 0) parts.push(ansis.green(`${passedCommands} passed`)) + if (failedCommands > 0) parts.push(ansis.red(`${failedCommands} failed`)) const time = elapsed < 1000 ? `${Math.round(elapsed)}ms`