Fix user home config conflicting with the test suite - #2725
TimvdLippe wants to merge 3 commits into
Conversation
| const possibles = [ | ||
| [false, path.join(this.cwd, filename)], | ||
| [true, this.config.userconfig || path.join(userHome, filename)], | ||
| [true, this.config.userconfig || path.join(process.env.YARN_HOME_FOLDER || userHome, filename)], |
There was a problem hiding this comment.
Before coming up with this fix, I tried several others. Most notably I tried to pass on the config to override this.config.userconfig used on the same line. However, this.config is initialized as empty object in the constructor of the Registries. Passing on an initialConfig would work, but in cli/commands/global.js this config is discarded and rewritten. Therefore that solution would require passing on config objects all over the place in order to properly inject the location.
There was a problem hiding this comment.
This is a bit confusing because we have HOME defined in constants.js, npm-registry and yarn-registry.
Could you bring all of them into one place?
There was a problem hiding this comment.
I have modified the util-home-dir to export a function instead. This allows for later extension if developers want to modify their home dir too. I hope that this was what you were looking for, else please let me know!
3ab1b0b to
ce70e4a
Compare
|
Rebased this PR to fix the import test failures, but now AppVeyor is still failing per #2613 (comment) |
ce70e4a to
3ca3c32
Compare
|
I rebased this PR on master and all tests are passing now. |
3ca3c32 to
550a74f
Compare
| import * as fs from '../../src/util/fs.js'; | ||
| import {Install} from '../../src/cli/commands/install.js'; | ||
| import Config from '../../src/config.js'; | ||
| import {userHomeDir, setUserHomeDir} from '../../src/util/user-home-dir'; |
There was a problem hiding this comment.
I think for tests this can be achieved with a simple jest mock,
Then you won't need to do setter/getter and change the code
bestander
left a comment
There was a problem hiding this comment.
Better mock user-home with Jest
550a74f to
1f52ca8
Compare
|
@bestander thank you for your suggestion of using Could you maybe point out what the issue is? Thank you in advance! |
|
@TimvdLippe, you can have a look at https://github.com/yarnpkg/yarn/blob/master/__tests__/commands/install/integration.js#L38 how an internal js module can be mocked. |
|
@bestander I have copied that to https://github.com/yarnpkg/yarn/pull/2725/files#diff-ae8f7de5bfa66fccd0d4a651ae01fc77R22 The problem right now is that when I run the test, the home directory does not seem to be mocked. I suspect that the problem is that |
|
Yeah, you are right, the value from user-home-dir is imported into other projects. |
The test suite did not properly isolate the home config from influencing the behavior of the tests. Therefore if a user used the global configuration and also cloned Yarn, the tests could fail. A primary example of that was when a user set the prefix value. If the user would set the prefix, the test suite would fail.
1f52ca8 to
d2ce0ad
Compare
|
The latest commit tries to do so, but sadly still fails locally 😭 Maybe a Jest engineer could chime in to explain why it is not working? |
Summary
The test suite did not properly isolate the home config from
influencing the behavior of the tests. Therefore if a user
used the global configuration and also cloned Yarn, the tests could fail.
A primary example of that was when a user set the prefix value.
If the user would set the prefix, the test suite would fail.
Test plan
yarnon your machine following https://yarnpkg.com/en/docs/installyarn config set prefix /usr/local(or any other location)yarnyarnWithout this fix,
react-nativewould be installed in/usr/local/bin/and the test suite fails in__tests__/commands/global.js. Now the prefix is correctly set andreact-nativeis installed in the proper location.