Skip to content

Commit d676982

Browse files
committed
fix: support inline helper objects in Container.create
- Added detection for inline helper objects (objects with callable methods) - Inline helpers are now used directly without module loading - Distinguishes between inline helpers and empty config objects - Fixes AsyncWrapper test that uses inline TestHelper This resolves the 'Cannot find module TestHelper' error when creating containers with inline helper objects for testing purposes. Test results: 487 passed, 1 failed (pre-existing BDD timeout), 16 skipped
1 parent 395e0e8 commit d676982

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

lib/container.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,19 @@ async function createHelpers(config) {
333333
helperName = HelperClass.constructor.name
334334
}
335335

336+
// Check for inline helper object (plain object with callable methods, no require field)
337+
// Inline helpers have methods defined directly on them, unlike config objects
338+
if (!HelperClass && !config[helperName].require && typeof config[helperName] === 'object') {
339+
// Check if this object has any callable methods (indicates it's an inline helper)
340+
const hasMethods = Object.values(config[helperName]).some(val => typeof val === 'function')
341+
if (hasMethods) {
342+
// This is an inline helper object, use it directly
343+
helpers[helperName] = config[helperName]
344+
debug(`helper ${helperName} loaded as inline object`)
345+
continue
346+
}
347+
}
348+
336349
// classical require - may be async for ESM modules
337350
if (!HelperClass) {
338351
// requireHelperFromModule is async, so we need to await it
@@ -343,9 +356,7 @@ async function createHelpers(config) {
343356
HelperClass = HelperClass.default
344357
debug(`extracted default export for ${helperName}`)
345358
}
346-
}
347-
348-
// handle async CJS modules that use dynamic import
359+
} // handle async CJS modules that use dynamic import
349360
if (isAsyncFunction(HelperClass)) {
350361
helpers[helperName] = {}
351362

0 commit comments

Comments
 (0)