Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: pipe some error output if npm fails #12490

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions test/parallel/test-npm-install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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'
Expand All @@ -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));