diff --git a/__tests__/commands/_helpers.js b/__tests__/commands/_helpers.js index 5e369f6a47..f7cf1d8528 100644 --- a/__tests__/commands/_helpers.js +++ b/__tests__/commands/_helpers.js @@ -101,8 +101,6 @@ 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')); @@ -126,14 +124,12 @@ export async function run( production: flags.production, }, reporter); - const install = await factory(args, flags, config, reporter, lockfile, () => out); + const install = await factory(args, flags, config, reporter, lockfile, () => out, path.join(cwd, '.yarn-home')); if (checkInstalled) { await checkInstalled(config, reporter, install); } } catch (err) { throw new Error(`${err && err.stack} \nConsole output:\n ${out}`); - } finally { - process.env.YARN_HOME_FOLDER = homeFolderLocation; } } diff --git a/__tests__/commands/global.js b/__tests__/commands/global.js index a8a9d6f80a..044bbd6152 100644 --- a/__tests__/commands/global.js +++ b/__tests__/commands/global.js @@ -3,7 +3,6 @@ import type {CLIFunctionReturn} from '../../src/types.js'; import {ConsoleReporter} from '../../src/reporters/index.js'; import {run as buildRun} from './_helpers.js'; -import {run as global} from '../../src/cli/commands/global.js'; import * as fs from '../../src/util/fs.js'; import assert from 'assert'; const isCI = require('is-ci'); @@ -18,7 +17,15 @@ const runGlobal = buildRun.bind( null, ConsoleReporter, fixturesLoc, - (args, flags, config, reporter): CLIFunctionReturn => { + (args, flags, config, reporter, _lockfile, _out, homeFolderLocation): CLIFunctionReturn => { + const automock = jest.genMockFromModule('../../src/util/user-home-dir'); + jest.setMock('../../src/util/user-home-dir', Object.assign(automock, homeFolderLocation)); + + jest.resetModules(); + jest.mock('../../src/util/user-home-dir'); + + const global = require('../../src/cli/commands/global.js').run; + jest.unmock('../../src/util/user-home-dir'); return global(config, reporter, flags, args); }, ); diff --git a/src/registries/npm-registry.js b/src/registries/npm-registry.js index 176a469918..2c3de01328 100644 --- a/src/registries/npm-registry.js +++ b/src/registries/npm-registry.js @@ -97,7 +97,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(process.env.YARN_HOME_FOLDER || userHome, filename)], + [true, this.config.userconfig || path.join(userHome, filename)], [false, path.join(getGlobalPrefix(), filename)], ];