Skip to content

Commit 8b04574

Browse files
Fishrock123MylesBorins
authored andcommitted
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: #12490 Refs: #12480 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 25be2a3 commit 8b04574

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

test/parallel/test-npm-install.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const common = require('../common');
33

44
const path = require('path');
5-
const spawn = require('child_process').spawn;
5+
const exec = require('child_process').exec;
66
const assert = require('assert');
77
const fs = require('fs');
88

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

25-
const args = [
26-
npmPath,
27-
'install'
28-
];
29-
3025
const pkgContent = JSON.stringify({
3126
dependencies: {
3227
'package-name': `${common.fixturesDir}/packages/main`
@@ -43,17 +38,22 @@ env['NPM_CONFIG_PREFIX'] = path.join(npmSandbox, 'npm-prefix');
4338
env['NPM_CONFIG_TMP'] = path.join(npmSandbox, 'npm-tmp');
4439
env['HOME'] = path.join(npmSandbox, 'home');
4540

46-
const proc = spawn(process.execPath, args, {
41+
exec(`${process.execPath} ${npmPath} install`, {
4742
cwd: installDir,
4843
env: env
49-
});
44+
}, common.mustCall(handleExit));
45+
46+
function handleExit(error, stdout, stderr) {
47+
const code = error ? error.code : 0;
48+
const signalCode = error ? error.signal : null;
49+
50+
if (code !== 0) {
51+
process.stderr.write(stderr);
52+
}
5053

51-
function handleExit(code, signalCode) {
5254
assert.strictEqual(code, 0, `npm install got error code ${code}`);
5355
assert.strictEqual(signalCode, null, `unexpected signal: ${signalCode}`);
5456
assert.doesNotThrow(function() {
5557
fs.accessSync(`${installDir}/node_modules/package-name`);
5658
});
5759
}
58-
59-
proc.on('exit', common.mustCall(handleExit));

0 commit comments

Comments
 (0)