-
-
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
Add ability to run tests in a mocha instance multiple times #4234
Conversation
You're welcome 💁♂️ |
@boneskull the documentation website build failed because of an http error, not my doing. Please rerun that job if you can, thanks! |
I will be paying close attention to this PR, for now, it looks good! |
Huh, I am not sure how to re-deploy this on netlify. I don't see the option. |
* Implements listenerCount for 'uncaughtException'. | ||
*/ | ||
|
||
process.listenerCount = function(name) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: this is an observation and not a request for changes.
I don't love how process
is shimmed here. we might be able to get away with changing the prototype to the EventEmitter
shim (loaded via browserify via events, because process
should be an EventEmitter
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I was surprised that that wasn't yet the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, great work here! good tests too.
I have a couple concerns which I've commented on, but overall looks excellent. If you're unable to do further work on it, I think it could land as-is, and I could take care of those myself later. I'd like to see if #4245 can consume it.
lib/suite.js
Outdated
}); | ||
this.tests.forEach(function(test) { | ||
test.reset(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what of hooks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure I know what you mean with hooks, but I think it is beforeEach
and friends.
I super duper don't want them to be cleaned. They should stay, just like the test fn's themselves. We're going to need them for the next run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, hooks are beforeEach
etc. I think I am confused about why suites and tests are getting reset()
called, but not hooks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be clear: I'm still confused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I now understand your criticism. Hooks have state as well. And they inherit from Runnable
. Didn't realize. Will add it when I have some time. Thanks for pointing it out!
test/integration/fixtures/multiple-runs/multiple-runs-different-output.fixture.js
Outdated
Show resolved
Hide resolved
I've implemented (most of) the requested changes. I've also added one last bit. When disposed of, a Mocha instance will now unload files internally. That makes a lot of sense to me. If someone wants to create a new mocha instance in the same process and add the same files again, he should be able to. |
ty for the update. looks like there's a conflict. |
Conflict has gone 🤸♂️ |
@nicojs there's another conflict 😜 |
You're a busy guy. Fixed once more 🤸♂️ |
You're quite good at keeping me busy 🙊 I've implemented the reset on hooks. I saw that As far as I know, I've fixed all issues/recommendations. |
lib/errors.js
Outdated
default: | ||
throw new Error('unknown pluginType "' + pluginType + '"'); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You seem to have missed a closing bracket.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, fixed now. Did a merge in the browser 🤷♂️
Fixed now. I'm hoping you guys do squash commit? If not, I could do it as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, will squash.
@boneskull can you take a look if it is good to go? 🚀 |
Seems to be yet another conflict. |
I would like to call this a "bugfix", since it really always should have worked properly. But I could see how others may consider this a feature. Thoughts, @mochajs/core? EDIT: either way, this shouldn't be breaking. |
1e28dea
to
70f4554
Compare
Something's gone wonky with the changesets here. I tried to rebase back onto @nicojs Sorry, I tried to help. You'll need to pull your branch again from your fork, and pull |
It looks as if there are changesets in here that shouldn't be in here; @nicojs I'll give you a chance, but please let me know if you want me to give it another go. I may have screwed it up myself! Might even be best to not pull your branch back down, and instead just retry a rebase onto |
Rename since we cannot dispose the entire mocha instance after a test run. We should keep the process.on('uncaughtException') handlers in place in order to not break existing functionality.
Will give @juergba 48h to look at this; if he declines to review I'll merge it |
This is one of those "missing features" that is only a bug because it was missing. 😄 |
True. To be fair, I think we same problem in Stryker itself. Creating an instance of |
So... I guess this will be merged soon 🤗 |
yes |
So it looks like I can't actually use this for the parallel runner. What I had hoped to do is re-use the same Mocha instance... except with different files (specifically, a single file) on every run. @nicojs What I'm trying to do is:
I attempted to "reset" by calling Mocha instance is already disposed, cannot start a new test run. Please create a new mocha instance. Be sure to set disable `cleanReferencesAfterRun` when you want to reuse the same mocha instance for multiple test runs Of course, if I don't call Why can't I reuse the |
Should I just not call |
(I suppose I'm rubbber-ducking now...) |
I think, maybe, that it wasn't the problem you were trying to solve. but it seems to get most of the way there. |
OK, so, I am thinking it's really not worth the bother to try to reuse anyway, thanks for the PR 😄 |
Yeah, it wasn't the problem I was trying to solve. The reason I added the behavior of throwing an error on run after dispose was just because thought that made the most sense. Feel free to change that behavior, no harm done since it wasn't released yet, right? As long as I can run the exact same suite without reloading files, I'm happy ;) |
…loses #2783 * Add ability to run tests in a mocha instance multiple times * Rename `autoDispsoe` to `cleanReferencesAfterRun`, Rename since we cannot dispose the entire mocha instance after a test run. We should keep the process.on('uncaughtException') handlers in place in order to not break existing functionality. * Allow `unloadFiles` to reset `referencesCleaned`. * Complete rename of _cleanReferencesAfterRun * Add integration test for running a suite multiple times * improve api docs * Docs: fix dead link * Make sure tests run on older node versions * Remove `.only` 😅 * Implement `process.listenerCount` in the browser * Implement mocha states in a finite state machine * Fix some small remarks * Make integration tests more damp * Keep `Runner` api backward compatible * Unload files when disposed * Runnable.reset should also reset `err` and `state` * Also reset hooks Co-authored-by: Christopher Hiller <[email protected]>
This appears to cause breakage for me: I haven't had a chance to debug why yet. Any tips would be appreciated. |
Fix issue with ability run tests in multiple times mochajs/mocha#4234
Fix issue with ability run tests in multiple times mochajs/mocha#4234
@birtles Please could you submit this bug as a new issue? Please include details of versions as well as how you are calling mocha. Thanks |
Hi. I went to submit a bug but the bug form was requiring a little bit more time than I can currently afford, unfortunately. I discovered that dropping a call to For what it's worth, I'm running with |
i updated the thread #2314 and I found out that there must be a bug in the options parser.
|
Description of the Change
These changes allow mocha to run multiple times with the same test suite programmatically (without reload). It does this with minimal code changes.
It also adds to validations, for when people call
mocha.run
at the wrong time.For more details and reasoning, please see #2783 (comment)
Fixes #2783
Alternate Designs
Alternatively, we could have totally removed all state from tests, suites and runnable, but we don't want to change the entire way of keeping state. Please see #2783 for the entire history.
Why should this be in core?
A lot of people seem interested in running a test suite multiple times without reloading files from disk. See #2783. I personally will use it to implement mutation switching in Stryker
Benefits
Huge performance gain for my mutation testing use case. Other people have valid use cases as well.
Possible Drawbacks
It should be backward compatible, but since I had to rewrite parts in the core, I might have introduced undesired side effects 🤷♂️. Although the integration test suite is awesome!
Applicable issues
#2783
Todo:
reset
reset
reset
dispose
andcleanReferencesAfterRun
run
call is invalid.dispose
andcleanReferencesAfterRun