Skip to content

Commit 1911ae6

Browse files
committed
fix: actor initialization and helper config issues (v4.0.1-beta.7)
- Fixed actor not being populated with helper methods - Fixed circular dependency in actor.js - Moved actor creation timing to allow proper callback registration - Fixed helpers to use this.options consistently instead of this.config - Fixed helpers to merge defaults after _setConfig() - Fixed container proxy getOwnPropertyDescriptor for destructuring support - Changed createHelpers to defer await for proper callback accumulation
1 parent de632a3 commit 1911ae6

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

lib/actor.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ export default function (obj = {}, container) {
7575
if (!container) {
7676
container = Container
7777
}
78-
79-
const actor = container.actor() || new Actor()
78+
79+
// Create a new Actor instance
80+
const actor = new Actor()
8081

8182
// load all helpers once container initialized
8283
container.started(() => {

lib/container.js

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class Container {
7474
// Preload includes (so proxies can expose real objects synchronously)
7575
const includes = config.include || {}
7676

77-
// Ensure I is available for DI modules at import time
77+
// Check if custom I is provided
7878
if (Object.prototype.hasOwnProperty.call(includes, 'I')) {
7979
try {
8080
const mod = includes.I
@@ -89,7 +89,7 @@ class Container {
8989
throw new Error(`Could not include object I: ${e.message}`)
9090
}
9191
} else {
92-
// Create default actor if not provided via includes
92+
// Create default actor - this sets up the callback in asyncHelperPromise
9393
createActor()
9494
}
9595

@@ -110,7 +110,7 @@ class Container {
110110
}
111111
}
112112

113-
// Wait for all async helpers to finish loading and populate the actor with helper methods
113+
// Wait for all async helpers to finish loading and populate the actor
114114
await asyncHelperPromise
115115

116116
if (opts && opts.ai) ai.enable(config.ai) // enable AI Assistant
@@ -350,16 +350,17 @@ async function createHelpers(config) {
350350
}
351351
}
352352

353-
// Wait for all async helpers to be fully loaded
354-
await asyncHelperPromise
355-
356-
// Call _init on all helpers after they're all loaded
357-
for (const name in helpers) {
358-
if (helpers[name]._init) {
359-
await helpers[name]._init()
360-
debug(`helper ${name} _init() called`)
353+
// Don't await here - let Container.create() handle the await
354+
// This allows actor callbacks to be registered before resolution
355+
asyncHelperPromise = asyncHelperPromise.then(async () => {
356+
// Call _init on all helpers after they're all loaded
357+
for (const name in helpers) {
358+
if (helpers[name]._init) {
359+
await helpers[name]._init()
360+
debug(`helper ${name} _init() called`)
361+
}
361362
}
362-
}
363+
})
363364

364365
return helpers
365366
}
@@ -534,10 +535,17 @@ function createSupportObjects(config) {
534535
return [...new Set([...keys, ...container.sharedKeys])]
535536
},
536537
getOwnPropertyDescriptor(target, prop) {
538+
// For destructuring to work, we need to return the actual value from the getter
539+
let value
540+
if (container.sharedKeys.has(prop) && prop in container.support) {
541+
value = container.support[prop]
542+
} else {
543+
value = lazyLoad(prop)
544+
}
537545
return {
538546
enumerable: true,
539547
configurable: true,
540-
value: target[prop],
548+
value: value,
541549
}
542550
},
543551
get(target, key) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codeceptjs",
3-
"version": "4.0.0-beta.20",
3+
"version": "4.0.1-beta.7",
44
"type": "module",
55
"description": "Supercharged End 2 End Testing Framework for NodeJS",
66
"keywords": [

0 commit comments

Comments
 (0)