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

@@ -445,4 +445,49 @@ The protocol parser was fixed to correctly handle inline timing metadata:
- Changed condition from `!simpleMatch[1].includes(':')` to check for simple key:value pairs
- Excludes prefixed formats (META:, SKIP:, TODO:, EVENT:) while parsing simple formats like `time:250`
This ensures timing metadata is correctly extracted and displayed in test results.
This ensures timing metadata is correctly extracted and displayed in test results.
## Streaming Console Output (Fixed)
### Problem
When tests use `process.stdout.write()` for streaming output (without newlines), each write was appearing on a separate line. This happened because:
1. Child process stdout data events arrive as separate chunks
2. `TapParser._processLog()` split on `\n` and processed each segment
3. `testConsoleOutput()` used `console.log()` which added a newline to each call
### Solution
The streaming behavior is now preserved by:
1. **Line buffering for TAP parsing**: Only buffer content that looks like TAP protocol messages
2. **True streaming for console output**: Use `process.stdout.write()` instead of `console.log()` for partial lines
3. **Intelligent detection**: `_looksLikeTapStart()` checks if content could be a TAP protocol message
### Implementation Details
**TapParser changes:**
- Added `lineBuffer` property to buffer incomplete TAP protocol lines
- Rewrote `_processLog()` to handle streaming correctly:
- Complete lines (with newline) are processed through protocol parser
- Incomplete lines that look like TAP are buffered
- Incomplete lines that don't look like TAP are streamed immediately
- Added `_looksLikeTapStart()` helper to detect TAP protocol patterns
- Added `_handleConsoleOutput()` to handle console output with proper streaming
- Buffer is flushed on process exit
**TsTestLogger changes:**
- Added `testConsoleOutputStreaming()` method that uses `process.stdout.write()` in verbose mode
- Added `logToTestFileRaw()` for writing to log files without adding newlines
- In non-verbose mode, streaming content is appended to the last buffered entry
**TapTestResult changes:**
- Added `addLogLineRaw()` method that doesn't append newlines
### Usage
Tests can now use streaming output naturally:
```typescript
process.stdout.write("Loading");
process.stdout.write(".");
process.stdout.write(".");
process.stdout.write(".\n");
```
This will correctly display as `Loading...` on a single line in verbose mode.