diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5668f87 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,24 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# ============================================================================ +# EXPORT IGNORE - Excluded from `git archive` (production builds) +# ============================================================================ + +# Test files +__tests__/ export-ignore +vitest.config.mjs export-ignore +coverage/ export-ignore + +# Development configuration +.github/ export-ignore +.gitattributes export-ignore + +# Package management (not needed in production) +package.json export-ignore +package-lock.json export-ignore +node_modules/ export-ignore + +# Documentation that's not needed in production +CHANGELOG.md export-ignore +CONTRIBUTING.md export-ignore diff --git a/README.md b/README.md index 3803591..c46e8bc 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ A lightweight module loader that lets DOM elements request their own JavaScript - [Using Third-Party Modules](#using-third-party-modules) - [Migration Guide (v2.x → v3.0)](#migration-guide-v2x--v30) - [Troubleshooting](#troubleshooting) +- [Testing](#testing) - [DOM... what?](#so-why-is-it-called-domule) - [Notes](#notes) @@ -1170,6 +1171,76 @@ Core features require ES6 module support. Optional features degrade gracefully: --- +## Testing + +DOMule includes a comprehensive test suite using [Vitest](https://vitest.dev/). + +### Running Tests + +```bash +# Install dependencies (first time only) +npm install + +# Run all tests +npm test + +# Watch mode (re-runs on file changes) +npm run test:watch + +# With coverage report +npm run test:coverage +``` + +### Test Structure + +``` +__tests__/ +├── core.*.test.mjs # Core module tests (loader, registry, events, etc.) +├── util.*.test.mjs # Utility function tests (debounce, observe, format, etc.) +├── integration.test.mjs # Full loading flow tests +└── module.compat.test.mjs # Module compatibility checker +``` + +### Testing Your Custom Modules + +Validate that your module is compatible with DOMule: + +```bash +# Linux/Mac +MODULE=./modules/mymodule.mjs npm run test:module + +# Windows CMD +set MODULE=./modules/mymodule.mjs && npm run test:module + +# PowerShell +$env:MODULE="./modules/mymodule.mjs"; npm run test:module +``` + +This checks for: +- Required `NAME` export +- Valid `init(elements, context)` signature +- Optional `api()` and `destroy()` functions +- ModuleRegistry compatibility + +### Production Distribution (without tests) + +Two options for getting a clean distribution without test files: + +**Option 1: npm pack** +```bash +npm pack +# Creates domule-3.2.0.tgz with only production files +``` + +**Option 2: git archive** +```bash +git archive --format=zip HEAD -o domule-production.zip +``` + +Both methods exclude `__tests__/`, `node_modules/`, and other development files. The `files` field in `package.json` controls npm pack output, while `.gitattributes` controls git archive. + +--- + ## So, why is it called "DOMule"? Great question. @@ -1187,6 +1258,6 @@ DOM + Module + Mule. This is a personal repository for maintaining the module system. Feel free to use it, but note: modules may change without prior notice. -**Version:** 3.1.0 +**Version:** 3.2.0 **License:** MIT **Author:** Klaas Leussink / hnldesign diff --git a/package.json b/package.json index bf995f2..0f85d0b 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,22 @@ { "name": "domule", - "version": "3.1.0", + "version": "3.2.0", "description": "A lightweight module loader that lets DOM elements request their own JavaScript dependencies", "type": "module", + "main": "DOMule.mjs", + "files": [ + "core.*.mjs", + "util.*.mjs", + "modules/", + "DOMule.mjs", + "_template.mjs", + "README.md", + "LICENSE" + ], + "repository": { + "type": "git", + "url": "https://github.com/c-kick/DOMule.git" + }, "scripts": { "test": "vitest run", "test:watch": "vitest",