-
-
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
Preserve module identity for symlinks #4761
Conversation
Apparently the build on master is failing 😞 Should I send another PR to disable the failing test in the meantime? |
@gaearon if it's |
if (result) { | ||
// Dereference symlinks to ensure we don't create a separate | ||
// module instance depending on how it was referenced. | ||
result = fs.realpathSync(result); |
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.
So basically we're hitting fs
one more time, wonder how it affects perfomance.
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 know it was slow (nodejs/node#2680) and was optimized in nodejs/node@b488b19.
Perhaps counter-intuitively, running on React codebase (with warm caches) makes this PR slightly faster. Maybe there's some indirection in accessing the symlinks later that resolving them removes?
before the change (5 tries)
44.67 real 123.24 user 8.76 sys
44.61 real 123.07 user 8.76 sys
44.58 real 123.44 user 8.77 sys
44.62 real 122.45 user 8.72 sys
46.73 real 124.52 user 8.93 sys
after the change (5 tries)
44.08 real 121.83 user 8.14 sys
43.63 real 121.55 user 8.15 sys
44.01 real 121.95 user 8.23 sys
43.85 real 122.70 user 8.29 sys
44.33 real 122.54 user 8.16 sys
before the change again (5 tries)
44.43 real 122.47 user 8.66 sys
45.18 real 123.94 user 8.91 sys
44.95 real 123.20 user 8.84 sys
44.34 real 123.15 user 8.76 sys
44.50 real 122.88 user 8.72 sys
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 for caring about this!
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.
It could be that it's faster for us (since we use symlinks) but slower on projects that don't use symlinks at all. ¯\(ツ)/¯
const didFail = result.status !== 0; | ||
if (didFail) { | ||
console.log(result.stderr); | ||
} |
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.
This is a leftover, right? I know these integration tests don't give great error feedback, but it gets better while running inside specific directory (when debugging what's wrong)
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.
That was not obvious at all. Contributing document doesn't mention this :-(
I spent half an hour guessing why the test doesn't work without feedback.
As I wrote above:
I also added some logging to the test runner for this integration test because when it failed, there used to be no indication at all as to the reasons why it was failing.
I can remove though.
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 you open up a separate issue for this? If nothing else it should be documented, but maybe we can make it better
Failing test on master is tracked in #4745 |
I also verified that it fixes a different (but related) Yarn/Jest integration problem for us. After migrating to Yarn Workspaces, our @cpojer told me he’s aware this was an issue. @BYK said GraphQL team also bumped into this. In my testing, this PR solves it. |
Thanks so much @gaearon for making this happen. This definitely seems like the right fix for this issue. I published |
Sweet. Thanks. 💃 |
Unrelated, but I noticed that in fit('should throw on children for void elements', () => {
const container = document.createElement('div');
let caughtErr;
try {
ReactDOM.render(<input>children</input>, container); // throws
} catch (err) {
caughtErr = err;
}
expect(caughtErr).not.toBe(undefined);
}); end up being reported as failures. This isn't the case in I know I could use Is this intentional or a bug? Worth making an issue? |
Thanks so much for this. I've been plagued by it since workspaces was released! |
They were fixed by jestjs/jest#4761.
* Update Jest * Remove hacks for Jest + Workspace integration They were fixed by jestjs/jest#4761. * Use relative requires in tests relying on private APIs I changed them to absolute to work around a Jest bug. The bug has been fixed so I can revert my past changes now.
* Update Jest * Remove hacks for Jest + Workspace integration They were fixed by jestjs/jest#4761. * Use relative requires in tests relying on private APIs I changed them to absolute to work around a Jest bug. The bug has been fixed so I can revert my past changes now.
Discovered while doing this some weirdness involving babel transpilation. gherkin-runner wasn't getting transpiled when tests run. Found some discussion of the issue, including an indication that a fix is due out in jest soon: jestjs/jest#4761 I updated jest to 21.3.0-beta.3 to see if that helped. It didn't at first, which turned out to be because it wasn't under the original package directory, so babel didn't know what transforms to run (?). (These thoughts are based on discussion here:) babel/babel-loader#293 I added some babel configuration to the root-level package.json which fixed the issue.
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
We bumped into a problem trying to use Yarn Workspaces with Jest in the React repo.
It is the same issue as described in #3830.
In our case, we had
packages/*
symlinked throughnode_modules
.We noticed that importing the same file with the path
root/packages/react/module
from a test inroot/packages/react/folder/__tests__
produced a different instantiation depending on how it is imported:react/folder/module
symlink.../module
path.This is because the old resolving mechanism established resolved paths as:
react/folder/module
=>repo/node_modules/react/folder/module.js
../module
=>repo/packages/react/folder/module.js
So Jest treated them as two different modules. This created very subtle and hard-to-debug errors (such as duplicate caches in arbitrary module branches depending on the initial imports that "forked" them).
With this fix, the resolving mechanism resolves both cases to
repo/packages/react/folder/module.js
.It also fixes a different problem we experienced with Jest/Yarn together not compiling modules.
Test plan
Tests pass in React repo with relative paths, whereas they would fail before.
The reproducing case in https://github.com/tmeasday/jest-symlink-repro used to print twice:
Now it prints once, as expected in its README:
I added a new integration test and verified it fails on master.
I also added some logging to the test runner for this integration test because when it failed, there used to be no indication at all as to the reasons why it was failing.Removed per feedback.Locally, I see a test failure in
packages/jest-worker/src/__tests__/child.test.js
but it also happens in master so is unrelated.