Skip to content

Migrate integration tests to Vitest Browser Mode #282

Closed

Description

@malibio

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
  • Phase 3: Backspace Operations (18 tests)

    • File: src/tests/browser/backspace-focus.test.ts
    • Focus transitions to previous node, merge point cursor positioning
  • Phase 4: Slash Command Integration (21 tests)

    • File: src/tests/browser/slash-dropdown-interaction.test.ts
    • Dropdown positioning, viewport edge detection, keyboard navigation
  • Phase 5: Autocomplete Flow (17 tests)

    • File: src/tests/browser/autocomplete-interaction.test.ts
    • @mention dropdown positioning, Selection API, reference insertion

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

Documentation ✅ COMPLETE (PR #395)

  • Update CLAUDE.md with 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)

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

Activity

  1. added
    enhancement
    on Oct 17, 2025
  2. self-assigned this
    on Nov 4, 2025
  3. added a commit that references this issue on Nov 4, 2025
  4. malibio commented on Nov 4, 2025

    @malibio
    CollaboratorAuthor

    ✅ 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 2: Enter Key Operations (626 lines)
    • Phase 3: Backspace Operations (555 lines)
    • Phase 4: Slash Command Integration (260 lines)
    • Phase 5: Autocomplete Flow (879 lines)

    Phase 1 infrastructure is ready for immediate use. Any feature can now write browser tests for focus/blur events and real browser interactions. 🎉

  5. reopened this on Nov 4, 2025
  6. malibio commented on Nov 4, 2025

    @malibio
    CollaboratorAuthor

    🔄 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:

    • Phase 2: Enter Key Operations (626 lines)
    • Phase 3: Backspace Operations (555 lines)
    • Phase 4: Slash Command Integration (260 lines)
    • Phase 5: Autocomplete Flow (879 lines)

    Branch recreated: feature/issue-282-vitest-browser-mode

  7. reopened this on Nov 4, 2025
  8. added 3 commits that reference this issue on Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementtesting

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions