Refactor test output to count commands not files

This commit is contained in:
Chris Wanstrath 2026-03-09 21:59:10 -07:00
parent 2aaf74e581
commit 180d2379f5
2 changed files with 24 additions and 16 deletions

View File

@ -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")

View File

@ -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`