Fixing 42 Tests: Durable Objects & CORS First!
We've got a bit of a testing situation on our hands – 42 failing tests, to be exact. But don't worry, we have a plan! Our top priority is ensuring production stability, so we're tackling the Durable Object and CORS failures first. This guide will walk you through the process, step by step, to get everything back on track.
Context
Right now, our test suite isn't looking its best, with 42 tests currently failing. To ensure smooth operations and a stable environment, we're prioritizing the fixes in a specific order:
- Phase 1a: Address Durable Object and CORS failures (critical for production stability).
- Phase 1b: Resolve the remaining test suite failures.
This strategy aligns with Phase 1.3 of our Architecture Alignment & Stability plan, ensuring we focus on the most critical areas first.
Failure Categories
Here's a breakdown of the failing tests, categorized by priority:
High Priority - Production Stability
These failures pose the most significant risk to our live environment and require immediate attention.
Durable Object Test Failures
- [ ]
tests/durable-objects/job-state-manager.test.js- Mock WebSocket issues - [ ]
tests/durable-objects/websocket-connection.test.js- Lifecycle failures - Related: Issue #113 (Add error handling coverage for WebSocket RPC methods)
Impact: If these tests fail, WebSocket progress updates might fail silently in production, leading to a poor user experience and potential data loss.
CORS Test Failures
- [ ]
tests/middleware/cors.test.js- Preflight request handling - Handler tests with CORS headers verification
Impact: CORS (Cross-Origin Resource Sharing) errors can block iOS and Flutter clients, preventing them from accessing our resources. This can lead to complete app failure for those users.
Medium Priority - Test Infrastructure
These failures relate to our testing environment itself and need to be addressed to ensure reliable and accurate testing.
Mock/Fixture Issues
- [ ] Issue #102: Broken test mocking -
vi.doMock()without module re-import - [ ] WebSocket mock payload validation (Issue #115)
- [ ] Test fixture updates for v2 response format
Lower Priority - Cleanup
These are less critical issues that can be addressed after the higher priority items are resolved.
- [ ] Type assertion failures from v2 migration
- [ ] Deprecated API usage warnings
- [ ] Coverage gaps in new modules
Systematic Approach
To ensure we tackle these failures effectively, we'll follow a systematic approach, breaking the work into two phases.
Phase 1a: Critical Failures (Target: 2-4 hours)
Our primary focus is on the Durable Object and CORS tests. Let’s get these sorted out first!
# Run Durable Object tests only
npm test -- tests/durable-objects/
# Run CORS tests only
npm test -- tests/middleware/cors.test.js
# Fix failures incrementally, commit after each fix
Success Criteria:
- All Durable Object tests pass (WebSocket lifecycle, state management).
- All CORS tests pass (preflight, origin validation).
- No production-blocking failures remain.
Phase 1b: Remaining Failures (Target: 4-8 hours)
Once the critical failures are resolved, we'll move on to the rest of the test suite.
# Run full test suite
npm test
# Categorize remaining failures:
# - Mock issues (fix mocks, not implementation)
# - Type errors (update type assertions)
# - Contract changes (update test expectations)
Success Criteria:
- All 42 tests pass.
- Test coverage remains ≥75%.
- No skipped/disabled tests.
Acceptance Criteria
To ensure we've successfully addressed all the issues, we'll use the following acceptance criteria:
- [ ] Phase 1a Complete: Zero Durable Object or CORS test failures.
- [ ] Phase 1b Complete: Zero test failures across the entire suite.
- [ ] Test coverage report shows ≥75% overall coverage.
- [ ] CI/CD pipeline passes on the main branch.
- [ ] Documentation updated with new test patterns (if applicable).
Testing Commands
Here are some helpful commands for running tests and analyzing results:
# Run all tests with verbose output
npm test -- --reporter=verbose
# Run specific test file
npm test -- tests/durable-objects/job-state-manager.test.js
# Generate coverage report
npm run test:coverage
# Watch mode for iterative fixing
npm run test:watch
# Run only failed tests (after first run)
npm test -- --reporter=verbose --only
Common Failure Patterns & Fixes
Here are some common failure patterns we've observed and their corresponding fixes. Hopefully, it will save you some time.
Pattern 1: WebSocket Mock Issues
Symptom: TypeError: mockWebSocket.send is not a function
Fix:
// Add missing mock methods
const mockWebSocket = {
accept: vi.fn(),
send: vi.fn(),
close: vi.fn(),
addEventListener: vi.fn()
}
Pattern 2: V2 Response Format Mismatches
Symptom: Expected { data, metadata } but got { success, data }
Fix:
// Update test expectations to v2 format
expect(response.body).toEqual({
data: expect.any(Object),
metadata: expect.any(Object),
error: null
})
Pattern 3: CORS Preflight Failures
Symptom: OPTIONS request returns 404
Fix:
// Ensure OPTIONS handler is registered before route handlers
if (request.method === 'OPTIONS') {
return handleCorsPreflightRequest(request)
}
Dependencies
- Blocks: Production deployment, confidence in v2 migration
- Relates to: Issues #102, #113, #115 (test infrastructure fixes)
- Prerequisite: All handlers must use v2 response format (Issue #117)
Progress Tracking
Use this checklist to track your progress as you fix test files. This will help us stay organized and ensure everything is covered.
Durable Objects
- [ ]
job-state-manager.test.js(0 failures) - [ ]
websocket-connection.test.js(0 failures)
Middleware
- [ ]
cors.test.js(0 failures) - [ ]
rate-limiting.test.js(0 failures)
Handlers
- [ ]
search-title.test.js(0 failures) - [ ]
search-isbn.test.js(0 failures) - [ ]
search-advanced.test.js(0 failures) - [ ]
batch-enrichment.test.js(0 failures)
Integration
- [ ]
api-integration.test.js(0 failures) - [ ]
websocket-integration.test.js(0 failures)
References
- Test status report (42 failures documented)
tests/directory structure.github/CONTRIBUTING.md- Testing requirements- Vitest documentation: https://vitest.dev