-
-
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
🐛 Bug: Mocha throws error if it is running a spec more than once #2706
Comments
Do you have an example of what necessitated multiple programatic runs of mocha? |
I have the same issue: We haven't tested this feature from long time but realized today that it is broken and we get same error as @crishushu mentioned. Please confirm if Mocha supports repeating tests which can be controlled as an argument? thanks |
It is really hard to judge what this could be without a code example, including a setup. Out of curiosity have you looked https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically ? The wiki describes that the run method returns a Runnable, which might help you debug. For example: try running your second test after the first has completed and see if that helps:
I am not sure what you mean here, could you elaborate? |
I meant the retry feature: thanks |
Here is another example of someone raising the issue: adamgruber/mochawesome#79, Look at last comment: Please note: this error happens in mochawesome but caused by this issue in Mocha inside, i tested by reproducing below issue and then remove mochawesome and then i find current issue.
|
Using 3.2.0 as well * edit: same behavior with 3.1.2 The error seems to occur on the first line of code on the second time the file is run because I cannot get anything including logs. There are no problems or errors when I attempt to run only 1 version (so one run of the tests). I thought maybe if I didn't use addFile multiple times that would work, but it did not make a difference. Just a guess, I was wondering if the test is being cached like a require then would it need to be "unregistered" so it can be run again with new information? Here is a brief output from my tests: 1 passing (12s)
|
@tgirishkumar thank you for clarifying. I have never used mocha for React tests, nor have had a need for using retries on failed tests. I have generally setup tests to always run in one command ( It is possible mocha is relying on something in the global state or loading setup multiple times. Hard to trace without a reproducible unit test / stack trace. Maybe with @elevow and @crishushu we can create a reproducible small unit test, track down the issue, and then submit a PR for the mocha team. They mentioned on their site that they are in dire need of help maintaining the project 😄 |
Yesterday I was playing with different versions of mocha. AFAIK the latest release where running mocha with same suite/spec setting multiple times is supported, is 2.3.0. @dennisbaskin just out of curiosity is there any reason why the feature (yes, I consider it as one) has been disabled. I assume that it happened deliberately. |
I was able to make a small version of the failure. Hopefully someone can duplicate it. one.test.js is just a it statement with console.log();
TypeError: Cannot read property 'call' of undefined edit: I tried moving the addFile command inside and outside of the eachLimit and both give the failure |
Hey after some testing the issue seems to be specific to async.eachLimit for me. |
@crishushu I would not able to answer your question as to why. I am not directly involved on the contributing team, just trying to help triage issu.es since they need help. @elevow I will try to play around with your example, thanks for setting that up. |
Guys, any update on this? |
I have same problem. I just tried to set up mocha programmatically and have just one test is I load one test file then i run the tests.
First time it runs fine, after 5s it throws me an error. This is the full error stack |
I think you should have a look at grunt-loop-mocha. I use it for my Selenium WebDriver tests. https://github.com/grawk/grunt-loop-mocha My understanding is that mocha is a unit testing framework and so it creates only one instance/process of your tests. So, when you try to execute the same test, it does not execute before and after statements. Grunt-loop-mocha on other hand helps you create the new instance for each specification. So, it will even execute before and after statements with the different configuration. I guess that's what you are looking for. |
+1
got this error
my test
I'm running in a docker environment with node 8.5.0 |
This worked for me, if anyone is still looking for a solution
|
I am seeing this issue too using Mocha 5.2.0 - here is my stacktrace:
I am writing a library where I want to compare the output to console of a reporter based with and without my library .. which is why I need to be able to re-run the same test twice, programatically. When inspecting the It looks like a I ultimately gave up and just reinstantiated the mocha instance between runs - remembering to clear node.js require cache ( |
I clean the require cache up by using the clear-require component, |
The current codebase needs |
Related: #1938 |
taken from https://cdnjs.com/libraries/mocha
The text was updated successfully, but these errors were encountered: