Skip to content

Phase 2: Complete Migration of Existing Tape Tests to Vitest #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 14, 2025
Merged
4 changes: 3 additions & 1 deletion .claude/settings.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"Bash(npm install)",
"Bash(git pull:*)",
"Bash(npm run test:autobahn:*)",
"Bash(gh api:*)"
"Bash(gh api:*)",
"Bash(pnpm test:vitest:*)",
"Bash(rm:*)"
],
"deny": []
}
Expand Down
3 changes: 3 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
"mounts": [
"source=claude-code-bashhistory,target=/commandhistory,type=volume",
"source=claude-code-config,target=/home/node/.claude,type=volume",
"source=dotconfig,target=/home/node/.config,type=volume",
"source=pnpm-home,target=/pnpm,type=volume",
"source=node-modules,target=/workspace/node_modules,type=volume",
"source=${localEnv:HOME}/.gitconfig,target=/tmp/host-gitconfig,type=bind,consistency=cached",
"source=${localEnv:HOME}/.config/gh,target=/tmp/host-gh-config,type=bind,consistency=cached",
"source=${localEnv:HOME}/.ssh,target=/tmp/host-ssh,type=bind,consistency=cached,readonly"
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ builderror.log
npm-debug.log
test/autobahn/reports*/*
test/scripts/heapdump/*
/coverage
test-results.json
/coverage
87 changes: 48 additions & 39 deletions TEST_SUITE_MODERNIZATION_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ This section outlines the discrete phases, tasks, and subtasks for implementing
- [ ] **1.3.3** Test CI/CD integration with basic test
- [ ] **1.3.4** Validate test discovery and execution

### Phase 2: Test Migration and Helper Infrastructure
### Phase 2: Test Migration and Helper Infrastructure ⚠️ IN PROGRESS

**Objective**: Migrate existing tests and create foundational testing utilities.

Expand All @@ -627,49 +627,58 @@ This section outlines the discrete phases, tasks, and subtasks for implementing
**Dependencies**: Phase 1 complete (Vitest infrastructure operational)
**Tasks**:

- [ ] **2.1.1** Migrate `websocketFrame.js` tests
- [ ] Convert tape syntax to Vitest syntax
- [ ] Update imports and assertions
- [ ] Verify test functionality matches original
- [ ] **2.1.2** Migrate `request.js` tests
- [ ] Handle server setup/teardown in Vitest context
- [ ] Convert async test patterns
- [ ] **2.1.3** Migrate `w3cwebsocket.js` tests
- [ ] **2.1.4** Migrate `regressions.js` tests
- [ ] **2.1.5** Migrate `dropBeforeAccept.js` tests
- [ ] **2.1.6** Validate all migrated tests pass consistently
- [x] **2.1.1** Migrate `websocketFrame.js` tests
- [x] Convert tape syntax to Vitest syntax
- [x] Update imports and assertions
- [x] Verify test functionality matches original
- [x] **2.1.2** Migrate `request.js` tests
- [x] Handle server setup/teardown in Vitest context
- [x] Convert async test patterns
- [x] **2.1.3** Migrate `w3cwebsocket.js` tests
- [x] **2.1.4** Migrate `regressions.js` tests
- [x] **2.1.5** Migrate `dropBeforeAccept.js` tests
- [x] **2.1.6** Validate all migrated tests pass consistently

#### 2.2 Test Helper Infrastructure
#### 2.2 Test Helper Infrastructure ✅ **COMPLETED**

**Dependencies**: 2.1.1-2.1.5 (Need examples of test patterns before building helpers)
**Tasks**:

- [ ] **2.2.1** Create enhanced test server helpers
- [ ] Refactor `test/shared/test-server.js` for Vitest
- [ ] Add server lifecycle management utilities
- [ ] Create configurable test server options
- [ ] **2.2.2** Build mock infrastructure
- [ ] Create `MockWebSocketServer` class
- [ ] Create `MockWebSocketClient` class
- [ ] Create `MockHTTPServer` class
- [ ] **2.2.3** Develop test data generators
- [ ] Frame generation utilities
- [ ] Payload generation utilities
- [ ] Malformed data generators for edge case testing
- [ ] **2.2.4** Create custom assertion library
- [ ] WebSocket frame validation assertions
- [ ] Connection state validation assertions
- [ ] Protocol compliance assertions

#### 2.3 Parallel Test Execution Setup

**Dependencies**: 2.1 (Migrated tests must be stable), 2.2 (Helpers needed for stability)
**Tasks**:

- [ ] **2.3.1** Configure Vitest for parallel execution
- [ ] **2.3.2** Identify and resolve test isolation issues
- [ ] **2.3.3** Optimize test server management for parallel execution
- [ ] **2.3.4** Validate test reliability with parallel execution
- [x] **2.2.1** Create enhanced test server helpers
- [x] Enhanced `test/helpers/test-server.mjs` with `TestServerManager` class
- [x] Server lifecycle management utilities
- [x] Configurable test server options (echo, broadcast, protocol testing)
- [x] Legacy API compatibility maintained
- [x] **2.2.2** Build mock infrastructure
- [x] `MockWebSocketServer` class in `test/helpers/mocks.mjs`
- [x] `MockWebSocketClient` class with connection simulation
- [x] `MockWebSocketConnection` class for connection testing
- [x] `MockHTTPServer` and `MockSocket` classes for low-level testing
- [x] **2.2.3** Develop test data generators
- [x] `generateWebSocketFrame()` for various frame types in `test/helpers/generators.mjs`
- [x] `generateRandomPayload()` with text, binary, JSON support
- [x] `generateMalformedFrame()` for edge case testing
- [x] `generateProtocolViolation()` for protocol compliance testing
- [x] Performance test payload generators
- [x] **2.2.4** Create custom assertion library
- [x] `expectValidWebSocketFrame()` frame validation in `test/helpers/assertions.mjs`
- [x] `expectConnectionState()` connection state validation
- [x] `expectProtocolCompliance()` RFC 6455 compliance checking
- [x] `expectHandshakeHeaders()` header validation
- [x] Performance and memory leak assertions

#### 2.3 Parallel Test Execution Setup ⚠️ **DEFERRED**

**Status**: Deferred to future phases for simplicity and stability

**Decision**: Parallel test execution adds complexity with WebSocket server port management and test isolation. For the current modernization phase, single-threaded test execution provides sufficient performance while ensuring test reliability and easier debugging.

**Future Considerations**:

- Port allocation management
- Test isolation improvements
- Network resource conflict resolution
- Performance optimization needs assessment

### Phase 3: Core Component Test Expansion

Expand Down
4 changes: 4 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
onlyBuiltDependencies:
- bufferutil
- esbuild
- utf-8-validate
Loading