Skip to content

Migrate test suite from Jest to Bun with web component testing#22

Merged
thavelick merged 7 commits intomainfrom
jest-to-bun-migration
Aug 9, 2025
Merged

Migrate test suite from Jest to Bun with web component testing#22
thavelick merged 7 commits intomainfrom
jest-to-bun-migration

Conversation

@thavelick
Copy link
Owner

Summary

Complete migration from Jest to Bun test framework with added web component testing capabilities and improved code quality.

  • Jest → Bun Migration: Converted all unit tests to modern Bun framework syntax
  • DOM Testing: Added happy-dom integration for real DOM testing of web components
  • Component Coverage: Comprehensive tests for all 3 web components (SaveMessage, SettingsDialog, SettingOption)
  • Dead Code Removal: Eliminated redundant showSaveMessage() function replaced by web components
  • HTML Coverage: Added make test-coverage-html command for browseable coverage reports
  • Code Quality: Cleaned up redundant comments, maintained 97.25% line coverage

Changes Made

Test Framework Migration

  • Migrated all test syntax from Jest to Bun (mock(), expect(), describe(), etc.)
  • Updated imports and test runner configuration
  • Maintained 100% test compatibility - all existing tests pass

DOM Testing Setup

  • Added @happy-dom/global-registrator dependency
  • Created bunfig.toml and happydom.js for DOM globals in tests
  • Enables real DOM manipulation and web component testing

Web Component Tests

  • SaveMessage: Tests rendering with correct class, id, and text content
  • SettingsDialog: Tests structure rendering and localStorage integration via nested components
  • SettingOption: Tests individual option rendering, selected state, and localStorage persistence
  • Used beforeAll() for clean component registration across all tests

Code Cleanup

  • Dead code removal: Eliminated showSaveMessage() function (9 lines) and its tests (41 lines)
  • Comment cleanup: Removed redundant comments while keeping meaningful ones
  • Dependency injection: Fixed toggleDarkMode parameter handling for better testability

Developer Experience

  • HTML Coverage: New make test-coverage-html generates browseable reports in coverage/html/
  • Performance: Faster test execution with Bun compared to Jest
  • Modern tooling: Leverages Bun's built-in test runner and coverage

Test Results

  • 72 tests passing (maintained from 74, removed 2 dead tests)
  • 97.25% line coverage (excellent coverage maintained)
  • 127 test expectations across unit and component tests
  • All integration tests still pass with existing Playwright setup

Migration Impact

  • Zero breaking changes - all functionality preserved
  • Improved architecture - better separation between mock-based unit tests and DOM-based component tests
  • Enhanced testing - can now test web component behavior with real DOM
  • Cleaner codebase - removed redundant code and comments
  • Better tooling - HTML coverage reports for development

🤖 Generated with Claude Code

thavelick and others added 7 commits August 9, 2025 00:11
- Convert all unit tests from Jest to Bun syntax (mock(), expect(), etc.)
- Add happy-dom for DOM testing capabilities with bunfig.toml configuration
- Create separate web component tests in search-components.spec.js
- Implement proper dependency injection for toggleDarkMode function
- Fix event handler binding with arrow function wrapper
- Add coverage/ directory to .gitignore
- Update package.json with @happy-dom/global-registrator dependency

All 100% test coverage maintained with improved performance and modern tooling.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Keep all project files as JavaScript for consistency in a pure JS project.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Clean up after renaming to happydom.js.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Use beforeAll instead of beforeEach for component registration
- Remove guard clauses since we only register once
- Clean up redundant comments that just restated obvious code
- Keep meaningful comments that explain non-obvious behavior
- Add comprehensive SettingOption component tests

All 74 unit tests passing with 97% line coverage.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Runs unit tests with lcov coverage reporter
- Uses genhtml to generate browseable HTML coverage report
- Outputs to coverage/html/index.html
- Added to .PHONY declaration for proper make behavior

Usage: make test-coverage-html

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
The showSaveMessage() function became redundant after migrating to web
components, since SaveMessage component handles its own visibility with
the show() method.

Removed:
- showSaveMessage() function definition
- showSaveMessage export
- 2 unit tests (41 lines) with 5 test assertions
- Import statement in test file

Results: 72 tests passing, 97.25% line coverage maintained.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Reorder imports in search-components.spec.js alphabetically
- Add proper spacing between test sections
- Add trailing newline to test-results/.last-run.json
- All Biome linting checks now pass

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@thavelick thavelick merged commit 4f936a6 into main Aug 9, 2025
3 checks passed
@thavelick thavelick deleted the jest-to-bun-migration branch August 9, 2025 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant