$ node -r esm index.js
Hi @deepsweet!
This is still a cache clearing thing.
You can see that if you remove the entire cache...
Module._cache = {}
...it will report the correct results.
!!!
[Module] { default: 123 }
[Module] { default: [Function] }
So clearing entire cache is the only way? I tried to clear cache for specific file.
This helps:
Reflect.deleteProperty(Module._cache, path.resolve('./file.js'))
Reflect.deleteProperty(Module._cache, path.resolve('./file2.js'))
But for example if I write my own mocking library then how do I know these related files?
Ok, I'm going to iterate over cache and look for related parents. Sorry for all the noise, it looks like I finally have no more issues.
No problem. Check with how other mocking libs work with it _(they may have already covered the ground)_ or you could suggest improvements to them as well 馃挭
Just to let you know that I ended up with my own "ESM mocking library" which I will keep in sync with esm loader because that's my personal use case now. Thanks for all the help, I can finally write tests.
Awesome @deepsweet!
Most helpful comment
Just to let you know that I ended up with my own "ESM mocking library" which I will keep in sync with
esmloader because that's my personal use case now. Thanks for all the help, I can finally write tests.