feat(tapbundle): Add global postTask (teardown) and suite lifecycle hooks (beforeAll/afterAll) to tapbundle
This commit is contained in:
125
readme.hints.md
125
readme.hints.md
@@ -244,6 +244,131 @@ tstest test/specific.ts -w
|
||||
- Ignores changes matching the ignore patterns
|
||||
- Shows "Waiting for file changes..." between runs
|
||||
|
||||
## Phase 1 API Improvements (v3.1.0)
|
||||
|
||||
### New Features Implemented
|
||||
|
||||
#### 1. tap.postTask() - Global Teardown (COMPLETED)
|
||||
|
||||
Added symmetric teardown method to complement `tap.preTask()`:
|
||||
|
||||
**Implementation:**
|
||||
- Created `PostTask` class in `ts_tapbundle/tapbundle.classes.posttask.ts`
|
||||
- Mirrors PreTask structure with description and function
|
||||
- Integrated into Tap class execution flow
|
||||
- Runs after all tests complete but before global `afterAll` hook
|
||||
|
||||
**Usage:**
|
||||
```typescript
|
||||
tap.postTask('cleanup database', async () => {
|
||||
await cleanupDatabase();
|
||||
});
|
||||
```
|
||||
|
||||
**Execution Order:**
|
||||
1. preTask hooks
|
||||
2. Global beforeAll
|
||||
3. Tests (with suite hooks)
|
||||
4. **postTask hooks** ← NEW
|
||||
5. Global afterAll
|
||||
|
||||
#### 2. Suite-Level beforeAll/afterAll (COMPLETED)
|
||||
|
||||
Added once-per-suite lifecycle hooks:
|
||||
|
||||
**Implementation:**
|
||||
- Extended `ITestSuite` interface with `beforeAll` and `afterAll` properties
|
||||
- Added `tap.beforeAll()` and `tap.afterAll()` methods
|
||||
- Integrated into `_runSuite()` execution flow
|
||||
- Properly handles nested suites
|
||||
|
||||
**Usage:**
|
||||
```typescript
|
||||
tap.describe('Database Tests', () => {
|
||||
tap.beforeAll(async () => {
|
||||
await initializeDatabaseConnection(); // Runs once
|
||||
});
|
||||
|
||||
tap.test('test 1', async () => {});
|
||||
tap.test('test 2', async () => {});
|
||||
|
||||
tap.afterAll(async () => {
|
||||
await closeDatabaseConnection(); // Runs once
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
**Execution Order per Suite:**
|
||||
1. Suite beforeAll ← NEW
|
||||
2. Suite beforeEach
|
||||
3. Test
|
||||
4. Suite afterEach
|
||||
5. (Repeat 2-4 for each test)
|
||||
6. Child suites (recursive)
|
||||
7. Suite afterAll ← NEW
|
||||
|
||||
#### 3. tap.parallel() Fluent Entry Point (COMPLETED)
|
||||
|
||||
Added fluent API for parallel test creation:
|
||||
|
||||
**Implementation:**
|
||||
- Updated `TestBuilder` class with `_parallel` flag
|
||||
- Builder constructor accepts optional parallel parameter
|
||||
- Added `tap.parallel()` method returning configured builder
|
||||
- Fixed `testParallel()` to return TapTest<T> (was void)
|
||||
|
||||
**Usage:**
|
||||
```typescript
|
||||
// Simple parallel test
|
||||
tap.parallel().test('fetch data', async () => {});
|
||||
|
||||
// With full configuration
|
||||
tap
|
||||
.parallel()
|
||||
.tags('api', 'integration')
|
||||
.retry(2)
|
||||
.timeout(5000)
|
||||
.test('configured parallel test', async () => {});
|
||||
```
|
||||
|
||||
**Benefits:**
|
||||
- Consistent with other fluent builders (tags, priority, etc.)
|
||||
- More discoverable than separate `testParallel()` method
|
||||
- Allows chaining parallel with other configurations
|
||||
- `testParallel()` kept for backward compatibility
|
||||
|
||||
### Documentation Updates
|
||||
|
||||
**tapbundle/readme.md:**
|
||||
- Added suite-level beforeAll/afterAll documentation
|
||||
- Documented postTask with execution order notes
|
||||
- Added parallel() fluent API examples
|
||||
- Expanded TapTools documentation with all methods
|
||||
- Added "Additional Tap Methods" section for fail(), getSettings(), etc.
|
||||
- Documented all previously undocumented methods
|
||||
|
||||
### Tests
|
||||
|
||||
**test/tapbundle/test.new-lifecycle.ts:**
|
||||
- Tests postTask execution order
|
||||
- Verifies suite-level beforeAll/afterAll
|
||||
- Tests nested suite lifecycle
|
||||
- Validates parallel() fluent API
|
||||
- Confirms all execution order requirements
|
||||
|
||||
**Test Results:** All 9 tests passing ✅
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
None - all changes are additive and backward compatible.
|
||||
|
||||
### Migration Guide
|
||||
|
||||
No migration needed. New features are opt-in:
|
||||
- Continue using existing patterns
|
||||
- Adopt new features incrementally
|
||||
- `testParallel()` still works (recommended: switch to `parallel().test()`)
|
||||
|
||||
## Fixed Issues
|
||||
|
||||
### tap.skip.test(), tap.todo(), and tap.only.test() (Fixed)
|
||||
|
||||
Reference in New Issue
Block a user