Skip to content
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

fix: Updating spec watcher to detect directory events #20962

Merged
merged 12 commits into from
Apr 11, 2022

Conversation

tbiethman
Copy link
Contributor

We use chokidar to detect changes to a project's filesystem and reflect changes to specs (new specs / removed specs) in the Cypress app. However, chokidar will not emit file add events for files that are added alongside a new directory; the converse is also true for removed file events during the removal of a parent directory. We are also limiting what we watch to files that match the spec pattern; however, that does not include directories that may be a partial match.

I updated the chokidar watcher to listen for changes more broadly. I also updated the debounce duration on our handler so that sequential filesystem events do not trigger our spec detection more often than necessary (it was defaulting to a debounce timeout of 0 previously).

User facing changelog

  • The spec watcher has been updated to detect directory changes to the project filesystem. It will now detect specs added within new directories and removed alongside parent directories and update the UI appropriately.

Additional details

How has the user experience changed?

PR Tasks

  • Have tests been added/updated?
  • Has the original issue (or this PR, if no issue exists) been tagged with a release in ZenHub? (user-facing changes only)
  • Has a PR for user-facing changes been opened in cypress-documentation?
  • Have API changes been updated in the type definitions?
  • Have new configuration options been added to the cypress.schema.json?

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 7, 2022

Thanks for taking the time to open a PR!

@cypress
Copy link

cypress bot commented Apr 7, 2022



Test summary

17832 0 218 0Flakiness 0


Run details

Project cypress
Status Passed
Commit f28308e
Started Apr 11, 2022 11:53 AM
Ended Apr 11, 2022 12:04 PM
Duration 11:27 💡
OS Linux Debian - 10.10
Browser Multiple

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@tbiethman tbiethman requested a review from ZachJW34 April 7, 2022 15:21
@tbiethman tbiethman self-assigned this Apr 7, 2022
// We respond to all changes to the project's filesystem when
// files or directories are added and removed that are not explicitly
// ignored by config
this._specWatcher = chokidar.watch('.', {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In 9.x we had integration/component folders defined in config to better scope what we're watching, but no longer. I still worry that this may be too broad/expensive, but debouncing the handler will limit the amount of thrash that can result. We could add more explicit ignored dirs (node_modules)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So are we saying that providing the specPattern here definitely does not work properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my testing, yes, it does not work correctly when files are introduced with or removed alongside parent directories. No 'add'/'unlink' events for those files get emitted in that case. This could very well be a bug within chokidar, I need to dig into its implementation more fully to figure out why it's behaving this way.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, it looks like chokidar v4 is dropping globbing entirely: paulmillr/chokidar#1195, so this might be the best approach, to watch the directory and handle matching on our side.

Copy link
Contributor

@rachelruderman rachelruderman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are very clean & easy to follow, thank you! I don't know enough about Cypress to understand the effects of more broadly watching file changes, so I will leave that part of the review up to others :)

…ce duration to match develop. Explicitly ignoring node_modules for watcher.
Copy link
Member

@tgriesser tgriesser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, as I mentioned I think we'd gain a lot by cleaning up the spec management layer in general but getting it working & tested is a great first step!

@tgriesser tgriesser merged commit 24808dc into 10.0-release Apr 11, 2022
@tgriesser tgriesser deleted the tbiethman/UNIFY-1221-spec-watcher branch April 11, 2022 12:23
tgriesser added a commit that referenced this pull request Apr 11, 2022
* 10.0-release:
  fix: Updating spec watcher to detect directory events (#20962)
  chore(launchpad): fix launchpad e2e tests on windows
  refactor: allow ts-node to be scoped (#20786)
tgriesser added a commit that referenced this pull request Apr 11, 2022
…1206-cloud

* tgriesser/fix/UNIFY-1206-git:
  add ensureDir
  fix test
  fix: Updating spec watcher to detect directory events (#20962)
  chore(launchpad): fix launchpad e2e tests on windows
  refactor: allow ts-node to be scoped (#20786)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants