feat(core): Implement Protocol V2 with enhanced settings and lifecycle hooks

This commit is contained in:
2025-05-26 04:02:32 +00:00
parent 91880f8d42
commit 33d2ff1d4f
24 changed files with 2356 additions and 441 deletions

View File

@@ -125,4 +125,94 @@ The protocol v2 implementation is contained in a separate `ts_tapbundle_protocol
This architectural decision ensures the protocol can be used in any JavaScript environment without modification and maintains proper build dependencies.
See `readme.protocol.md` for the full specification and `ts_tapbundle_protocol/` for the implementation.
See `readme.protocol.md` for the full specification and `ts_tapbundle_protocol/` for the implementation.
## Protocol V2 Implementation Status
The Protocol V2 has been implemented to fix issues with TAP protocol parsing when test descriptions contain special characters like `#`, `###SNAPSHOT###`, or protocol markers like `⟦TSTEST:ERROR⟧`.
### Implementation Details:
1. **Protocol Components**:
- `ProtocolEmitter` - Generates protocol v2 messages (used by tapbundle)
- `ProtocolParser` - Parses protocol v2 messages (used by tstest)
- Uses Unicode markers `⟦TSTEST:` and `` to avoid conflicts with test content
2. **Current Status**:
- ✅ Basic protocol emission and parsing works
- ✅ Handles test descriptions with special characters correctly
- ✅ Supports metadata for timing, tags, errors
- ⚠️ Protocol messages sometimes appear in console output (parsing not catching all cases)
3. **Key Findings**:
- `tap.skip.test()` doesn't create actual test objects, just logs and increments counter
- `tap.todo()` method is not implemented (no `addTodo` method in Tap class)
- Protocol parser's `isBlockStart` was fixed to only match exact block markers, not partial matches in test descriptions
4. **Import Paths**:
- tstest imports from: `import { ProtocolParser } from '../dist_ts_tapbundle_protocol/index.js';`
- tapbundle imports from: `import { ProtocolEmitter } from '../dist_ts_tapbundle_protocol/index.js';`
## Test Configuration System (Phase 2)
The Test Configuration System has been implemented to provide global settings and lifecycle hooks for tests.
### Key Features:
1. **00init.ts Discovery**:
- Automatically detects `00init.ts` files in the same directory as test files
- Creates a temporary loader file that imports both `00init.ts` and the test file
- Loader files are cleaned up automatically after test execution
2. **Settings Inheritance**:
- Global settings from `00init.ts` → File-level settings → Test-level settings
- Settings include: timeout, retries, retryDelay, bail, concurrency
- Lifecycle hooks: beforeAll, afterAll, beforeEach, afterEach
3. **Implementation Details**:
- `SettingsManager` class handles settings inheritance and merging
- `tap.settings()` API allows configuration at any level
- Lifecycle hooks are integrated into test execution flow
### Important Development Notes:
1. **Local Development**: When developing tstest itself, use `node cli.js` instead of globally installed `tstest` to test changes
2. **Console Output Buffering**: Console output from tests is buffered and only displayed for failing tests. TAP-compliant comments (lines starting with `#`) are always shown.
3. **TypeScript Warnings**: Fixed async/await warnings in `movePreviousLogFiles()` by using sync versions of file operations
## Enhanced Communication Features (Phase 3)
The Enhanced Communication system has been implemented to provide rich, real-time feedback during test execution.
### Key Features:
1. **Event-Based Test Lifecycle Reporting**:
- `test:queued` - Test is ready to run
- `test:started` - Test execution begins
- `test:completed` - Test finishes (with pass/fail status)
- `suite:started` - Test suite/describe block begins
- `suite:completed` - Test suite/describe block ends
- `hook:started` - Lifecycle hook (beforeEach/afterEach) begins
- `hook:completed` - Lifecycle hook finishes
- `assertion:failed` - Assertion failure with detailed information
2. **Visual Diff Output for Assertion Failures**:
- **String Diffs**: Character-by-character comparison with colored output
- **Object/Array Diffs**: Deep property comparison showing added/removed/changed properties
- **Primitive Diffs**: Clear display of expected vs actual values
- **Colorized Output**: Green for expected, red for actual, yellow for differences
- **Smart Formatting**: Multi-line strings and complex objects are formatted for readability
3. **Real-Time Test Progress API**:
- Tests emit progress events as they execute
- tstest parser processes events and updates display in real-time
- Structured event format carries rich metadata (timing, errors, diffs)
- Seamless integration with existing TAP protocol via Protocol V2
### Implementation Details:
- Events are transmitted via Protocol V2's `EVENT` block type
- Event data is JSON-encoded within protocol markers
- Parser handles events asynchronously for real-time updates
- Visual diffs are generated using custom diff algorithms for each data type