node/test/parallel/test-npm-install.js
Anna Henningsen 15cd45c6fc
test: fix tests for non-crypto builds
Fix running the tests when node was compiled without crypto
support. Some of these are cleanup after 52bae222a3, where
common was used before it was required.

PR-URL: https://github.com/nodejs/node/pull/7056
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-06-08 11:42:28 +02:00

56 lines
1.1 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
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));