Skip to content

Commit 4fb0489

Browse files
committed
fix: add missing resetModules
1 parent c980955 commit 4fb0489

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

packages/runtime/assets/harness-module-system.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,30 @@
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

0 commit comments

Comments
 (0)