-
-
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
--watch option works strangely with .only()
#2429
Comments
Looks like is related to #2327 |
Same problem here, glad its already reported. |
Would accept a PR to fix this if it's not too complicated. We don't really have the resources to maintain Suggested workaround: use a third-party package to watch files and re-execute |
I don't have enough knowledge of mocha internal to fix this problem, but I want to share what I have checked. I changed bin/_mocha as followed to check runner's state. // https://github.com/mochajs/mocha/blob/master/bin/_mocha
// line: 355
function loadAndRun() {
try {
mocha.files = files;
runAgain = false;
runner = mocha.run(function(){
runner = null;
if (runAgain) {
rerun();
}
});
// ADDED for testing
console.log('in loadAndRun():', runner.total);
} catch(e) {
console.log(e.stack);
}
} When I run test with mocha 2.5.3, I think |
@boneskull About 3rd party tools you're suggesting. Can you please point me some tool which might work with mocha.opts? Because all examples i see on the internet imply using some task runners like gulp-mocha which do not accept mocha.opts. |
@dobryanskyy Maybe |
@boneskull you don't have the resources to maintain watch, yet you update the rest of mocha without removing it? i'd rather remove a neglected feature when it's broken than leave it as is. edit: will see if i find the time to have a look at it later on |
@gurdiga thanks a lot, |
However, it's a bit slower than using |
mocha 3.0 problem with .only and --watch (mochajs/mocha#2429)
I've just run into this as well, but I'm using Mocha's api programmatically, so this issue is not limited only to the In my case I've written a little test runner script that uses Mocha's api specifically to work around problems with In looking through the codebase, I noticed A fix here may be to initialize |
I suspect that some of the issues experienced with I guess the question is whether running tests multiple times in the same process is something that should be supported by the api. Sane file watch functionality is a prime example where this is useful. The suggestion given to replace |
@bartels I also noticed that I just wonder if we should fix the |
@davidspinat Your pull request does seem like the best way to fix this. I'm testing it out and seems to work well in my case. Might be good for @boneskull to take a look too. I'm not all that familiar with mocha internals. Looking at this a bit more, your pull request seems to have removed the need for setting I tried removing all instances of |
Whether that particular PR makes the cut or not, let's make sure we get one source of truth on |
@bartels @ScottFreeCode thank you for having a look. @bartels I agree that it would make most sense to just remove the @ScottFreeCode from my point of view these kind of states are very hard to maintain and should be avoided. However I tried to evaluate the situation and agree, that Should I extend #2544 to also remove all related |
I have no strong opinions one way or the other on separating the fix into immediate and underlying/architecture phases, or into "eliminate use of That being said, ideally if we could both fix the immediate issue and set up some kind of test for it so we know if the issue comes back (preferably using the programmatic API in a manner similar to *The more tests we get using the programmatic API, especially for |
I've also written a tool that uses mocha programmatically and I also faced similar issues. I ended up doing |
If d22cae8 fixes this, I would love to see this merged! |
(mochajs#2544) * Fix .only() behaviour when running with watch option * Remove all occurrences of the hasOnly property
After adding
.only()
and removing it,--watch
doesn't work correctly. After removing.only
from a test case, I expectedmocha
should test all test cases, but it did not test any case at all.steps to reproduce
mocha test.js --watch
with following code..only
to the first test..only
from the first test.Expected Behavior
After removing
.only
, all tests should be tested again.Environmet
The text was updated successfully, but these errors were encountered: