mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 09:02:40 +00:00

Currently we are overwriting the entire env object of the child-process spawned in `npm-test-install`. This commit alternatively clones the `process.env` object and modifies it with the neccessary changes before passing it the the spawned process. Fixes: https://github.com/nodejs/node/issues/6736 PR-URL: https://github.com/nodejs/node/pull/6797 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
52 lines
1.0 KiB
JavaScript
52 lines
1.0 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
|
|
const path = require('path');
|
|
const spawn = require('child_process').spawn;
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
|
|
common.refreshTmpDir();
|
|
|
|
const npmPath = path.join(
|
|
common.testDir,
|
|
'..',
|
|
'deps',
|
|
'npm',
|
|
'bin',
|
|
'npm-cli.js'
|
|
);
|
|
|
|
const args = [
|
|
npmPath,
|
|
'install'
|
|
];
|
|
|
|
const pkgContent = JSON.stringify({
|
|
dependencies: {
|
|
'package-name': common.fixturesDir + '/packages/main'
|
|
}
|
|
});
|
|
|
|
const pkgPath = path.join(common.tmpDir, 'package.json');
|
|
|
|
fs.writeFileSync(pkgPath, pkgContent);
|
|
|
|
const env = Object.create(process.env);
|
|
env['PATH'] = path.dirname(process.execPath);
|
|
|
|
const proc = spawn(process.execPath, args, {
|
|
cwd: common.tmpDir,
|
|
env: env
|
|
});
|
|
|
|
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');
|
|
});
|
|
}
|
|
|
|
proc.on('exit', common.mustCall(handleExit));
|