-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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 |
PR Checklist
status: accepting prs
Overview
Turn off
ignoreInitial
and distinguish between initial'add'
events and paths added after test startup. We can compare themtime
of the path to the test startup time to decide if the change should trigger a rerun.