Skip to content

Commit

Permalink
Fix user home config conflicting with the test suite
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TimvdLippe committed Mar 12, 2017
1 parent 664b6a4 commit 814b962
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions __tests__/commands/_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,15 @@ export async function run<T, R>(

// remove the lockfile if we create one and it didn't exist before
const lockfile = await createLockfile(cwd);
const homeFolderLocation = process.env.YARN_HOME_FOLDER;
process.env.YARN_HOME_FOLDER = path.join(cwd, '.yarn-home');

// create directories
await fs.mkdirp(path.join(cwd, '.yarn-global'));
await fs.mkdirp(path.join(cwd, '.yarn-link'));
await fs.mkdirp(path.join(cwd, '.yarn-cache'));
await fs.mkdirp(path.join(cwd, 'node_modules'));
await fs.mkdirp(path.join(cwd, '.yarn-home'));

// make sure the cache folder been created in temp folder
if (flags.cacheFolder) {
Expand All @@ -130,5 +133,7 @@ export async function run<T, R>(
}
} catch (err) {
throw new Error(`${err && err.stack} \nConsole output:\n ${out}`);
} finally {
process.env.YARN_HOME_FOLDER = homeFolderLocation;
}
}
2 changes: 1 addition & 1 deletion src/registries/npm-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default class NpmRegistry extends Registry {
async getPossibleConfigLocations(filename: string): Promise<Array<[boolean, string, string]>> {
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)],
[false, path.join(getGlobalPrefix(), filename)],
];

Expand Down

0 comments on commit 814b962

Please sign in to comment.