node/test/parallel/test-npm-install.js
Santiago Gimeno fbe0b444ef test: improve test-npm-install
Make npm install a dependency that is defined as a relative path, so it
avoids any network interaction.

PR-URL: https://github.com/nodejs/node/pull/5613
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Claudio Rodriguez <cjrodr@yahoo.com>
2016-03-14 08:25:55 -07:00

48 lines
973 B
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
});
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));