-
-
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
describe.only runs multiple unrelated tests #1060
Comments
I've noticed this also happens if the name in test2 is not the same but still includes the name in test1 (e.g. test1 is "Test" and test2 is "AnotherTest", test2 will still be run). |
yeah it's a bit of a hack right now, it uses .grep() internally, one could argue you shouldn't name the same but yea it's definitely a gotcha |
Yeah, I intentionally never have two tests with the same name. I often copy&paste unit tests to use it as a template for new module's. And sometimes I forget to rename the unit test. This is why I found this bug :) However, in large projects this problem may occur more easily. |
I am new to Mocha. so ignore if something i say that doesnot make sense and I am coming from TestNG world. the way .only works is, for a given file, it skips all other tests and run the test marked describe.only. |
Currently, when I use In the Mocha doc, |
okay, got it. Thanks for the clarification |
This is actually worse than just the exact same name; grep does a substring match, so |
sometimes it's nice, and sometimes it isn't. |
Oh . So it's this what is happenning.It was driving me crazy! At least i know how to avoid now |
If anyone has a convincing reason why this behavior should be changed, please let me know--I can see it being used effectively either way. |
I have. For example i have two files one has the file A.js and the other B.js. All tests Inside B bellow that point are running. |
Not in your use case, no. This even suggests to me there's something hinky about the grep implementation. However I can envision people actually wanting behavior like that. If we're gonna break the API, we should probably keep the current So, any PR will not be merged very soon. PR #1445, if that gets in, may alleviate some of the issues here. |
Someone should fix this instead of these endless talks about an obvious bug. Will do it myself if I get a bit of time this week. The easiest fix is to just run the first .only occurence and ignore the others, right? |
Not sure what the fix is. You can rush to fix it but it will necessitate a major release. |
From my perspective, I mean whatever the naming is, I am most wondering what people think |
Sure, it's weird and probably erroneous, but it's been around so long that it's probably going to break something for somebody. |
Finally figured out why my test is running. It gets the full name of the describe and performs a grep on each test. So describe.only('Applicant Consolidation') greps the string 'CompanyApplicant '+'Consolidation' of the other test. So not only on each describe it is an issue, but on all nested describe combinations. I agree with @boneskull on the fact that if it's going on for a while somebody may be relying on it. But since is more of an undocumented behaviour i don't think that it would enter on a Backward compatibility break. |
how .only works shouldn't be affected by the name imo. if someone made a pr fixing this that'd be great. |
Not sure if fixing this 'bug' will break anybody's code. |
People push Anyway if @travisjeffery doesn't want to keep the current behavior in some manner then that's fine. Reading over the docs it doesn't appear that grep-like behavior was necessarily intended. I'm not eager to merge this into a patch or minor release, just because of some of the changes we thought were "non-breaking" caused a shitstorm. |
This substring matching is a pain in the rear for us as well. When we mark describe as |
+1, I think this issue is sabotaging my tests right now as well. |
+1 this is really needs fixing. I would consider this a bug fix, the documented behaviour is:
I don't think prioritising upsetting someone relying on a bug over everyone else expecting documented behaviour is a good reason to not patch it. |
if @mochajs/mocha can agree it's a bug, then it could go into a minor |
@boneskull rather than discuss that (although I could be convinced to go put it in a minor [that sounds worrying]), how about we change #1782 to become a release of v3.0.0 in stead, merge #1632 and #1481 asap, lift the rest of milestone V3.0.0 to the next major release and ship v3.0.0? :) |
Because Mocha internally uses grepping in .only(), that takes the other suites which all have 'model' in their names. mochajs/mocha#1060
This has bitten me multiple times and kind of stinks. Is there a better way we could do preprocessing of all .only() and build out a tree? The desired behavior is such that I can mark a 'top level' suite with only, then as I work through sub-level describes I can attach another only without having to remove the top-level marker. |
This issue is causing problems for me because I want to describe my tests in a hierarchical structure like below, but then it is not possible to run one suite exclusively.
|
@PerlPong Why not restructure the specs to be something like this: context('components', function () {
describe('Form', function () {...});
describe('FormField', function () {...});
describe('FormControls', function () {...});
}); |
@demisx thanks for the tip, but unfortunately it does not work around this bug. If you execute the following with mocha, both suites will run: var expect = require('chai').expect;
context('components', function() {
describe.only('Form', function() {
it('should be true', function () {
expect(true).to.be.true;
});
});
describe('FormField', function() {
it('should be false', function () {
expect(false).to.be.false;
});
});
});
|
@PerlPong I see. Yeah, I believe if the spec |
With Mocha, two identically named blocks will both run if you put `.only` on both. mochajs/mocha#1060
When multiple unit tests have same name in
describe
, mocha ignores the.only
setting.Steps to reproduce:
mocha test1.js test2.js -R spec
test1.js
test2.js
The text was updated successfully, but these errors were encountered: