-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mock.restore() leaks (no garbage collection) #302
Comments
I think I created that leak. Lines 243 to 266 in e42fdbb
It was to bypass some weird behaviour on nodejs v10+ when I did not understand what's going on. I will try to reclaim my lost memory, and provide you a build to test. |
Haha. No worries. I've been running into some extremely bizarre behaviour dealing with node / v8 lately, so I completely understand. Since you're familiar with the architecture, what are you thoughts on the feasibility of providing a route toward reading a file outside of the mocked system? If such a function was available, I'd be glad to do a PR, re-engineering my logic into a helper that allowed people to populate a FileSystem.DirectoryItems object from a set of real paths with the option to pre-load or lazyload files. |
Can you test locally against |
@3cp Cool! Will have a look at it tomorrow. Meanwhile, I just wrapped up this pull request, which I think should help ease everyone's frustrations without doing any major changes to the core. Let me know what you think. |
Bug Report
Hello,
Unfortunately, it seems that garbage collection is not working after mock.restore().
In my case, I have a collection of files which are pre-loaded. The total size is around 100mb.
The format is:
When I call mock.restore(), the expectation is that the memory usage would go down, however it does not.
Re-initializing mock() with the same object causes the memory to go up. Just a few calls to mock/restore puts me over 1.4gb very quickly. I discovered this because GH actions started failing due to exceeding oldspace size for Node 10.
Workaround
If anyone encounters the same issue, here is my workaround, which uses file caching that we can control
Feature Request
Access to original
fs
It would be wonderful to have the ability to access the original
fs
module. Originally, I wanted to do a lazy load solution, which allowed me to only cache files when a readFileSync was called.I'm mocking full node projects with node_modules (testing for https://npmjs.com/ts-patch), but many files never get loaded. It would be great to not have to load them.
It's easy to integrate with the above logic, however however, we'd need the ability to read file data from the actual filesystem. The only way I found to do that was by
child_prcoess.spawnSync
to create a new node instance and get the data from the output buffer. This was unfortunately too slow.TLDR; Would love the have an
fsOriginal
accessible, or, minimally,readFileSync
, so we could lazy-load and cacheThe text was updated successfully, but these errors were encountered: