feat(logging): Improve logging output, CLI option parsing, and test report formatting.
This commit is contained in:
230
readme.plan.md
230
readme.plan.md
@ -1,51 +1,199 @@
|
||||
# Plan for adding single file and glob pattern execution support to tstest
|
||||
# Plan for improving logging and output in tstest
|
||||
|
||||
!! FIRST: Reread /home/philkunz/.claude/CLAUDE.md to ensure following all guidelines !!
|
||||
|
||||
## Goal - ✅ COMPLETED
|
||||
- ✅ Make `tstest test/test.abc.ts` run the specified file directly
|
||||
- ✅ Support glob patterns like `tstest test/*.spec.ts` or `tstest test/**/*.test.ts`
|
||||
- ✅ Maintain backward compatibility with directory argument
|
||||
## Goal - ✅ MOSTLY COMPLETED
|
||||
- ✅ Make test output cleaner and more visually appealing
|
||||
- ✅ Add structured logging capabilities
|
||||
- ✅ Support different verbosity levels
|
||||
- ✅ Improve CI/CD compatibility
|
||||
- ✅ Add progress indicators and timing summaries
|
||||
|
||||
## Current behavior - UPDATED
|
||||
- ✅ tstest now supports three modes: directory, single file, and glob patterns
|
||||
- ✅ Directory mode now searches recursively using `**/test*.ts` pattern
|
||||
- ✅ Single file mode runs a specific test file
|
||||
- ✅ Glob mode runs files matching the pattern
|
||||
## Current State - UPDATED
|
||||
- ✅ Clean, modern visual design with Unicode characters
|
||||
- ✅ Structured output format (JSON support)
|
||||
- ✅ Multiple verbosity levels (quiet, normal, verbose)
|
||||
- ✅ Real-time output with cleaner formatting
|
||||
- ✅ Better error aggregation and display
|
||||
- ✅ TAP protocol support integrated with new logger
|
||||
|
||||
## Completed changes
|
||||
## Completed Improvements
|
||||
|
||||
### 1. ✅ Update cli argument handling in index.ts
|
||||
- ✅ Detect argument type: file path, glob pattern, or directory
|
||||
- ✅ Check if argument contains glob characters (*, **, ?, [], etc.)
|
||||
- ✅ Pass appropriate mode to TsTest constructor
|
||||
- ✅ Added TestExecutionMode enum
|
||||
### 1. ✅ Created new TsTestLogger class
|
||||
- ✅ Centralized logging with consistent formatting
|
||||
- ✅ Support for different output modes (normal, quiet, verbose)
|
||||
- ✅ Better visual hierarchy with modern Unicode characters
|
||||
- ✅ Progress indicators for multiple test files
|
||||
- ✅ Structured error collection and display
|
||||
|
||||
### 2. ✅ Modify TsTest constructor and class
|
||||
- ✅ Add support for three modes: directory, file, glob
|
||||
- ✅ Update constructor to accept pattern/path and mode
|
||||
- ✅ Added executionMode property to track the mode
|
||||
### 2. ✅ Updated visual design
|
||||
- ✅ Replaced heavy separators with cleaner alternatives
|
||||
- ✅ Used better emoji and Unicode characters
|
||||
- ✅ Added indentation for hierarchical display
|
||||
- ✅ Grouped related information visually
|
||||
- ✅ Added color coding consistently
|
||||
|
||||
### 3. ✅ Update TestDirectory class
|
||||
- ✅ Used `listFileTree` for glob pattern support
|
||||
- ✅ Used `SmartFile.fromFilePath` for single file loading
|
||||
- ✅ Refactored to support all three modes in `_init` method
|
||||
- ✅ Return appropriate file array based on mode
|
||||
- ✅ Changed default directory behavior to recursive search
|
||||
- ✅ When directory argument: use `**/test*.ts` pattern for recursive search
|
||||
- ✅ This ensures subdirectories are included in test discovery
|
||||
### 3. ✅ Added command-line options
|
||||
- ✅ `--quiet` for minimal CI-friendly output
|
||||
- ✅ `--verbose` for detailed debugging information
|
||||
- ✅ `--no-color` for environments without color support
|
||||
- ✅ `--json` for structured JSON output
|
||||
- ⏳ `--log-file <path>` for persistent logging (TODO)
|
||||
|
||||
### 4. ✅ Test the implementation
|
||||
- ✅ Created test file `test/test.single.ts` for single file functionality
|
||||
- ✅ Created test file `test/test.glob.ts` for glob pattern functionality
|
||||
- ✅ Created test in subdirectory `test/subdir/test.sub.ts` for recursive search
|
||||
- ✅ Tested with existing test files for backward compatibility
|
||||
- ✅ Tested glob patterns: `test/test.*.ts` works correctly
|
||||
- ✅ Verified that default behavior now includes subdirectories
|
||||
### 4. ✅ Improved progress feedback
|
||||
- ⏳ Show progress bar for multiple files (TODO)
|
||||
- ✅ Display current file being executed
|
||||
- ✅ Show real-time test counts
|
||||
- ⏳ Add ETA for long test suites (TODO)
|
||||
|
||||
## Implementation completed
|
||||
1. ✅ CLI argument type detection implemented
|
||||
2. ✅ TsTest class supports all three modes
|
||||
3. ✅ TestDirectory handles files, globs, and directories
|
||||
4. ✅ Default pattern changed from `test*.ts` to `**/test*.ts` for recursive search
|
||||
5. ✅ Comprehensive tests added and all modes verified
|
||||
### 5. ✅ Better error and summary display
|
||||
- ✅ Collect all errors and display at end
|
||||
- ✅ Show timing metrics and performance summary (in verbose mode)
|
||||
- ✅ Highlight slowest tests (in verbose mode)
|
||||
- ✅ Add test failure context
|
||||
|
||||
### 6. ✅ Browser console integration
|
||||
- ✅ Clearly separate browser logs from test output
|
||||
- ⏳ Add browser log filtering options (TODO)
|
||||
- ✅ Format browser errors specially
|
||||
|
||||
## Implementation Steps - COMPLETED
|
||||
|
||||
### Phase 1: ✅ Core Logger Implementation
|
||||
1. ✅ Created `tstest.logging.ts` with TsTestLogger class
|
||||
2. ✅ Added LogOptions interface for configuration
|
||||
3. ✅ Implemented basic formatting methods
|
||||
4. ✅ Added progress and summary methods
|
||||
|
||||
### Phase 2: ✅ Integration
|
||||
1. ✅ Updated CLI to accept new command-line options
|
||||
2. ✅ Modified TsTest class to use new logger
|
||||
3. ✅ Updated TapParser to use structured logging
|
||||
4. ✅ Updated TapCombinator for better summaries
|
||||
|
||||
### Phase 3: ✅ Visual Improvements
|
||||
1. ✅ Replaced all existing separators
|
||||
2. ✅ Updated color scheme
|
||||
3. ✅ Added emoji and Unicode characters
|
||||
4. ✅ Implemented hierarchical output
|
||||
|
||||
### Phase 4: ✅ Advanced Features
|
||||
1. ✅ Add JSON output format
|
||||
2. ⏳ Implement file-based logging (TODO)
|
||||
3. ✅ Add performance metrics collection
|
||||
4. ✅ Create error aggregation system
|
||||
|
||||
### Phase 5: ✅ Browser Integration
|
||||
1. ✅ Update browser console forwarding
|
||||
2. ✅ Add browser log formatting
|
||||
3. ✅ Implement browser-specific indicators
|
||||
|
||||
## Files modified
|
||||
- ✅ `ts/tstest.logging.ts` - New logger implementation (created)
|
||||
- ✅ `ts/index.ts` - Added CLI options parsing
|
||||
- ✅ `ts/tstest.classes.tstest.ts` - Integrated new logger
|
||||
- ✅ `ts/tstest.classes.tap.parser.ts` - Updated output formatting
|
||||
- ✅ `ts/tstest.classes.tap.combinator.ts` - Improved summary display
|
||||
- ❌ `ts/tstest.logprefixes.ts` - Still in use, can be deprecated later
|
||||
- ❌ `package.json` - No new dependencies needed
|
||||
|
||||
## Success Criteria - ACHIEVED
|
||||
- ✅ Cleaner, more readable test output
|
||||
- ✅ Configurable verbosity levels
|
||||
- ✅ Better CI/CD integration
|
||||
- ✅ Improved error visibility
|
||||
- ✅ Performance metrics available
|
||||
- ✅ Consistent visual design
|
||||
- ✅ Maintained backward compatibility
|
||||
|
||||
## Example Output Comparison
|
||||
|
||||
### Current Output
|
||||
```
|
||||
☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰☰
|
||||
**TSTEST** FOUND 4 TESTFILE(S):
|
||||
**TSTEST** test/test.ts
|
||||
------------------------------------------------
|
||||
=> Running test/test.ts in node.js runtime.
|
||||
= = = = = = = = = = = = = = = = = = = = = = = =
|
||||
```
|
||||
|
||||
### Actual Output (IMPLEMENTED)
|
||||
```
|
||||
🔍 Test Discovery
|
||||
Mode: directory
|
||||
Pattern: test
|
||||
Found: 4 test file(s)
|
||||
|
||||
▶️ test/test.ts (1/4)
|
||||
Runtime: node.js
|
||||
✅ prepare test (0ms)
|
||||
Summary: 1/1 PASSED
|
||||
|
||||
▶️ test/test.single.ts (2/4)
|
||||
Runtime: node.js
|
||||
✅ single file test execution (1ms)
|
||||
Summary: 1/1 PASSED
|
||||
|
||||
📊 Test Summary
|
||||
┌────────────────────────────────┐
|
||||
│ Total Files: 4 │
|
||||
│ Total Tests: 4 │
|
||||
│ Passed: 4 │
|
||||
│ Failed: 0 │
|
||||
│ Duration: 5739ms │
|
||||
└────────────────────────────────┘
|
||||
|
||||
ALL TESTS PASSED! 🎉
|
||||
```
|
||||
|
||||
### Additional Features Implemented
|
||||
|
||||
1. **Quiet Mode**:
|
||||
```
|
||||
Found 1 tests
|
||||
✅ single file test execution
|
||||
|
||||
Summary: 1/1 | 1210ms | PASSED
|
||||
```
|
||||
|
||||
2. **JSON Mode**:
|
||||
```json
|
||||
{"event":"discovery","count":1,"pattern":"test/test.single.ts","executionMode":"file"}
|
||||
{"event":"fileStart","filename":"test/test.single.ts","runtime":"node.js","index":1,"total":1}
|
||||
{"event":"testResult","testName":"single file test execution","passed":true,"duration":0}
|
||||
{"event":"summary","summary":{"totalFiles":1,"totalTests":1,"totalPassed":1,"totalFailed":0,"totalDuration":1223,"fileResults":[...]}}
|
||||
```
|
||||
|
||||
3. **Error Display**:
|
||||
```
|
||||
❌ Failed Tests:
|
||||
|
||||
test/test.fail.ts
|
||||
❌ This test should fail
|
||||
|
||||
SOME TESTS FAILED! ❌
|
||||
```
|
||||
|
||||
## Summary of Implementation
|
||||
|
||||
The logging improvement plan has been successfully implemented with the following achievements:
|
||||
|
||||
1. **Created a new centralized TsTestLogger class** that handles all output formatting
|
||||
2. **Added multiple output modes**: quiet, normal, verbose, and JSON
|
||||
3. **Improved visual design** with modern Unicode characters and emojis
|
||||
4. **Added CLI argument parsing** for all new options
|
||||
5. **Integrated the logger throughout the codebase** (TsTest, TapParser, TapCombinator)
|
||||
6. **Better error aggregation and display** with failed tests shown at the end
|
||||
7. **Performance metrics** available in verbose mode
|
||||
8. **Clean, hierarchical output** that's much more readable
|
||||
|
||||
### Remaining TODOs
|
||||
|
||||
Only a few minor features remain unimplemented:
|
||||
- File-based logging (--log-file option)
|
||||
- Progress bar visualization
|
||||
- ETA for long test suites
|
||||
- Browser log filtering options
|
||||
|
||||
The core logging improvements are complete and provide a much better user experience!
|
Reference in New Issue
Block a user