-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix: begin running tests immediately instead of waiting for watcher #5409
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
base: main
Are you sure you want to change the base?
Conversation
|
@mark-wiemer is using Also, let me know if you have any opinions about if/how I should test this change. It would be nice if I could inject some kind of chokidar mock so I can control timing of the file events to be able to verify in a test that it runs before the ready event is emitted...but the only easy way I think of to do that would be to call things in |
lib/cli/watch-run.js
Outdated
| }); | ||
|
|
||
| (async () => { | ||
| if (!globalFixtureContext) { |
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.
The earlier versions of Mocha using Chokidar 3 still waited until watcher.on('ready') to call mocha.runGlobalSetup(), but I'm not sure why. A quick look at the code isn't too revealing, but I see why we'd want to call this right away. I'm curious if we can add a test case that has a complex global setup to ensure things still work?
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 exactly familiar with what that global setup is (loading required modules?) but I can try to figure out what goes into it
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.
Okay Chokidar doesn't seem to specify whether 'change'/'unlink' events can get emitted before 'ready' if changes occur during its initial scan, but if so, it could cause the preexisting code here to start running tests before it's performed global setup.
Obviously the intention of the preexisting code is to wait for the 'ready' event to run everything for the first time (first global setup, then the first test run).
I've fixed this in my PR now, if it gets an event before the global fixture context has been created it won't schedule a rerun.
(I still need to write tests for this)
|
Marking as draft until tests are added |
f8a4eca to
368d7c0
Compare
|
@mark-wiemer I want to run some changes by you before I dive into them... I realized that Also...
|
|
Hey @jedwards1211, the current glob code is not ideal for sure for exactly the reasons you mentioned and probably more. The best discussion around this is #5379 and in short we don't want to touch this code until v12. We as maintainers don't have a ton of experience with glob matching and don't want to break anything, but we do want to keep Chokidar at v4. Mocha 11.2.1 used Chokidar v3, we upgraded to v4 in Mocha 11.2.2, but Chokidar v4 dropped glob support so we had to use our own. Learning more about globs is definitely a priority, but I'm still getting the ropes on the rest of Mocha as a new maintainer, so I won't have a ton of updates here. In short, feel free to update or change or even rewrite the glob handling. Just keep #5379 in mind as another alternative and add as many tests as you can to help me and other maintainers verify any changes :) |
|
Yeah I kind of thought about doing the same thing as that PR. One question is how to change Instead we would have to delete all |
|
I wouldn't worry about performance too much in the abstract. We had a concrete issue with #5374 that has effectively been resolved with #5379, and in practice I can't imagine folks are using many regexes for watch paths. If we get a bug report about perf, we can look into it, but as long as our basic stress tests pass, I'd prefer simpler changes first. On another note, @mochajs/maintenance-crew I'm thinking of marking this as "semver-major" given the complexity impacted and possibility of bugs. Since we want Mocha 12 to have minimal changes we'll probably hold this one for Mocha 13. (#5357) |
|
Okay I guess I'll eventually piggyback this on #5379 and blast the cache with the new filtering from that PR. Also, I'm not sure what to do about getting the launch time to compare file mtimes to. Date etc could get monkeypatched by test utils like Sinin fake timers... do you have any thoughts? I guess it won't get monkeypatched before we run global setup though. But I got an ESLint error about using Date, it must be for good reason. |
|
I'm not sure why our linter warns about using Date. Could you see if that's a recommended rule? There's a real chance that our linter is very out of date. We've had some discussions about it but haven't prioritized updates there for a while. |
|
@mark-wiemer looks like the rule was explicitly added to guard against exactly the danger of fake timers I was talking about: #237 (This issue is explicitly linked in your ESLint config) Note, it would probably be possible to grab a reference to the original As I was saying though, in this case I only need to get the launch date before running any global setup where userland code might monkeypatch |
|
Thanks for researching. The core concern still applies, but I think the workaround does too: just have |
|
👋 Just checking in @jedwards1211, are you waiting on us for anything? |
|
No, I'll pick this back up soon now that that related PR is merged |
f7b12be to
527741b
Compare
527741b to
f99c91e
Compare
|
@mark-wiemer okay, to test timing-sensitive cases, I used an IPC channel to send mock |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5409 +/- ##
==========================================
+ Coverage 93.69% 93.70% +0.01%
==========================================
Files 57 57
Lines 4396 4419 +23
Branches 849 860 +11
==========================================
+ Hits 4119 4141 +22
- Misses 277 278 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@jedwards1211 new tests are frequently timing out, do you think we can refactor them to complete in under 10 seconds? |
|
@mark-wiemer huh, there may be a race condition causing the new tests to time out, I'll see what I can figure out. Theoretically they should run especially quickly since they aren't designed to rely on any arbitrary delays. (Many of the watch tests do use delays of a second or so, which makes running the entire watch test suite quite slow). |
57b83be to
e591466
Compare
|
@mark-wiemer is there a way I can run CI with SSH to debug if the tests keep timing out? It's not happening to me locally |
|
oh I think I know what was causing the timeouts, they were probably sometimes missing the initial |
|
@jedwards1211 seems the tests are consistently failing on Windows, are you able to look into it? |
|
Yup, I will tomorrow |
|
@mark-wiemer is there a way I can run the Windows CI tests with SSH? I can't reproduce locally on a Windows machine. It seems to be some issue with IPC on Windows CI, but I'll need to either SSH into the tests or turn on some kind of debug logging to figure it out. |
|
I'm going to re-run the tests just to make sure this wasn't some weird fluke. And if they fail again, I'll try to repro from Windows on my side. I'll note that you can run the tests locally with the DEBUG flag on (ref #5538) , but if you can't repro, I understand those debug logs don't mean much. Ref https://github.com/mochajs/mocha/actions/runs/19623994930 for test run |
|
@mark-wiemer okay I temporarily turned on more debug logging in these tests, hopefully that will help me figure out what's going on in Windows CI |
|
@mark-wiemer lol, the Windows issue is that In the new watch tests I'm I changed the I guess I should also confirm that if Chokdiar is watching the contents of Also -- I think all |
|
Okay this stuff about Windows short names is really aggravating. Here's what I've discovered...
I guess leaving the |
PR Checklist
status: accepting prsOverview
Turn off
ignoreInitialand distinguish between initial'add'events and paths added after test startup. We can compare themtimeof the path to the test startup time to decide if the change should trigger a rerun.