From ce70e4a11fc931a10a6d462be0aa3f5668c981d8 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Sun, 19 Feb 2017 16:57:58 +0100 Subject: [PATCH] Fix user home config conflicting with the test suite 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. --- __tests__/commands/_helpers.js | 5 +++++ src/registries/npm-registry.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/__tests__/commands/_helpers.js b/__tests__/commands/_helpers.js index a5c42f9fe9..5e369f6a47 100644 --- a/__tests__/commands/_helpers.js +++ b/__tests__/commands/_helpers.js @@ -101,12 +101,15 @@ export async function run( // 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) { @@ -130,5 +133,7 @@ export async function run( } } catch (err) { throw new Error(`${err && err.stack} \nConsole output:\n ${out}`); + } finally { + process.env.YARN_HOME_FOLDER = homeFolderLocation; } } diff --git a/src/registries/npm-registry.js b/src/registries/npm-registry.js index 348f512e5b..1f117da950 100644 --- a/src/registries/npm-registry.js +++ b/src/registries/npm-registry.js @@ -98,7 +98,7 @@ export default class NpmRegistry extends Registry { async getPossibleConfigLocations(filename: string): Promise> { 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)], ];