Browse Source

test: pipe some error output if npm fails

This test now prints out some child error output if the npm child proc
fails, allowing us to debug easier.

PR-URL: https://github.com/nodejs/node/pull/12490
Refs: https://github.com/nodejs/node/pull/12480
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
canary-base
Jeremiah Senkpiel 8 years ago
committed by Ruben Bridgewater
parent
commit
99c478eb36
No known key found for this signature in database GPG Key ID: F07496B3EB3C1762
  1. 22
      test/parallel/test-npm-install.js

22
test/parallel/test-npm-install.js

@ -4,7 +4,7 @@ if (!common.hasCrypto)
common.skip('missing crypto');
const path = require('path');
const spawn = require('child_process').spawn;
const exec = require('child_process').exec;
const assert = require('assert');
const fs = require('fs');
@ -24,11 +24,6 @@ const npmPath = path.join(
'npm-cli.js'
);
const args = [
npmPath,
'install'
];
const pkgContent = JSON.stringify({
dependencies: {
'package-name': `${common.fixturesDir}/packages/main`
@ -45,17 +40,22 @@ 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, {
exec(`${process.execPath} ${npmPath} install`, {
cwd: installDir,
env: env
});
}, common.mustCall(handleExit));
function handleExit(error, stdout, stderr) {
const code = error ? error.code : 0;
const signalCode = error ? error.signal : null;
if (code !== 0) {
process.stderr.write(stderr);
}
function handleExit(code, signalCode) {
assert.strictEqual(code, 0, `npm install got error code ${code}`);
assert.strictEqual(signalCode, null, `unexpected signal: ${signalCode}`);
assert.doesNotThrow(function() {
fs.accessSync(`${installDir}/node_modules/package-name`);
});
}
proc.on('exit', common.mustCall(handleExit));

Loading…
Cancel
Save