Skip to content

Conversation

@c-kick
Copy link
Owner

@c-kick c-kick commented Jan 15, 2026

Summary

This PR implements comprehensive automated testing for DOMule, addressing issue #10.

What's included

Test Infrastructure

  • Vitest configuration with jsdom environment
  • Global mocks for browser APIs (IntersectionObserver, ResizeObserver, matchMedia)
  • Coverage thresholds (70% lines/functions, 60% branches)
  • GitHub Actions CI workflow for Node 18.x, 20.x, 22.x

Test Files (13 total, 274 tests)

File Tests Description
util.math.test.mjs 18 toMS, cubicBezier, getRandomInt
util.format.test.mjs 36 cleanUpString, formatPhone, formatHref
util.iteration.test.mjs 17 objForEach, forEachBatched
util.dom.test.mjs 21 parseHTML, writeCSS, waitForComplexNode
util.debounce.test.mjs 20 debounceThis, debouncedEvent
util.observe.test.mjs 24 isVisible, isVisibleNow, isUnobstructed
core.registry.test.mjs 23 ModuleRegistry API
core.scanner.test.mjs 23 domScanner
core.loader.test.mjs 26 loadModules, path validation, security
core.events.test.mjs 19 EventHandler singleton
core.log.test.mjs 18 Logger with debug mode
integration.test.mjs 17 Full scanner→loader→registry flow
module.compat.test.mjs 12 Custom module compatibility checker

npm Scripts

  • npm test - Run all tests once
  • npm run test:watch - Watch mode
  • npm run test:coverage - With coverage report
  • npm run test:module - Test a custom module (set MODULE env var)

Test plan

  • All 274 tests pass
  • Coverage thresholds met
  • CI workflow configured for Node 18/20/22

Closes #10

claude and others added 3 commits January 15, 2026 10:44
Implements comprehensive testing infrastructure for issue #10.

Test Setup:
- Vitest with jsdom environment for DOM testing
- Mock implementations for IntersectionObserver, ResizeObserver
- Helper utilities for creating test elements

Test Coverage (116 tests):
- util.math.mjs: toMS, cubicBezier, getRandomInt (17 tests)
- util.format.mjs: cleanUpString, formatPhone, formatHref, formatString (36 tests)
- util.iteration.mjs: objForEach, forEachBatched (17 tests)
- core.registry.mjs: ModuleRegistry API (23 tests)
- core.scanner.mjs: domScanner with lazy loading detection (23 tests)

CI/CD:
- GitHub Actions workflow for automated testing on PRs
- Tests run on Node.js 18.x, 20.x, and 22.x
- Coverage reporting with v8 provider

npm scripts:
- npm test: Run tests
- npm run test:watch: Run in watch mode
- npm run test:coverage: Generate coverage report

Closes #10
This commit addresses all issues identified in the self-review:

## Test Infrastructure Improvements
- Add matchMedia mock to setup.mjs (fixes hnl.breakpoints.mjs errors)
- Add registry cleanup in afterEach to prevent state leakage
- Use vi.useFakeTimers() for deterministic timeout tests
- Mock Math.random for deterministic random number tests

## New Test Files (7 modules, ~200 new tests)
- core.loader.test.mjs: 26 tests for module loading, path validation
- core.events.test.mjs: 19 tests for event handler singleton
- core.log.test.mjs: 18 tests for debug logging with badge styling
- util.dom.test.mjs: 21 tests for DOM utilities
- util.debounce.test.mjs: 20 tests for debounce/throttle functions
- util.observe.test.mjs: 24 tests for visibility detection
- integration.test.mjs: 17 tests for scanner->loader->registry flow

## CI/CD Improvements
- Add fail-fast: false for matrix builds
- Add timeout-minutes for test jobs
- Add coverage artifact upload
- Add test-summary job for PR status

Total: 262 tests passing across 12 test files

Closes #10
   Adds a reusable test that checks if any module is DOMule-compatible.
   Users can test their own modules by setting the MODULE environment variable.

   Usage:
     $env:MODULE="./modules/mymodule.mjs"; npm run test:module  (PowerShell)
     set MODULE=./modules/mymodule.mjs && npm run test:module   (CMD)
     MODULE=./modules/mymodule.mjs npm run test:module          (Linux/Mac)

   Tests 12 compatibility checks:
   - NAME export (required, non-empty string)
   - init() function (optional, accepts elements/context)
   - api() function (optional, handles unknown actions)
   - destroy() function (optional, callable)
   - ModuleRegistry integration
@c-kick c-kick merged commit 9bc21ea into main Jan 15, 2026
6 checks passed
@c-kick c-kick deleted the claude/code-review-critique-OS8ld branch January 15, 2026 15:57
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.

No automated tests

3 participants