-
-
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
Root hooks not executed when programmatically running Mocha in serial mode #5006
Comments
Huh, what an odd little discrepancy! Thanks for filing. This sounds reasonable to consider a straightforward bug to be fixed. For quick use, I copy & pasted the OP's files into a repro here: https://github.com/JoshuaKGoldberg/repros/tree/mocha-api-not-respecting-root-hook-beforeAll. |
hi @JoshuaKGoldberg, would this be a good first issue for somebody looking to make their first open source contribution? |
Hmm, I suspect not. It involves parallel stuff and parts of Mocha that most users don't touch. You can certainly try it but I'd be worried about getting into really deep things. We have a separate Thanks for asking though! 🙌 |
@JoshuaKGoldberg challenge accepted |
hi @JoshuaKGoldberg, the API documentation states that the Changing the way the Mocha object is invoked by using the What should the underlying fix for this issue be? I was thinking of pulling in the underlying hooks from the path in |
...heck if I know! 😄 #5027 - we're finishing up triaging existing issues and haven't yet started reviewing PRs in earnest. So we're not yet at the place where we can give advice like this. None of us have looked closely enough at the code to be able to be coherent in trying to ask questions like that. It sounds like you're on the right track (yay! nicely done!) in general. But this is why I was not super enthusiastic in #5006 (comment). We can't really give you great support for this just yet. |
no worries at all. I'll take a stab at the most straightforward approach, just trying to mirror the behavior of the CLI |
Unfortunately wasn't able to come up with a solution that passed the unit and integration tests :( I think the helper function |
Hi, do you guys have any update on this bug? |
Prerequisites
faq
labelnode_modules/.bin/mocha --version
(Local) andmocha --version
(Global). We recommend that you not install Mocha globally.Description
Hey team!
When running tests programmatically (using
new Mocha
), the root hooks provided inrequire
are not executed if parallel is not set/set to false.This is a discrepancy with the CLI method of invoking tests that correctly interprets the
require
flags and consume them before running the test suites.Steps to Reproduce
index.js
test.js
root-hook.js
Expected behavior: Similar behavior as the CLI:
Actual behavior: The root hooks logging "before all" is not being executed
Reproduces how often: 100%
Versions
mocha --version
andnode_modules/.bin/mocha --version
: 10.2.0 (reproduced in 9.x as well)node --version
: v14.21.3Additional Information
I assume the discrepancy comes from
lib/cli/run.js
(cli runner) andlib/nodejs/worker.js
(worker thread logic) executinghandleRequires
while the barerunner.js
does not.The text was updated successfully, but these errors were encountered: