-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Option to disable globals #2765
Comments
Not a core contributor here, but I don't think this is possible the way Mocha is written. If it's really important to you, you may need to use a different test runner. Just out of curiosity, what is your primary reason for not wanting a couple of global variables defined? (I can imagine a couple reasons). |
|
I am 100% with you - if that's very important to you, then you should try AVA or TapJS/Tape, instead. Of course, a core member might step in and say that you can avoid globals with Mocha, but I am 99% certain that's not possible. |
I believe that if bug #2207 were fixed, it would be possible/trivial to create a no-op interface that doesn't set up any globals and therefore would effectively leave you with the See also #2210 |
(Apologies for the double-post --) This would also fix #956, if I understand correctly. Seems like the complaint is very old and adding the ability to |
Yeah, it would be nice to have:
or whatever |
Right -- you can do that now. What you can't do is make it an error to use those functions without having But on the other hand, I think that this should work to achieve that: // requires.js
module.exports = function() {} mocha --ui requires ...except that Mocha's BDD interface is being set up no matter what other interface is selected, which is a bug anyway (e.g. it gets set up if you use So in other words, I believe this request would be really simple to fulfill -- if we first fix an unrelated bug that merely happens to have an effect that renders the solution here moot. |
Urgh -- you might be right about this enhancement not being so possible; I was just digging into #2207 and discovered along the way that the "require interface" is implemented by way of a giant hack: hardcoding the exports in question for BDD and TDD to reference whichever one is set up globally. ...I... don't even know what to say to that. The only reason I can imagine it might have been done is that Mocha's interfaces technically get set up once per file rather than once and for all globally when run in Node, using a convoluted system of event-emitting from the root suite as files are loaded. But on the other hand, I can't imagine a good reason to set up the interface once per file like that -- and it certainly won't be doing that in the browser, so I would be surprised if it's even having any effect now as it is... This looks an awful lot like a backwards-compatibility hack for legacy code that was designed around environment assumptions that aren't even valid anymore -- though of course, being absolutely certain it's that and not breaking anything if we changed it... Hrmm. Not easy. Well, now I'm just annoyed enough I might try to get a PR working just to spite the whole thing, but I can't make any promises. |
Yup, you were right all along -- this isn't feasible, short of some pretty drastic changes to the semi-internal structure. It's pretty weird -- I tried to fake the system out by imitating the global setup but using a dummy suite and a dummy object in place of the global object, to see if I could get the interface to attach to the dummy object instead -- no such luck, because while I was able to call the interface functions exported that way, doing so didn't cause the tests to be used. Apparently there's some hidden coupling buried in there somewhere between the suite or some such context and what the interface functions interact with under the hood. ...Which, horrifyingly, makes a certain amount of sense now that I think about the fact that you can theoretically create multiple instances using the Even having worked with Mocha for some time now, I'm still learning new things. Unfortunately, at this point I'm mostly learning just how deep the rabbit-hole goes. Talk about legacy code. |
I am a bot that watches issues for inactivity. |
So, the mocha team would rather quit and go the way of grunt? |
@stevenvachon please keep your comments constructive. duplicate of #956 |
It was constructive, albeit a bit negative. |
what’s constructive is finding a solution, offering to help, or sending a PR |
I don't want anything mocha-related defined on
global
. I understand that not everyone cares to explicitly have everything required/imported, but I do, so it can be optional.The text was updated successfully, but these errors were encountered: