-
-
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
🚀 Feature: Add events to be fired on block and test completions #1860
Comments
I think the recommended way is to listen to the Doing so will keep your reporter consistent with mocha's own reporters. |
Well I do so, but it is surprising that sometimes I can receive two pass/fail events for one testcase |
Have you seen that in a lot of different situations? Off the top of my head: $ cat test.js
it('test', function(done) {
setTimeout(done, 10);
setTimeout(done, 20);
});
it('test2', function(done) {
setTimeout(done, 100);
});
$ mocha test.js
✓ test
1) test
✓ test2 (106ms)
2 passing (130ms)
1 failing
1) test:
Error: done() called multiple times
at Object.<anonymous> (test.js:1:63)
at Array.forEach (native)
at node.js:868:3 |
I ran that tests with xunit reporter and got following <testsuite name="Mocha Tests" tests="2" failures="1" errors="1" skipped="-1" timestamp="Mon, 14 Sep 2015 17:58:02 GMT"
time="0.125">
<testcase classname="" name="test" time="0.014">
<failure><![CDATA[done() called multiple times
Error: done() called multiple times
at Object.<anonymous> (test.js:1:63)
at Array.forEach (native)
at node.js:814:3]]></failure>
</testcase>
<testcase classname="" name="test" time="0.014">
<failure><![CDATA[done() called multiple times
Error: done() called multiple times
at Object.<anonymous> (test.js:1:63)
at Array.forEach (native)
at node.js:814:3]]></failure>
</testcase>
<testcase classname="" name="test2" time="0.106"/>
</testsuite> This report is weird. Here is a negative I am trying to avoid this weirdness in my reporter, but I am not sure that is my issue rather than test runner itself. |
+1, same issue
For WebStorm mocha integration it caused attaching stdout printed in |
I know it's been a while, but is there any plan to address the issue of having the I have some cleanup work in the afterEach() hook that i'd like to access after the test finishes execution. |
None. Those events are test-related (i.e., whether
Can you provide an example of why your cleanup would require further event handling? |
@plroebuck Sure thing! In the afterEach() hook, I will do a couple different things:
I can't do this in each individual test because if an assertion fails, then obviously an assertion exception is thrown and I have nothing to catch that. And I'd prefer not to do that in the test as well since that would result in a lot of code duplication. And if I just listen to the Looking at other test frameworks like NUnit, their That being said, I did find a work around for my scenario where I'm listening to the |
Another work around is to call mocha.suite.afterEach to add your own after each. if it’s done after all files are added then it will run after any user after’s. |
Sounds like #1860 (comment) is an appropriate workaround for this feature gap? I'm not 100% confident this issue actually is resolved by that - but it's been a couple years and not that many people have interacted here. Marking as closed for now. If someone still would like to add more events, great! Please do file a new issue that says specifically what events you'd like to add. For reference, the event string constants in source code are here: Line 48 in b7b849b
|
I expected that reporter lives as a separate layer and does not mess with tests flow. But if you are saying this is the way reporters should work, ok by me ¯_(ツ)_/¯ |
I write my own reporter and I am wondering how to detect end of testcase.
I tried to listen event
test end
, but according to source codeafterEach
hooks are invoked after this event. It affects me, because I want to know time of whole test execution, including teardown actions. Also afterEach, can emit afail
event and it a bit unexpected, because a test already report about its finish.Moreover,
test
event is emitted beforebeforeEach
hooks invocation.What about extra event
afterEach end
which will be fired afterafterEach
hooks invocation?The text was updated successfully, but these errors were encountered: