Add comprehensive automated testing with Vitest#19
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements comprehensive automated testing for DOMule, addressing issue #10.
What's included
Test Infrastructure
Test Files (13 total, 274 tests)
util.math.test.mjsutil.format.test.mjsutil.iteration.test.mjsutil.dom.test.mjsutil.debounce.test.mjsutil.observe.test.mjscore.registry.test.mjscore.scanner.test.mjscore.loader.test.mjscore.events.test.mjscore.log.test.mjsintegration.test.mjsmodule.compat.test.mjsnpm Scripts
npm test- Run all tests oncenpm run test:watch- Watch modenpm run test:coverage- With coverage reportnpm run test:module- Test a custom module (set MODULE env var)Test plan
Closes #10