-
-
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
Add support for --preserve-symlinks #5356
Comments
Is there a reason Jest ignores the Maybe it is, and I'm doing something wrong. |
We use Jest at Dropbox and we are also in need of the ability to preserve symlinks when Jest resolves file paths. All of our automated test runs and frontend asset build steps are performed using Bazel. Notably, Bazel runs build tools and binaries inside sandboxes, temporary directories inside which every file is actually a read-only symlink that points outside of the sandbox. Bazel expects the test binary to treat the symlinks opaquely — as normal files relative to the sandbox root. This has a couple consequences for Jest:
We've started an internal fork of Jest at Dropbox, in which we've removed the We'd be happy to contribute these changes back upstream behind a |
@lennartjansson Hi Lenart, we at Ecosia are also using Bazel and just started integrating jest, running into the same issue. A PR would be really useful to us and also others it seems, given that the first issue on this topic has been opened already in 2016. Or if you could even just open-source the fork, then others could work around this issue for the time being. On a different note, if you already have some Bazel jest rules and would be willing to open source it that would also be great, as this would be the next natural step for us also. Otherwise we would also be happy to collaborate on this. |
In case it helps anyone, we are also waiting for jest to support symlinks out of the box. Until that happens, we wrote a collection of patches (mainly inspired in @lennartjansson's post and in an abandoned PR - https://github.com/facebook/jest/pull/4387/files). We apply these patches using a postinstall hook: https://gist.github.com/rodrigoalmeidaee/a12d0c1e72f277d8c125c3c086607449 Of course these may break at any time with jest updates, so they aren't robust at all :-/ (Note: There is one extra patch there that is unrelated, it has to do with webpack-dev-server with we also had to patch to deal well with symlinks) |
I just opened up #7364 which is functionally almost complete to implement this feature. If anyone wants to help out tu push this over the finish line quicker that would be much appreciated. |
@Globegitter I would be interested in helping to pick up work on your PR #7364 if you don't expect to be working more on it soon. I was planning eventually to work on a PR myself implementing what I described here but @SimenB do you have any overall feedback or suggestions for the proposed behavior of the
(@Globegitter if the above doesn't match your intended implementation please correct me / let me know so we can design a behavior that will work for all of us.) |
@lennartjansson yep the behaviour you described is the intention of #7364 (so it is a bit of an overload of the flag). I should actually have some time for it today, otherwise it will probably quite some time until I would get around to it again. |
Ok I did not get around to do any progress after all. But if I should find some time again in the near future I'll make sure to post here first to try and avoid any double work. |
@lennartjansson is coverage working for you with symlinks? We are on the latest 24.7.1 version with patches to fix symlinks and it has been working well for normal testing, but now with coverage turned on it is not working. If I manually copy the files over coverage is working again. So maybe we missed some part in the code, or istanbul underlying needs to be configured? |
Updating @rodrigoalmeidaee patch to work with jest 24.7.1: |
So... is this on the roadmap? |
Jest now supports Plug'n'Play; it may be worth looking at how that was implemented. |
Here is a custom resolver that solved problems to us: https://gist.github.com/gcangussu/af52da296aef829eba15ea626453f031 |
@gcangussu I tried using your resolver (thanks for sharing!) doing something like: |
@ACollectionOfAtoms I'm not sure if Jest will use the custom resolver to resolve the test suite file. I think it only uses it to resolve the modules you Edit: you can pass args to Node and run Jest like this:
|
This worked perfectly for me! |
Thanks mate. This could be indeed the solution I was looking for. Do you know how I could use this line so I can configure my own vscode debug config for running jest in debug mode along the preserve-symlinks? thanks in advance |
Any updates? |
@SimenB in order to use Bazel and Jest together we really need this to go through. We need an option to preserve the parent process argv containing |
any update on this? |
If you're looking to resolve an issue regarding using Bazel with jest, then you can preserve symlinks in your jest config like this: module.exports = {
// ...
haste: {
enableSymlinks: true,
},
} |
jest yell at me with:
|
There're 2 chunks of work needs to be done for supporting symlinks.
|
Are there any updates? I'm trying to test an angular library which I symlinked into a angular test client app via import { MyLibModule } from 'my-lib'; // symlinked via npm link
describe('...', () => {
// ...
beforeEach(() => {
await TestBed.configureTestingModule({
imports: [MyLibModule],
}).compileComponents();
});
}); throws |
I've found a pretty workaround. I've replaced default jest resolver with my own, which use only
const resolve = require("resolve");
module.exports = (path, options) =>
resolve.sync(path, { ...options, preserveSymlinks: true });
Under the hood jest's |
I have also a library symlinked to an app (I'm developing both). I have found out my main app Jest tests fail when I run them after I was watching the library for changes. But if I build the library manually with its build command and then run the main app Jest tests, then they work properly 😕. |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
I'm still working on projects that would benefit from Jest supporting I have a repo structure like:
I can get all other parts of my dev process to respect In order to run Jest for |
6 years later... Jest still lacks basic things like this, full ESM support etc. Shall we use the resolver workaround above as a temporary official solution? |
Any update on this? We are running into this with ts-jest and we're having troubles even getting the resolver workaround to work with ES modules. Getting this issue resolved would be really nice |
Any update on this? I'm running into this problem with Jest v6.2.5 on macOS. |
This is a thorny issue but I believe I'm beginning to understand it.
Basically there's two ways to treat symlinks:
There are downsides to both (if my understanding is right).
Node by default does not preserve symlinks. They tried to change this behavior in Node 6 (nodejs/node#5950) but that backfired with non-trivial breakages and they reverted it soon and put behind a
--preserve-symlinks
flag (nodejs/node#6537). There is also an argument that the behavior isn't a bug or needs a different fix (https://github.com/isaacs/node6-module-system-change).Regardless, it seems like some people prefer one behavior (with its set of tradeoffs) and other people prefer the other behavior (with another set of tradeoffs). Node currently supports both. Webpack does too (https://webpack.js.org/configuration/resolve/#resolve-symlinks).
Jest currently seems to support a mixture of both behaviors (?). I fixed at least some of it to match Node in #4761 (ironically despite "preserve" in the PR name the change aligned with Node's default behavior of not preserving them). I still think that PR was a good idea. However, apparently there are places where Jest still doesn't match node: #5228, #5085.
Assuming those get fixed, and Jest always does not preserve symlinks by default (just like Node), what do you think about allowing the "preserve symlinks" behavior as an opt-in, just like Node and webpack already offer?
The text was updated successfully, but these errors were encountered: