node/test/parallel/test-npm-install.js
Myles Borins 738a1d639f test: ensure test-npm-install uses correct node
Currently it is possible that the shelled out instance of npm will use
the system copy of node. This PR changes the test to shim the build
directory into the path. This will ensure that npm will use the correct
version of node.

fixes: https://github.com/nodejs/node/issues/6648

PR-URL: https://github.com/nodejs/node/pull/6658
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-05-11 12:21:05 -07:00

51 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 proc = spawn(process.execPath, args, {
cwd: common.tmpDir,
env: {
PATH: path.dirname(process.execPath)
}
});
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));