Enhance Jest Configuration and Resolver for ESM and TypeScript Support

- Updated Jest configuration to handle .mts and .mjs file extensions
- Improved Jest resolver to better support ESM modules and @digital-alchemy packages
- Added comprehensive test coverage for AI router, Home Assistant integration, and WebSocket client
- Expanded test scenarios for error handling, event subscriptions, and service interactions
This commit is contained in:
jango-blockchained
2025-02-01 13:53:55 +01:00
parent 99c66099c6
commit 8f0b9eb909
4 changed files with 447 additions and 105 deletions

View File

@@ -16,18 +16,43 @@ module.exports = (request, options) => {
}
}
// Handle @digital-alchemy packages
if (request.startsWith('@digital-alchemy/')) {
try {
const packagePath = path.resolve(__dirname, 'node_modules', request);
return options.defaultResolver(packagePath, {
...options,
packageFilter: pkg => {
if (pkg.type === 'module') {
if (pkg.exports && pkg.exports.import) {
pkg.main = pkg.exports.import;
} else if (pkg.module) {
pkg.main = pkg.module;
}
}
return pkg;
}
});
} catch (e) {
// If resolution fails, continue with default resolver
}
}
// Call the default resolver
return options.defaultResolver(request, {
...options,
// Handle ESM modules
packageFilter: pkg => {
// Preserve ESM modules
if (pkg.type === 'module' && pkg.exports) {
// If there's a specific export for the current conditions, use that
if (pkg.exports.import) {
pkg.main = pkg.exports.import;
} else if (typeof pkg.exports === 'string') {
pkg.main = pkg.exports;
if (pkg.type === 'module') {
if (pkg.exports) {
if (pkg.exports.import) {
pkg.main = pkg.exports.import;
} else if (typeof pkg.exports === 'string') {
pkg.main = pkg.exports;
}
} else if (pkg.module) {
pkg.main = pkg.module;
}
}
return pkg;