-
-
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
mocha: the next big thing #1969
Comments
Is this a hard requirement for a new major release? For example, would you consider dropping support of it('foo', function(done) {
this.timeout(10000);
}); we could do: it('foo', (test) => {
test.timeout(10000);
}); |
That's a good question, I would be very much in favor to transition to something without a globals in the default setup, so the usage would be something like this const {describe, it, timeout} = require('mocha')
describe('my test', () => {
it('my slow test', () => {
timeout(10000)
})
}) and for backwards compat it would be easy to add something like this const mocha = require('mocha')
global.describe = mocha.describe
global.it = mocha.it |
@dignifiedquire What's wrong with globals by default? And for tests in general? Why bloating every node test file with |
I was imagining backwards compatibility via config or executing something like
I like this change a lot. Doing
No, but I imagine we are likely to change quite a lot along the way, and old hacks might no longer work (or maybe we don't want them to work anymore), like coverage via |
@ArtemGovorov yes something like @dasilvacontin suggest for the non-commonjs based environments. Simply namespacing everything under one global const {describe, it} = window.mocha
// and as a convenience method
window.mocha.deployGlobals = () => {
window.describe = window.mocha.describe
window.it = window.mocha.it
} |
@dasilvacontin @dignifiedquire I understand there could be a function to set globals. I don't understand why making no globals the default option. Those who'd like to use globals can do it now without doing anything. Those who want to require: |
Because you are forced to have globals in the namespace with the current version, instead of being able to opt-in the global name space is already polluted as soon as mocha starts, even if I use |
@dignifiedquire I don't see anything bad in having a couple of globals for test environment. Pretty sure many people don't mind it as well. Perhaps we could consider an option to remove globals for those who're strongly against them: window.mocha.undeployGlobals = () => {
delete global.describe;
delete global.it
} From my observations there're way more people using globals for mocha than those who are not using them. My point is to try making it easier for the majority of existing users to migrate to the new version by trying not to change configuration defaults without a good reason. |
It could be an option in {
"interface": {
"bdd": true
}
}
// if "bdd": true, globals will be deployed |
Well, the 'mocha' way has always(?) been using globals, so I would put my bets on that statement too. It's only recently that we finally have It's wiser IMO to focus on having node-able tests – you can add 'globals-only' support easily. Whereas if you don't even consider having node-able tests, you are going to have trouble adding them later... which is the situation we found ourselves into. I picture this situation like someone trying to dig out sand from a hole while a sandstorm is going on. That's why a rewrite is being suggested – hacking on the current codebase won't lead to good code and it will take ages. So it's not very motivating, and motivation for maintainers is very important. Related: http://www.macwright.org/2014/03/11/tape-is-cool.html |
Leaving globals by default doesn't prevent one from writing node-able tests. Given mocha adds the support for node-able tests, one can use This way node-able tests are supported, the majority using globals will not have to add config options, and only those few who are somehow affected by globals will have to use the option (they must already have something in place anyway if they're affected in the current version - will just have to use the official option instead of whatever workaround they use now). Makes sense?
I understand, but the rewrite doesn't necessarily have to change certain previously established contract/defaults suitable for the majority of users. |
IMHO, for browser tests it seems reasonable to deploy globals by default, but for server-side node tests, deploying globals breaks CommonJS style making people confused a bit about environment they are developing their tests in. |
JFYI: jasmine spec runner for Node.js deploys globals always. Do people expect compatibility between mocha bdd style and jasmine? |
@ArtemGovorov I don't see any problem with globals for the test environment, personally, however some people do. I'd like to support those people by allowing Mocha tests to be run via |
To be clear, I'm not suggesting eliminating a global Perhaps that means the cli should still be within Mocha's core instead of a separate package (like |
@ArtemGovorov Please let me know if I haven't addressed your concerns. |
Not so hot on this idea. To recap, the idea is this:
|
I see the role of the
I'm thinking |
I do like the idea of a function call to populate the globals. |
I would like to eliminate This is a breaking change for sure, but also not unreasonable. It's a maintenance headache to have to manage the flags and two binaries, even if we have gotten better about it... |
Actually this isn't a bad idea, but it does mean running tests using |
there should also be better support for dynamic tests in the "new Mocha" |
This makes sense to me and addresses my concerns. Every group of users gets the most predictable and reasonable defaults.
Agreed. From what I'm observing, most of the people prefer globals in tests even with Browserify/Webpack. It's just faster than making Browserify/Webpack to compile your testing framework apart from everything else and easier than having to configure Browserify/Webpack to avoid the compilation. |
cc'ing @gotwarlost |
@ORESoftware what do you mean by this? If you have a specific use case or expected behavior, that'd be very helpful. Keep in mind we don't want to break existing tests. |
So with exports = mocha => {
mocha.option1();
mocha.option2();
...
}; It provides more flexibility, for example one could define |
@danielstjules that's true. It sucks. But I think the worst thing we could do is break thousands of tests which rely on this--major or no. |
Hmm. If the interfaces were all plugins in their own packages, we could simply version those. For mocha 3 we would retain the old BDD API. We could then develop the newer BDD API in unencumbered by Mocha. Users could install it if they wish. At the next major of Mocha it could become the default. Users could always fix their version of the BDD interface and still use the new major of Mocha. Is this sane? |
Also since I'm probably talking about a fair amount of individual packages, a monorepo might make sense for us. @sheerun does Bower play nice with monorepos? I'm worried about tags. |
@ArtemGovorov I prefer YAML over JSON. A I'd envision a |
@ORESoftware I'm unclear why you're talking about bugs in this issue. Please stop commenting in it unless you have anything helpful to offer. |
Indeed, that's the idea |
Randomization as a plugin using the API, I guess. |
As a comment on the idea of mocha being unopinionated: I think docker's approach has much merit: 'batteries included but removable' |
I'm unsure whether or not to push this code to branch |
@boneskull - what did you mean in the OP that Mocha can't leverage domains? are you referring to the domain core module and if so how do you mean that Mocha can't leverage them? |
They're not available in the browser, and the domain API is being deprecated. See nodejs/node#66 And something like nodejs/node-v0.x-archive#5243 wouldn't be quite as beneficial as we can't bind contexts to arbitrary functions within a test's function. |
What I meant was if your code under test is running in a domain and throws I see domain support as a necessary evil but it doesn't need to be part of Look at
|
This comment has been minimized.
This comment has been minimized.
nothing has happened here for quite a long time, so closing this, and we can readdress in another issue or discussion medium |
(..or maybe Mocha 4. I don't know.)
@mochajs/mocha + everyone,
I mentioned this in the mochajs/maintainers room on Gitter, but since it appears people aren't using Gitter much, I'll repeat it here:
Pitch
Mocha's old. What's cool about that is that we know what's wrong with it. And indeed, it has problems which make certain issues difficult to address. The major issue is "plugins". Others include (but are not limited to):
node
-ableIt's my opinion that any attempt to address these problems in an iterative fashion is a fool's errand. Components are too tightly coupled; each item above, if taken in the context of the current codebase, is a major undertaking. I propose we rewrite Mocha from scratch.
Plan
Mocha should made of plugins--all the way down. It should come with a default interface and a default reporter, but little else--Mocha's business is running tests and reporting the output. This is what it does well, and this is what the core should be.
From the current version of Mocha, we'd retain:
.mocharc
file(s) instead ofmocha.opts
. We would retain themocha.opts
functionality in a plugin; packagemocha-opts-plugin
, for example.--watch
, which should be handled by a plugin or another executable entirely.node
should be handled bynode
itself--either by executingmocha
withnode
, or usingnode
-able tests.mocha-cli
, as not everyone uses it.For libraries and tools which consume Mocha (I'm thinking stuff like JetBrains Mocha reporter, Wallaby.js,
mochify
,karma-mocha
, any Grunt/Gulp plugin which executes_mocha
), we must keep lines of communication open to ensure a smooth transition. Ideally, these tools should use the resulting programmatic interface instead of forking processes!We should supply a Yeoman generator for Mocha plugins, which would provide starting points and boilerplate for Browserify (since certain plugins will need to run in a browser).
Conclusion
If you guys are buying what I'm selling, I think the best thing to do is just start coding. The direction is clear, and the requirements are known. Let's create a prototype and take it from there. When the dust settles, we can address specific areas of concern, and begin to deprecate whatever needs deprecating. And start documenting. An upgrade to v3 shouldn't require the user to do much more than install an extra package or two.
cc @segrey @mantoni @ArtemGovorov @vojtajina @maksimr @dignifiedquire
The text was updated successfully, but these errors were encountered: