Skip to content

Commit f694ea6

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 b4e8850 commit f694ea6

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
@@ -4,7 +4,7 @@ if (!common.hasCrypto)
44
common.skip('missing crypto');
55

66
const path = require('path');
7-
const spawn = require('child_process').spawn;
7+
const exec = require('child_process').exec;
88
const assert = require('assert');
99
const fs = require('fs');
1010

@@ -24,11 +24,6 @@ const npmPath = path.join(
2424
'npm-cli.js'
2525
);
2626

27-
const args = [
28-
npmPath,
29-
'install'
30-
];
31-
3227
const pkgContent = JSON.stringify({
3328
dependencies: {
3429
'package-name': `${common.fixturesDir}/packages/main`
@@ -45,17 +40,22 @@ env['NPM_CONFIG_PREFIX'] = path.join(npmSandbox, 'npm-prefix');
4540
env['NPM_CONFIG_TMP'] = path.join(npmSandbox, 'npm-tmp');
4641
env['HOME'] = path.join(npmSandbox, 'home');
4742

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

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

0 commit comments

Comments
 (0)