Refactor test output to count commands not files
This commit is contained in:
parent
2aaf74e581
commit
180d2379f5
|
|
@ -125,25 +125,31 @@ $ true
|
||||||
return testResult
|
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) {
|
if (opts.parallel) {
|
||||||
const all = await Promise.all(files.map(runOne))
|
const all = await Promise.all(files.map(runOne))
|
||||||
for (const r of all) {
|
for (const r of all) {
|
||||||
if (r.passed) {
|
printDots(r)
|
||||||
process.stdout.write(ansis.green("."))
|
|
||||||
} else {
|
|
||||||
process.stdout.write(ansis.red("F"))
|
|
||||||
}
|
|
||||||
results.push(r)
|
results.push(r)
|
||||||
}
|
}
|
||||||
process.stdout.write("\n")
|
process.stdout.write("\n")
|
||||||
} else {
|
} else {
|
||||||
for (const filePath of files) {
|
for (const filePath of files) {
|
||||||
const r = await runOne(filePath)
|
const r = await runOne(filePath)
|
||||||
if (r.passed) {
|
printDots(r)
|
||||||
process.stdout.write(ansis.green("."))
|
|
||||||
} else {
|
|
||||||
process.stdout.write(ansis.red("F"))
|
|
||||||
}
|
|
||||||
results.push(r)
|
results.push(r)
|
||||||
}
|
}
|
||||||
process.stdout.write("\n")
|
process.stdout.write("\n")
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import { diff, matchOutput } from "./match.ts"
|
||||||
export type TestResult = {
|
export type TestResult = {
|
||||||
path: string
|
path: string
|
||||||
passed: boolean
|
passed: boolean
|
||||||
|
commandCount: number
|
||||||
failures: FailedCommand[]
|
failures: FailedCommand[]
|
||||||
error?: string
|
error?: string
|
||||||
}
|
}
|
||||||
|
|
@ -23,7 +24,7 @@ export function evaluateFile(
|
||||||
error?: string,
|
error?: string,
|
||||||
): TestResult {
|
): TestResult {
|
||||||
if (error) {
|
if (error) {
|
||||||
return { path, passed: false, failures: [], error }
|
return { path, passed: false, commandCount: results.length, failures: [], error }
|
||||||
}
|
}
|
||||||
|
|
||||||
const failures: FailedCommand[] = []
|
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 {
|
export function formatFailure(test: TestResult): string {
|
||||||
|
|
@ -104,12 +105,13 @@ export function formatSummary(
|
||||||
results: TestResult[],
|
results: TestResult[],
|
||||||
elapsed: number,
|
elapsed: number,
|
||||||
): string {
|
): string {
|
||||||
const passed = results.filter(r => r.passed).length
|
const totalCommands = results.reduce((n, r) => n + r.commandCount, 0)
|
||||||
const failed = results.filter(r => !r.passed).length
|
const failedCommands = results.reduce((n, r) => n + r.failures.length, 0)
|
||||||
|
const passedCommands = totalCommands - failedCommands
|
||||||
|
|
||||||
const parts: string[] = []
|
const parts: string[] = []
|
||||||
if (passed > 0) parts.push(ansis.green(`${passed} passed`))
|
if (passedCommands > 0) parts.push(ansis.green(`${passedCommands} passed`))
|
||||||
if (failed > 0) parts.push(ansis.red(`${failed} failed`))
|
if (failedCommands > 0) parts.push(ansis.red(`${failedCommands} failed`))
|
||||||
|
|
||||||
const time = elapsed < 1000
|
const time = elapsed < 1000
|
||||||
? `${Math.round(elapsed)}ms`
|
? `${Math.round(elapsed)}ms`
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user