-
-
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
Broken IntelliJ integration when tests are running in parallel #4403
Comments
@boneskull What do you think about this issue? |
It's likely not going to work. The test objects are not the same; they are shallow copies and lack certain properties, as you see. To support yr use-case, IntelliJ would need to attach a reporter to the underlying worker process. This is currently not possible, but happy to discuss an API that'd make it work. |
Sure, let's discuss an API. Would be great to use the same API for both parallel and non-parallel runners. There is no such requirement that the test objects are the same. We just need a way to associate some data with a test object. For example, if a test object could provide an unique key (if different test objects reference the same test, the keys would be the same), that would work. |
the way the parallel mode works is that the main process uses the user's chosen reporter, but it has a special Runner. this Runner creates a pool of subprocesses, and those subprocesses run the tests. each subprocess uses fixed reporter ("buffered" reporter) that doesn't do anything other than aggregate events in memory. at the end of a test file run, the subprocess takes the events stored by the buffered reporter and sends them to the main process, which then emits the events to the user's reporter like usual. here are two approaches we could take to solve yr issue:
also cc |
@boneskull Sorry for the delay. Just tried it and it worked great! However, I've played a bit more with parallel mode and looks like I missed that the main process reporter receives events after the test file run has been finished. Unfortunately, it leads to the following UX problems:
Seems like the easiest way is to take the second approach and attach the reporter to worker processes. Well, when two tests from different worker processes would print messages to stdout, the messages would still be attached to wrong test, but probably this can be fixed in IntelliJ reporter if
Yes, a method on the Mocha instance look good. How can one fetch the Mocha instance? Up until now, IntelliJ consumes Mocha API via attaching a reporter. Maybe it's possible to attach the reporter to worker processes and deattach it from the main process in the reporter constructor? When running in parallel mode of course and do nothing when running in non-parallel mode. In this case, IntelliJ would still pass |
this means there will be many "currently running" tests, but you probably realize that. I think regarding the API, since the reporter only interfaces with a // parallel-reporter.js
class IntelliJParallelReporter {
constructor(parallelRunner, options = {}) {
parallelRunner.workerReporter(require.resolve('./worker-reporter.js'));
// whatever else is already there
}
} // worker-reporter.js
const ParallelBufferedReporter = require('mocha/lib/nodejs/reporters/parallel-buffered');
class IntelliJWorkerReporter extends ParallelBufferedReporter {
constructor(workerRunner, options = {}) {
// do stuff
}
} In the above, I'm assuming Also FYI: in serial mode, the first parameter to a reporter's constructor is a This will also necessitate making |
Yes, that's right. Thank you for the details! It sounds very good.
Yes, a single "main process" reporter is preferable, because IDE don't know exactly whether
Seems There is a thing. Since IntelliJ reporter doesn't depend on mocha in its package.json, it might not be able to access mocha's internal classes when BTW, IntelliJ reporter already tries to |
Yes, those modules should be public APIs (if they are not already--the reporter you mentioned is not but should be) |
rather sorry the parallel buffered reporter is not but should be. base should already be public |
@boneskull Hmm, sorry, I looked through mocha's code and couldn't find a way to access |
that should be in I've updated #4409 to include an I've also:
so in your 'main' reporter, use it sounds like you may want the ability to fiddle with the |
Ah, thanks a lot, missed that! How can I access Fixed IntelliJ reporters as you suggested and it's possible to run tests in parallel mode! Awesome!
It's needed to send
Yes, I subclassed it, but didn't override any methods.
So far it works good without any changes to stdio. I'll let you know if it is needed. |
@boneskull Sorry for bothering, any updates on this? Seems it's mostly fixed, at least it works for me locally with #4409. |
To get at The problem with exposing the
Suggestion: |
Thanks for the information. The problem with
Great, thanks! |
Mocha makes the assumption that a custom reporter will have a I want to be clear, though: I am not going to go out of my way to support Yarn 2 PNP, and won't consider Yarn's limitations when making design decisions in Mocha. You may have more luck with other Mocha maintainers, though 😄 that said, proposing a more ergonomic way of defining a reporter is definitely on my to-do list. ideally, you will not need to |
Thanks for clarifying, understandable.
For normal reporters that are declared in user's package.json, Regarding PR, thanks, looking forward to it! |
Prerequisites
faq
labelnode node_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
IntelliJ integration with Mocha is broken when tests are running with
--parallel
(https://youtrack.jetbrains.com/issue/WEB-46034).Steps to Reproduce
Open IntelliJ IDEA / WebStorm and run Mocha tests with
![image](https://user-images.githubusercontent.com/607109/89879217-458e0200-dbcb-11ea-971f-84741dcda4cf.png)
--parallel
added in "Extra Mocha options" in Mocha run/debug configuration.Expected behavior:
Test results are presented in UI correctly (as they are presented when running without
--parallel
).Actual behavior:
No test results. IntelliJ mocha reporter fails with exceptions like:
Reproduces how often: always
Versions
mocha --version
andnode node_modules/.bin/mocha --version
: 8.1.1node --version
: v14.4.0Additional Information
Found the following problems when debugging the issue:
test.parent.parent.(etc.)
.suite.root === true
test
objects. For example, 'test' and 'pass' callbacks get called with differenttest
objects for the same test. This makes it impossible to associate extra data with tests.Here is a small reporter reproducing these issues:
Here is expected and actual outputs when running the reporter with the following test data:
Expected (running without
--parallel
)Actual (running with
--parallel
)The difference:
'undefined' > 'foo3'
instead of'baz' > 'bar' > 'foo3'
'undefined' > 'foo'
instead of'foo'
started: false
instead ofstarted: true
The text was updated successfully, but these errors were encountered: