@@ -40,6 +40,7 @@ class Container {
4040 static create ( config , opts ) {
4141 asyncHelperPromise = Promise . resolve ( )
4242
43+ container . support = { }
4344 container . helpers = createHelpers ( config . helpers || { } )
4445 container . translation = loadTranslation ( config . translation || null , config . vocabularies || [ ] )
4546 container . proxySupport = createSupportObjects ( config . include || { } )
@@ -138,9 +139,9 @@ class Container {
138139 */
139140 static clear ( newHelpers , newSupport , newPlugins ) {
140141 container . helpers = newHelpers || { }
141- container . support = newSupport || { }
142- container . plugins = newPlugins || { }
143142 container . translation = loadTranslation ( )
143+ container . proxySupport = createSupportObjects ( newSupport || { } )
144+ container . plugins = newPlugins || { }
144145 asyncHelperPromise = Promise . resolve ( )
145146 store . actor = null
146147 }
@@ -295,6 +296,10 @@ function createSupportObjects(config) {
295296 return actor [ prop ]
296297 }
297298
299+ if ( ! container . support [ name ] && typeof config [ name ] === 'object' ) {
300+ container . support [ name ] = config [ name ]
301+ }
302+
298303 if ( ! container . support [ name ] ) {
299304 // Load object on first access
300305 const supportObject = loadSupportObject ( config [ name ] )
@@ -326,28 +331,38 @@ function createSupportObjects(config) {
326331 container . support [ name ] = container . support [ name ] || loadSupportObject ( config [ name ] )
327332 return prop in container . support [ name ]
328333 } ,
329- ownKeys ( ) {
330- const keys = [ ]
331- // Add numeric indices
332- for ( let i = 0 ; i < Object . keys ( config ) . length ; i ++ ) {
333- keys . push ( String ( i ) )
334+ getOwnPropertyDescriptor ( target , prop ) {
335+ container . support [ name ] = container . support [ name ] || loadSupportObject ( config [ name ] )
336+ return {
337+ enumerable : true ,
338+ configurable : true ,
339+ value : this . get ( target , prop ) ,
334340 }
335- // Add other properties
341+ } ,
342+ ownKeys ( ) {
336343 container . support [ name ] = container . support [ name ] || loadSupportObject ( config [ name ] )
337- return [ ... keys , ... Reflect . ownKeys ( container . support [ name ] ) ]
344+ return Reflect . ownKeys ( container . support [ name ] )
338345 } ,
339346 } ,
340347 )
341348 }
342349
350+ const keys = Reflect . ownKeys ( config )
343351 return new Proxy (
344352 { } ,
345353 {
346354 has ( target , key ) {
347- return key in container . support
355+ return keys . includes ( key )
348356 } ,
349357 ownKeys ( ) {
350- return Reflect . ownKeys ( container . support )
358+ return keys
359+ } ,
360+ getOwnPropertyDescriptor ( target , prop ) {
361+ return {
362+ enumerable : true ,
363+ configurable : true ,
364+ value : this . get ( target , prop ) ,
365+ }
351366 } ,
352367 get ( target , key ) {
353368 return lazyLoad ( key )
@@ -424,6 +439,9 @@ function loadGherkinSteps(paths) {
424439}
425440
426441function loadSupportObject ( modulePath , supportObjectName ) {
442+ if ( ! modulePath ) {
443+ throw new Error ( `Support object "${ supportObjectName } " is not defined` )
444+ }
427445 if ( modulePath . charAt ( 0 ) === '.' ) {
428446 modulePath = path . join ( global . codecept_dir , modulePath )
429447 }
@@ -440,12 +458,13 @@ function loadSupportObject(modulePath, supportObjectName) {
440458 // If it's a regular function
441459 return obj ( )
442460 }
461+
443462 if ( obj && Array . isArray ( obj ) ) {
444463 return obj
445464 }
446465
447466 // If it's a plain object
448- if ( obj && typeof obj === 'object' && ! Array . isArray ( obj ) ) {
467+ if ( obj && typeof obj === 'object' ) {
449468 return obj
450469 }
451470
0 commit comments