fix(tstest): preserve streaming console output and correctly buffer incomplete TAP lines

This commit is contained in:
2026-01-19 19:14:05 +00:00
parent ae59b7adf2
commit 46f0a5a8cf
8 changed files with 202 additions and 109 deletions

View File

@@ -348,10 +348,10 @@ export class TsTestLogger {
}
}
// Console output from test files (non-TAP output)
// Console output from test files (non-TAP output) - complete lines
testConsoleOutput(message: string) {
if (this.options.json) return;
// In verbose mode, show console output immediately
if (this.options.verbose) {
this.log(this.format(` ${message}`, 'dim'));
@@ -359,12 +359,48 @@ export class TsTestLogger {
// In non-verbose mode, buffer the logs
this.currentTestLogs.push(message);
}
// Always log to test file if --logfile is specified
if (this.currentTestLogFile) {
this.logToTestFile(` ${message}`);
}
}
// Streaming console output (preserves original formatting, no newline added)
testConsoleOutputStreaming(message: string) {
if (this.options.json) return;
const prefix = ' ';
if (this.options.verbose) {
// Use process.stdout.write to preserve streaming without adding newlines
process.stdout.write(this.format(prefix + message, 'dim'));
} else {
// Buffer without trailing newline - append to last entry if exists and incomplete
if (this.currentTestLogs.length > 0) {
// Append to the last buffered entry (for streaming segments)
this.currentTestLogs[this.currentTestLogs.length - 1] += message;
} else {
this.currentTestLogs.push(message);
}
}
// Log to test file without adding newline
if (this.currentTestLogFile) {
this.logToTestFileRaw(prefix + message);
}
}
private logToTestFileRaw(message: string) {
try {
// Remove ANSI color codes for file logging
const cleanMessage = message.replace(/\u001b\[[0-9;]*m/g, '');
// Append to test log file without adding newline
fs.appendFileSync(this.currentTestLogFile, cleanMessage);
} catch (error) {
// Silently fail to avoid disrupting the test run
}
}
// Skipped test file
testFileSkipped(filename: string, index: number, total: number, reason: string) {