Skip to content

Commit

Permalink
test: pipe some error output if npm fails
Browse files Browse the repository at this point in the history
This test now prints out some child error output if the npm child proc
fails, allowing us to debug easier.

PR-URL: #12490
Refs: #12480
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
Fishrock123 authored and MylesBorins committed Sep 20, 2017
1 parent 25be2a3 commit 8b04574
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions test/parallel/test-npm-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const common = require('../common');

const path = require('path');
const spawn = require('child_process').spawn;
const exec = require('child_process').exec;
const assert = require('assert');
const fs = require('fs');

Expand All @@ -22,11 +22,6 @@ const npmPath = path.join(
'npm-cli.js'
);

const args = [
npmPath,
'install'
];

const pkgContent = JSON.stringify({
dependencies: {
'package-name': `${common.fixturesDir}/packages/main`
Expand All @@ -43,17 +38,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));

0 comments on commit 8b04574

Please sign in to comment.