diff --git a/test/parallel/test-npm-install.js b/test/parallel/test-npm-install.js index c716e48aef..8a900cf7f7 100644 --- a/test/parallel/test-npm-install.js +++ b/test/parallel/test-npm-install.js @@ -7,6 +7,10 @@ const assert = require('assert'); const fs = require('fs'); common.refreshTmpDir(); +const npmSandbox = path.join(common.tmpDir, 'npm-sandbox'); +fs.mkdirSync(npmSandbox); +const installDir = path.join(common.tmpDir, 'install-dir'); +fs.mkdirSync(installDir); const npmPath = path.join( common.testDir, @@ -28,15 +32,18 @@ const pkgContent = JSON.stringify({ } }); -const pkgPath = path.join(common.tmpDir, 'package.json'); +const pkgPath = path.join(installDir, 'package.json'); fs.writeFileSync(pkgPath, pkgContent); const env = Object.create(process.env); env['PATH'] = path.dirname(process.execPath); +env['NPM_CONFIG_PREFIX'] = path.join(npmSandbox, 'npm-prefix'); +env['NPM_CONFIG_TMP'] = path.join(npmSandbox, 'npm-tmp'); +env['HOME'] = path.join(npmSandbox, 'home'); const proc = spawn(process.execPath, args, { - cwd: common.tmpDir, + cwd: installDir, env: env }); @@ -44,7 +51,7 @@ function handleExit(code, signalCode) { assert.equal(code, 0, 'npm install should run without an error'); assert.ok(signalCode === null, 'signalCode should be null'); assert.doesNotThrow(function() { - fs.accessSync(common.tmpDir + '/node_modules/package-name'); + fs.accessSync(installDir + '/node_modules/package-name'); }); }