Successfully integrated comprehensive ESM (ES Modules) integration tests into the CI/CD pipeline to prevent ESM-related issues from reaching production.
- 8 test scenarios covering all aspects of ESM compatibility
- Static validation of import/export statements (scans 29+ files)
- Package structure validation
- Runtime import resolution testing
- Functionality verification
- Export completeness checks
- Run:
npm run test:esm:integration
- 4 fast tests for rapid validation
- Tests main entry point, decorator module, core module
- Basic functionality verification
- Run:
npm run test:esm:simple
- 10 usage scenarios simulating post-npm-install experience
- Tests basic mapper usage, field mapping, arrays, error handling
- Validates nested field access and multiple mappers
- Run:
npm run test:esm:simulation
New Job: esm-validation
- Runs on Node.js 18, 20, and 22 (matrix strategy)
- Executes after unit tests pass
- Validates:
- ✅ ESM build artifacts exist
- ✅
package.jsontype marker present - ✅ All imports have proper
.jsextensions - ✅ Runtime imports work correctly
- ✅ Functionality tests pass
- Uploads test results as artifacts
New Job: esm-validation-summary
- Posts PR comment with validation results
- Shows test matrix status for all Node.js versions
- Lists validation steps with pass/fail indicators
- Explains what was validated
- Updates existing comment on subsequent pushes
Added Pre-Release Validation:
- Runs ESM integration tests before publishing
- Verifies package integrity (CJS + ESM builds)
- Checks for ESM package marker
- Prevents broken ESM builds from being published to npm
Added to package.json:
{
"test:esm": "npm run test:esm:integration && npm run test:esm:simple && npm run test:esm:simulation",
"test:esm:integration": "node test/esm-integration.test.mjs",
"test:esm:simple": "node test/esm-runtime-simple.test.mjs",
"test:esm:simulation": "node test/esm-post-install-simulation.test.mjs",
"test:all": "npm run test && npm run test:esm"
}Created test/ESM_TESTING.md - Comprehensive guide covering:
- Why ESM testing is critical
- Detailed test file descriptions
- How to run tests locally
- CI/CD integration explanation
- Common issues and debugging tips
- Build process details
- Maintenance guidelines
- Scans all
.jsfiles inbuild/esm/ - Verifies every import/export has
.jsor.jsonextension - Reports missing extensions with file and line number
- Confirms
build/esm/package.jsonexists - Validates
"type": "module"marker
- Actually imports modules in Node.js
- Catches
ERR_MODULE_NOT_FOUNDerrors - Validates all expected exports are accessible
- Tests that imported code executes correctly
- Validates mapper creation and execution
- Tests array transformations
- Verifies nested field access
- Checks all expected functions/classes are exported
- Validates export types
- Ensures no exports are missing
1. Developer pushes code
↓
2. Unit Tests run (npm test)
↓
3. Build runs (npm run build)
↓
4. ESM Validation runs on Node.js 18, 20, 22
↓
5. PR Comment posted with results
↓
6. Merge blocked if ESM tests fail
1. Code merged to main
↓
2. Unit Tests run
↓
3. Build runs
↓
4. ESM Integration Tests run ← NEW!
↓
5. Package integrity verified ← NEW!
↓
6. Semantic Release publishes to npm
- Catch issues early - ESM problems detected in PR, not production
- Clear feedback - PR comments show exactly what failed
- Multiple Node.js versions - Test on 18, 20, 22 automatically
- Fast local testing - Run
npm run test:esmbefore pushing
- No broken imports - Guaranteed working ESM imports
- Node.js compatibility - Tested on multiple versions
- Reliable package - Can't publish broken ESM builds
- Automated validation - No manual ESM testing needed
- Comprehensive coverage - 8 integration + 4 smoke + 10 simulation tests
- Documentation - Clear guide for troubleshooting
- Artifact uploads - Debug failed builds easily
This test suite prevents:
❌ Missing .js Extensions
export * from './core/Mapper' // Would fail ESM tests❌ Incorrect Directory Imports
export * from './decorators.js' // Would fail ESM tests❌ Missing Package Marker
build/esm/ without package.json // Would fail ESM tests
❌ Broken Export Chains
// Missing re-export would fail completeness tests❌ Runtime Import Errors
ERR_MODULE_NOT_FOUND // Would fail runtime tests
- Integration Tests: 8 scenarios
- Smoke Tests: 4 scenarios
- Simulation Tests: 10 scenarios
- Total: 22 ESM-specific test scenarios
- Node.js 18 (LTS)
- Node.js 20 (LTS)
- Node.js 22 (Current)
- 29+ JavaScript files in
build/esm/ - All import/export statements
- Package structure
- Runtime behavior
npm run test:esmnpm run test:esm:integration # Comprehensive
npm run test:esm:simple # Quick smoke test
npm run test:esm:simulation # Real-world scenariosnpm run test:all # Unit tests + ESM tests# Build first
npm run build:esm
# Run tests with verbose output
node test/esm-integration.test.mjs- Enhanced
fix-esm-imports.jsto handle directory imports - Added
/index.jsfor directory imports - Created runtime validation tests
- Added 3 test files (22 test scenarios)
- Updated CI/CD workflows
- Added comprehensive documentation
- Integrated into release process
- Using
module: "ESNext"+moduleResolution: "bundler" - Post-build script adds
.jsextensions - Avoids requiring
.jsin.tssource files
- Explicit
.jsextensions required - Directory imports need
/index.js - Package marker
{"type": "module"}required
- Static analysis catches syntax issues
- Runtime tests catch resolution issues
- Functionality tests catch logic issues
- Multi-version testing catches compatibility issues
- Test Documentation:
test/ESM_TESTING.md - CI Workflow:
.github/workflows/ci.yml - Release Workflow:
.github/workflows/release.yml - Package Scripts:
package.json
We've successfully created a robust, automated ESM validation system that:
- ✅ Prevents ESM issues from reaching production
- ✅ Tests on multiple Node.js versions (18, 20, 22)
- ✅ Provides clear PR feedback via automated comments
- ✅ Blocks broken builds from being published
- ✅ Includes comprehensive documentation for maintenance
- ✅ Runs automatically on every PR and release
The package is now production-ready with guaranteed ESM compatibility! 🚀