diff --git a/lib/proxyquire.js b/lib/proxyquire.js index 64dca95..e6bcf69 100644 --- a/lib/proxyquire.js +++ b/lib/proxyquire.js @@ -284,6 +284,13 @@ Proxyquire.prototype._disableModuleCache = function (path, module) { // Return a function that will undo what we just did return function () { + const currentModule = Module._cache[id]; + const currentModuleParent = currentModule.parent; + // remove reference to a temporal module from a parent + if (currentModuleParent && currentModuleParent.children) { + currentModuleParent.children = currentModuleParent.children.filter(m => m !== currentModule) + } + // restore cache entry if (cached) { Module._cache[id] = cached } else {