-
Notifications
You must be signed in to change notification settings - Fork 18
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
Overriding globalThis
per mock
#198
Comments
At the first sight - no, because globalThis (or Array.prototype.map) mocking is not related to ESM / modules / loaders. If you want to suppress/capture console.log, just use 'spy' on globalThis from your test framework. |
esmock doesn't do it now but it is possible to do it. I experimented a few months back and did get a proof of concept working, but changes were very ugly and complicated so they weren't pushed up anywhere. If it is ever implemented it would be too "expensive" for the test process to apply globally imo so maybe best restricted to local mock. The local esmock could be nested inside a global esmock to achieve deep mocking if that makes sense. My own bandwidth has been limited these days. Also it would be cool if esmock interface changed to something like this, esmock(
...localmocks,
...packagemocks, // a new addition, similar to global mock but would not affect imports from node_modules
...globalmocks
) Maybe global this could be mocked on a "packagemocks" definition without being prohibitively slow, if the interface did support such a definition. |
I think it would be useful locally so that each test could have isolated changes to By |
basically. for example, if one mocked path.basename, path.basename would only be mocked for files in the app sharing package.json with the test, but would not be mocked for modules imported from node_modules |
I could try taking a look at implementing it locally, where's a good place to start? |
esmock operates in a way that is absurd (necessarily) and because of that there's not a great place to start. Maybe the best start would be to add a failing test. It would probably be less effort for me to wrap up changes begun here on my machine for this feature and push them up for review. I will at take a look at the changes and maybe push up a minimal starting point this weekend. |
Is it within scope for
esmock
to mockglobalThis
per mocked module? For example, to suppress/captureconsole.log
messages:The text was updated successfully, but these errors were encountered: