-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
feat(jest-haste-map): Enable crawling for symlink test files #9351
Conversation
Hi mrmeku! Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
CLA has been signed |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Hi @mrmeku, thanks for the issue and PR! Unfortunately I think the fix is not as simple. This will break e.g. if |
@jeysal If I handled the case for filtering out symlinked directories would you be satisfied with this change? For background:
Given that I've identified that this change does solve a bug with executing jest under bazel and prior attempts aren't showing much traction, I'd like to continue this PR. Can we work together to identify the short comings of this approach so that I can resolve those short comings? |
With a check that the linked node is a file I couldn't come up with an example that breaks anymore, I'm just not sure that I wholly understand the implications of the change because I'm only partially familiar with the low level parts of Jest. Unfortunately, I don't know who else would, since there is no one from FB working on Jest atm, and @SimenB, who has spent the most time on Jest, didn't do much with haste-map afaik. I only know @cpojer looked at symlink handling more broadly for Metro and Jest some time ago - not sure what the outcome was? |
@jeysal I'll update my PR to do the Just my two cents, so far as I can tell, I think that the majority of user's will not be impacted by a change allowing symlinks to be crawled since the majority of users do not use symlinks. Only special workspaces / runtime environments make use of symlinks directly in their source/test code. And at least for Jest execution in Bazel's runtime env, the current default behavior is a bug and this change eliminates that bug. |
4497c98
to
3888ea9
Compare
Codecov Report
@@ Coverage Diff @@
## master #9351 +/- ##
==========================================
- Coverage 65.09% 64.71% -0.39%
==========================================
Files 287 280 -7
Lines 12145 11998 -147
Branches 3007 2961 -46
==========================================
- Hits 7906 7764 -142
+ Misses 3604 3601 -3
+ Partials 635 633 -2
Continue to review full report at Codecov.
|
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.
Can we add a test (e2e I guess due to the nature of the change)?
@SimenB e2e test added successfully |
43f5092
to
d16f677
Compare
@SimenB I've updated the commit to fix lint errors, include copywrite for the test file I added and also augmented the non-native file crawler to pick up symlink files as well. |
Thank you so much for adding this feature. Since you are using Bazel, is this work related to Google's adoption of Jest or is this separate? The only concern I have is adding features to the node crawler that the watchman one does not support. If somebody has watchmen installed but falls back to node for some reason, Jest should be able to reconcile between the two. If we add this feature, different amounts of tests may be found depending on the current state of the machine or other environment factors. |
@cpojer Sorry for the late reply, I went on a vacation last week :) This isn't directly related to Google's adoption of a new test runner (I don't work there anymore so I'm a bit out of the loop). I got started on this project as a means of making the @cpojer One question. I'm willing to augment |
@mrmeku thanks for the reply and hope you enjoyed your vacation! I'd much prefer if we could merge watchman support for this given the concerns I outlined above that will lead to inconsistency and a poor experience with Jest when the underlying system is flaky. I am happy if you add that in a separate PR and would prefer holding off on merging this one until most of the watchman support is available or once we at least get the biggest blockers out of the way – or otherwise you make a big promise that you will do that. Otherwise we may need to disable or unland this change to not cause issues in Jest. |
@SimenB I'm taking a look into it tonight. Life got a little hectic so I had to delay things for a little while |
@SimenB @cpojer It looks like watchman's symlink's support is off by default, but it does support a flag to enable crawling symlinks: https://github.com/facebook/watchman/blob/b3895be21e4502fc1fcaae75b146a703bc134fce/root/stat.cpp#L232 That being the case, I'm not exactly sure what the best change to make is. So far as I can tell, we don't have a way to override the settings within a user's
I think I'm partial to #2 since its the least complex option. |
bee5d0d
to
c497fcb
Compare
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.
Thanks! I think this is finally good to go. To be safe I'll wait to land it until we start landing breaking changes (mostly because of the find
changes, I've broken that before without knowing). That will start landing this week though, so not a long wait 🙂
Thanks for sticking with this, it's taken a while with much back and forth!
(I landed parts of the docs changes in 038d8be, btw)
Thanks for all your patience :) |
Ping @SimenB could you find time to get this in? The community of Bazel users is all patching this change in, after tripping over the symlink problem. It's becoming a serious barrier to adoption since Jest is so popular :) |
@hgiesel the reason no files were being found is because Jest ignores symlinks by default. The Bazel example includes a patch we can use to work around it, and Jest plan to add symlink support in a future update. https://github.com/bazelbuild/rules_nodejs/blob/stable/examples/jest/patches/jest-haste-map%2B24.9.0.patch jestjs/jest#9351
sorry @SimenB I know we're all busy OSS maintainers, but this one would be a big help for the Bazel community. it trips all novice users on their way in. |
Hey @alexeagle, sorry about the radio silence here! We discussed this a bit, and got some pushback since it necessitates turning off watchman, which in theory leads to worse performance, especially during startup/initial crawl and watch mode re-runs. This led us down the rabbit hole of trying to benchmark the crawler implemented with node Aaaaaanyway, I didn't know you were actually using a patch to get this. I assume that means that this change works for Bazel users? |
@SimenB thank you for the extra info. When you were talking about node E.g. is the selection of |
yes, we have the patch in all our examples (e.g. https://github.com/bazelbuild/rules_nodejs/blob/stable/examples/jest/patches/jest-haste-map%2B24.9.0.patch) and have instructed all users to install it as well. |
#yolo |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Jest haste maps test file crawler (see packages/jest-haste-map/src/crawlers/node.ts) uses the unix find command by default to find files whose name matches the testMatch pattern defined in jest.config.js. This works great for most cases, but works poorly when executing jest under bazel.
In bazel's execution environment, all source/test files are symlinked into a sandboxed directory rather than copied over directly. Jest's crawler is currently set up to use find's type flag to filter only for files. This excludes symlinked files
Under bazel I would expect my symlinked test files to be able to be crawled. This merely involves tweaking the command line args to find to include both files and symlinks
--type f
--->(--type f -o --type=l)
Test plan
I have already tested my fix against multiple bazel environments to verify that the fix enables jest to work properly for that test runner. The only risk of this change is that my adding support for crawling symlinks hampers performance of file crawling. If that is the case this behavior might be better off to be enabled behind a flag. But I do not suspect that there will be a performance hit. If reviewers have a mechanism for running jest bench marks I'm happy to create a repo filled with both files and symlinks and benchmarking the change.