File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 102102 }
103103 }
104104 } ;
105+
106+ // Implement __resetAllModules
107+ // This allows the test runner to reset the state of all modules
108+ globalObject . __resetAllModules = function ( ) {
109+ if ( globalObject . __r && globalObject . __r . getModules ) {
110+ const modules = globalObject . __r . getModules ( ) ;
111+ if ( modules ) {
112+ for ( const [ moduleId , mod ] of modules ) {
113+ if ( mod ) {
114+ // We need to create a new object to ensure that the module is re-evaluated
115+ // Mutating existing module directly might not work as expected in some cases
116+ const newMod = { } ;
117+ for ( const key in mod ) {
118+ if ( Object . prototype . hasOwnProperty . call ( mod , key ) ) {
119+ newMod [ key ] = mod [ key ] ;
120+ }
121+ }
122+ newMod . isInitialized = false ;
123+ modules . set ( moduleId , newMod ) ;
124+ }
125+ }
126+ }
127+ }
128+ } ;
105129} ) (
106130 typeof globalThis !== 'undefined'
107131 ? globalThis
You can’t perform that action at this time.
0 commit comments