Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | 1x 1x 7x 7x 7x 8x 7x 8x 8x 8x 10x 8x 10x 10x 10x 10x 3x 1x 2x 2x 3x 1x 1x 7x 1x 8x 8x 8x 8x 7x 7x 7x 7x 7x 7x 4x 3x | import * as chalk from "chalk";
import { TestRunResult, TestResult } from "./types";
/**
* Console reporter for test results
*/
export class ConsoleReporter {
private verbose: boolean;
constructor(verbose = false) {
this.verbose = verbose;
}
/**
* Print results for all test runs
*/
printResults(results: TestRunResult[]): void {
console.log(""); // Empty line
for (const result of results) {
this.printSuiteResult(result);
}
this.printSummary(results);
}
/**
* Print results for a single test suite
*/
private printSuiteResult(result: TestRunResult): void {
const suiteStatus = result.failed === 0 ? chalk.green("✓") : chalk.red("✗");
console.log(`${suiteStatus} ${chalk.bold(result.suiteName)}`);
for (const testResult of result.results) {
this.printTestResult(testResult);
}
console.log(""); // Empty line
}
/**
* Print result for a single test
*/
private printTestResult(result: TestResult): void {
const status = result.passed ? chalk.green(" ✓") : chalk.red(" ✗");
const duration = chalk.gray(`(${result.duration}ms)`);
console.log(`${status} ${result.testName} ${duration}`);
if (!result.passed) {
if (result.error) {
console.log(chalk.red(` Error: ${result.error}`));
} else if (result.evaluationReasoning) {
console.log(chalk.yellow(` Reason: ${result.evaluationReasoning}`));
}
if (this.verbose) {
const responseStr =
typeof result.actualResponse === "string"
? result.actualResponse
: JSON.stringify(result.actualResponse, null, 2);
console.log(chalk.gray(` Response: ${responseStr}`));
}
} else if (this.verbose && result.evaluationReasoning) {
console.log(chalk.gray(` ✓ ${result.evaluationReasoning}`));
}
}
/**
* Print overall summary
*/
private printSummary(results: TestRunResult[]): void {
const totalTests = results.reduce((sum, r) => sum + r.totalTests, 0);
const totalPassed = results.reduce((sum, r) => sum + r.passed, 0);
const totalFailed = results.reduce((sum, r) => sum + r.failed, 0);
const totalDuration = results.reduce((sum, r) => sum + r.duration, 0);
console.log(chalk.bold("Summary:"));
console.log(` Suites: ${results.length}`);
console.log(
` Tests: ${chalk.green(`${totalPassed} passed`)}, ${
totalFailed > 0
? chalk.red(`${totalFailed} failed`)
: `${totalFailed} failed`
}, ${totalTests} total`
);
console.log(` Time: ${(totalDuration / 1000).toFixed(2)}s`);
console.log("");
if (totalFailed === 0) {
console.log(chalk.green.bold("✓ All tests passed!"));
} else {
console.log(
chalk.red.bold(
`✗ ${totalFailed} test${totalFailed === 1 ? "" : "s"} failed`
)
);
}
}
}
|