feat(logging): Improve logging output, CLI option parsing, and test report formatting.

This commit is contained in:
2025-05-15 16:39:46 +00:00
parent 3fc4cee2b1
commit 78ffad2f7d
9 changed files with 644 additions and 168 deletions

View File

@@ -1,4 +1,5 @@
import { TsTest } from './tstest.classes.tstest.js';
import type { LogOptions } from './tstest.logging.js';
export enum TestExecutionMode {
DIRECTORY = 'directory',
@@ -7,12 +8,54 @@ export enum TestExecutionMode {
}
export const runCli = async () => {
if (!process.argv[2]) {
// Parse command line arguments
const args = process.argv.slice(2);
const logOptions: LogOptions = {};
let testPath: string | null = null;
// Parse options
for (let i = 0; i < args.length; i++) {
const arg = args[i];
switch (arg) {
case '--quiet':
case '-q':
logOptions.quiet = true;
break;
case '--verbose':
case '-v':
logOptions.verbose = true;
break;
case '--no-color':
logOptions.noColor = true;
break;
case '--json':
logOptions.json = true;
break;
case '--log-file':
if (i + 1 < args.length) {
logOptions.logFile = args[++i];
}
break;
default:
if (!arg.startsWith('-')) {
testPath = arg;
}
}
}
if (!testPath) {
console.error('You must specify a test directory/file/pattern as argument. Please try again.');
console.error('\nUsage: tstest <path> [options]');
console.error('\nOptions:');
console.error(' --quiet, -q Minimal output');
console.error(' --verbose, -v Verbose output');
console.error(' --no-color Disable colored output');
console.error(' --json Output results as JSON');
console.error(' --log-file Write logs to file');
process.exit(1);
}
const testPath = process.argv[2];
let executionMode: TestExecutionMode;
// Detect execution mode based on the argument
@@ -24,6 +67,6 @@ export const runCli = async () => {
executionMode = TestExecutionMode.DIRECTORY;
}
const tsTestInstance = new TsTest(process.cwd(), testPath, executionMode);
const tsTestInstance = new TsTest(process.cwd(), testPath, executionMode, logOptions);
await tsTestInstance.run();
};