From 7b77b1ed46badbf1c70582734608b41d746ffa73 Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Tue, 18 Apr 2017 12:22:19 -0400 Subject: [PATCH] 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. Refs: https://github.com/nodejs/node/pull/12480 --- test/parallel/test-npm-install.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/parallel/test-npm-install.js b/test/parallel/test-npm-install.js index 5195dbc3ef9fbd..97bf0904cf4e1f 100644 --- a/test/parallel/test-npm-install.js +++ b/test/parallel/test-npm-install.js @@ -6,7 +6,7 @@ if (!common.hasCrypto) { } const path = require('path'); -const spawn = require('child_process').spawn; +const exec = require('child_process').exec; const assert = require('assert'); const fs = require('fs'); @@ -26,11 +26,6 @@ const npmPath = path.join( 'npm-cli.js' ); -const args = [ - npmPath, - 'install' -]; - const pkgContent = JSON.stringify({ dependencies: { 'package-name': common.fixturesDir + '/packages/main' @@ -47,17 +42,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));