Repository navigation
Description
Problem
Currently using Happy-DOM for all tests, which has limitations:
- ❌ Cannot simulate real focus/blur events
- ❌ Cannot test edit mode activation accurately
- ❌ Cannot test dropdown interactions (slash commands, @mentions)
- ❌ Cannot test cross-node navigation with real browser behavior
This led to deleting 9 integration tests (~4,200 lines) in #274 because they couldn't run properly in Happy-DOM.
Solution
Implement hybrid testing strategy with Vitest Browser Mode for integration tests:
Happy-DOM (fast unit tests)
└─ Controller logic, services, utilities (728+ tests, ~10s)
Vitest Browser Mode (real browser integration tests)
└─ Focus management, edit mode, user workflows (77 tests, ~750ms)
Implementation Status
✅ Phase 1: Infrastructure Setup + Focus Management (PR #395 - MERGED)
- Set up Vitest Browser Mode configuration
- Create browser test infrastructure
- Implement 6 focus management tests as proof-of-concept
- Document hybrid testing strategy
- File:
src/tests/browser/focus-management.test.ts - Status: ✅ Merged to main
🔄 Phases 2-5: Test Migrations (PR #404 - IN REVIEW)
All remaining phases delivered in PR #404:
-
Phase 2: Enter Key Operations (15 tests)
- File:
src/tests/browser/enter-key-focus.test.ts - Focus transitions, content splitting, cursor positioning
- File:
-
Phase 3: Backspace Operations (18 tests)
- File:
src/tests/browser/backspace-focus.test.ts - Focus transitions to previous node, merge point cursor positioning
- File:
-
Phase 4: Slash Command Integration (21 tests)
- File:
src/tests/browser/slash-dropdown-interaction.test.ts - Dropdown positioning, viewport edge detection, keyboard navigation
- File:
-
Phase 5: Autocomplete Flow (17 tests)
- File:
src/tests/browser/autocomplete-interaction.test.ts - @mention dropdown positioning, Selection API, reference insertion
- File:
Acceptance Criteria
Setup ✅ COMPLETE (PR #395)
- Install Vitest browser dependencies (
@vitest/browser,playwright) - Configure Vitest browser mode in
vitest.config.ts - Create separate config for browser tests (
vitest.browser.config.ts) - Add npm scripts:
test:browser,test:unit,test:all
Browser Tests
- Phase 1: Focus Management (6 tests) - ✅ Merged in PR Add Vitest Browser Mode Infrastructure (Phase 1) #395
- Phase 2: Enter Key Operations (15 tests) - 🔄 In PR Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests #404
- Phase 3: Backspace Operations (18 tests) - 🔄 In PR Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests #404
- Phase 4: Slash Command Integration (21 tests) - 🔄 In PR Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests #404
- Phase 5: Autocomplete Flow (17 tests) - 🔄 In PR Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests #404
Documentation ✅ COMPLETE (PR #395)
- Update
CLAUDE.mdwith testing strategy explanation - Add browser test writing guide to
/docs/architecture/development/testing-guide.md - Document when to use Happy-DOM vs Browser Mode
Enhanced Documentation (PR #404)
- Add 4 comprehensive browser mode examples - 🔄 In PR Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests #404
- Document pragmatic testing philosophy - 🔄 In PR Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests #404
- Add best practices section - 🔄 In PR Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests #404
- Include "When NOT to use" section - 🔄 In PR Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests #404
Technical Details
Vitest Browser Config:
// vitest.browser.config.ts
export default defineConfig({
test: {
browser: {
enabled: true,
name: 'chromium',
provider: 'playwright',
headless: true
},
include: ['src/tests/browser/**/*.test.ts']
}
})Dependencies:
{
"@vitest/browser": "2.1.9",
"playwright": "^1.56.1"
}Setup: bunx playwright install chromium (one-time)
Test Results (After PR #404 Merges)
All 77 browser tests passing in ~750ms:
✓ src/tests/browser/focus-management.test.ts (6 tests) 13ms
✓ src/tests/browser/enter-key-focus.test.ts (15 tests) 12ms
✓ src/tests/browser/backspace-focus.test.ts (18 tests) 10ms
✓ src/tests/browser/slash-dropdown-interaction.test.ts (21 tests) 14ms
✓ src/tests/browser/autocomplete-interaction.test.ts (17 tests) 11ms
Benefits
✅ Test real browser behavior (focus, blur, DOM APIs, positioning)
✅ 77 comprehensive tests covering all critical user workflows
✅ Fast execution (~750ms for all browser tests)
✅ Pragmatic approach (test APIs directly, not full components)
✅ Catch browser-specific bugs before production
✅ Maintain fast unit tests with Happy-DOM (728+ tests)
✅ Hybrid testing strategy provides optimal speed/coverage trade-off
Implementation Notes
Pragmatic Approach: Instead of migrating 2,320 lines of deleted integration tests, created new focused browser tests (~1,650 lines) that:
- Test current textarea-based implementation (not obsolete ContentEditableController)
- Focus exclusively on browser-specific APIs
- Avoid component complexity
- Complement (not duplicate) Happy-DOM tests
Result: Same confidence, less complexity, better maintainability.
Non-Goals
- ❌ Replace all Happy-DOM tests (keep fast unit tests)
- ❌ Add visual regression testing (separate initiative)
- ❌ Test backend integration (use existing integration tests)
References
- Vitest Browser Mode: https://vitest.dev/guide/browser/
- Issue Migrate to textarea-based editor (Logseq approach) #274: Textarea migration (where tests were deleted)
- PR Add Vitest Browser Mode Infrastructure (Phase 1) #395: Phase 1 complete (merged)
- PR Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests #404: Phases 2-5 (in review)
Activity
Fix code quality issues from PR #280 review (#274)
Migrate to textarea-based editor (Logseq approach) (#280)
Address code review feedback
Add Vitest Browser Mode Infrastructure (Phase 1) (#395)
malibio commentedon Nov 4, 2025
✅ Phase 1 Complete - Vitest Browser Mode infrastructure is now merged to main!
What Was Delivered
✅ Complete browser test infrastructure with Vitest + Playwright
✅ 6 proof-of-concept focus management tests demonstrating real browser behavior
✅ Comprehensive documentation (CLAUDE.md + testing-guide.md)
✅ Clear hybrid testing strategy (Happy-DOM → Browser Mode → Database Mode)
Next Steps
Future phases will migrate the remaining test suites in separate issues:
Phase 1 infrastructure is ready for immediate use. Any feature can now write browser tests for focus/blur events and real browser interactions. 🎉
malibio commentedon Nov 4, 2025
🔄 Continuing with Phases 2-5
Reopened the feature branch to complete the remaining test migration phases. Phase 1 (infrastructure) is already in main, now we'll continue with the remaining test migrations on the same branch.
Remaining Work:
Branch recreated:
feature/issue-282-vitest-browser-modeComplete Issue #282 Phases 2-5: Add 71 focused browser mode tests
Update testing guide with pragmatic browser mode patterns from Issue #…
Complete Issue #282 Phases 2-5: Add 71 focused browser mode tests
Update testing guide with pragmatic browser mode patterns from Issue #…
Complete Issue #282 Phases 2-5: Add 71 focused browser mode tests
Update testing guide with pragmatic browser mode patterns from Issue #…
Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests (#404)
Migrate to textarea-based editor (Logseq approach) (#280)
Add Vitest Browser Mode Infrastructure (Phase 1) (#395)
Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests (#404)
Migrate to textarea-based editor (Logseq approach) (#280)
Add Vitest Browser Mode Infrastructure (Phase 1) (#395)
Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests (#404)
Migrate to textarea-based editor (Logseq approach) (#280)
Add Vitest Browser Mode Infrastructure (Phase 1) (#395)
Complete Issue #282 Phases 2-5: Add 71 Browser Mode Tests (#404)