-
Notifications
You must be signed in to change notification settings - Fork 128
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
Modifying globals within module leaks to global with Node >=10 #167
Comments
I think I found the problem: clearly, Now,
Note that I think however, that simply adding
(that is Node 10 output, Node 9 is similar but missing The fix should be simple: replace An extra test has to be added too, to cover both enumerable and non-enumerable globals. Care should be taken that the chosen example globals are available in all versions of Node under test, and are always either enumerable or non-enumerable (so |
And – but I've never worked with them, so I am not sure how relevant they are – consider symbols:
They are (the only?) global variables that are not included in |
Possibly relevant is that in browsers, there are way more global variables
Could declaring them all with |
I think this is relevant to my issue where we are trying to override It works in Node 10, but stops working in Node 12. Node 10:
Node 12:
|
And to quote from https://nodejs.org/docs/latest-v12.x/api/process.html#process_process:
Does this sound right? Any other explanations? |
Not quite sure how to explain it, I'm not sure on their terminology. When I said " |
Using
on NodeJS 12 is broken, however...
does work on NodeJS 12 for me. |
* rewire workaround for NodeJS 12 * additional comment with a link to the underlying issue in jhnns/rewire#167
So,
which should return an integer (for me, it is 60) indicating it is in that list. But indeed, the same bug is the cause of your problems. I have a fork that fixes it. I also submitted it as a PR, but it has been a long time since the last PR in this repo was merged. Note, though, that the workaround to |
Thanks for the note... I'll forward this to the cordova peeps. We've tried the dot notation workaround and it didn't break existing tests, but would be beneficial to keep an eye on your PR so that we can update asap. |
This works around jhnns/rewire#167 by using Jasmine's `spyOn` to stub global variables like `process` and `console`.
* fix: return unhandled promises from run.spec tests * fix: stub globals w/ spyOn instead of rewire This works around jhnns/rewire#167 by using Jasmine's `spyOn` to stub global variables like `process` and `console`. * Move some tests from Api.spec to check_reqs.spec * Read configs in beforeEach instead of restoring them * Split test in prepare.spec into two * Pass fresh EventEmitter to every new Api instance This has multiple benefits: - we don't register too many listeners on `cordova-common.events` - we silence all output from Api * Fix and simplify check_reqs.checkTool tests * Simplify test for build.getDefaultSimulatorTarget
Yes, I can confirm this. This is because they started to make some global objects non-enumerable. I just skimmed #168 and it looks like it's a good fix for this. |
In case anyone else is having problems with this, in the absence of a fix I've stumbled into a workaround. For each module whose test module is
and add globals as needed. One caveat is that this may not work with repackaging tools. For instance, we have a check on |
Published as v6.0.0 🚀 |
Thank you!!! Version 6.0.0 seems to work for me: there is no longer a leak with global overrides (like Date, which was my case). |
When running the test suite with Node 10 or higher, the test
should not influence other modules when injecting mocks
in the shared test cases fails. This happens because__set__
ing a global inmoduleA.js
doesn't set that global only within that module, but globally (so also inmoduleB.js
and in the test suite itself). This should not happen, since it leaks to other tests and can have various unwanted effects. It did not happen with Node 9 (which is why Travis also didn't pick this up - it tests with Node 6, 8 and 9), and I do not know why this happens using higher versions (Node 10, 11 and 12 all have this behaviour, starting from the very first v10.0.0).What makes this case even more mysterious, is that since that test (
should not influence ...
) setsconsole
to a dummy mock{ }
(which should only have effect inmoduleA
, but because of this bug also changes the globalconsole
), all further Mocha output (which usesconsole.log
) is suppressed. It took me a while therefore, to actually notice this test was failing!All other tests seem to pass fine –
it.skip
the failing test, and you see the other tests pass:This is also the easiest way to check that Mocha actually ran the other tests.
How to reproduce
I use
nvm
to switch between node versions. (I left out some of the test results, as marked by...
)Note that the last 20-or-so tests disappeared, and there was no test result '
x passing
'.The text was updated successfully, but these errors were encountered: