-
-
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: Watch + mochaHooks inconsistent state on re-runs #5149
Comments
Fantastic investigation, thanks! I've gone through the (very helpful!) reproduction and confirmed the bug. +1 that only clearing some of the file cache is a root cause bug. Unfortunately, I think that fixing the behavior by clearing more of the cache would be considered a cc @mochajs/maintenance-crew for a second or third opinion, just to be safe. |
Thanks for checking it out! Bug fixed, now doing a full blast, and no problem in considering it a major due to potential breakages 👍 |
Thanks for the investigation. We are also running into this problem. This has helped us as a workaround. |
- Added node script to add terminal aliases (helps to easily run test groups) - Integrated mocha watch - Removed redundant sh helper scripts - See mochajs/mocha#5149 --------- Co-authored-by: Arya <90748009+aryamohanan@users.noreply.github.com>
Bug Report Checklist
faq
label, but none matched my issue.Expected
Mocha's watch mode should produce the same results on all runs, if the code does not change significantly (e.g. triggered by adding a new line.). Using
mochaHooks
that mutate globals and modules/requires should be consistent in all runs.Actual
Mocha's watch mode seems to not work the same on reloads regarding
mochaHooks
as in the 1st run.Having a
beforeEach()
thatrequire
s a fil, and which we mutate state of in that hook, when a test that relies on that mutated state runs, first time is ok, but subsequent "watch runs" fail.First run is ok, but then any irrelevant change on a watched file:
Minimal, Reproducible Example
I created a small repro repo, keeping it similar to my source: https://github.com/Kartones/mocha-hooks-watcher-bug
Includes a README with steps to reproduce, but adding here a minimal TL;DR:
given:
And a hook that mutates it:
The hook is correctly executed before each test, but
a
seems to be kept at the initial state (with_items=[]
, instead of_items=["testItem1", "testItem2"]
)Versions
Mocha: 10.4.0
NodeJS: v20.11.1
pnpm (not strictly relevant): pnpm@8.15.3
Additional Info
UPDATED: Taking a look, will provide a PR with one solution.
The text was updated successfully, but these errors were encountered: