-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: empty newline printed to stderr
Starting in v7.7.0 running `npm` (no args) is printing an empty newline to stderr. This fixes that by correctly exiting via errorHandler and avoiding hitting the cb() never called error and adds a test to make sure we avoid that regression moving forward. Fixes: nodejs/node#37678 (comment) Co-authored-by: Gar <[email protected]>
- Loading branch information
Showing
4 changed files
with
77 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ t.cleanSnapshot = s => s.split(cwd).join('{CWD}') | |
.split(process.cwd()).join('{CWD}') | ||
.replace(/\\+/g, '/') | ||
.replace(/\r\n/g, '\n') | ||
.replace(/ (in a browser)/g, '') | ||
|
||
// setup server | ||
const registryServer = require('./server.js') | ||
|
@@ -55,6 +56,19 @@ t.test('npm init', async t => { | |
t.equal(pkg.version, '1.0.0', 'should have expected generated version') | ||
}) | ||
|
||
t.test('npm (no args)', async t => { | ||
const cmd = `"${process.execPath}" "${npmLocation}" --no-audit --no-update-notifier` | ||
const cmdRes = await execAsync(cmd, { cwd: localPrefix, env }) | ||
.catch(err => { | ||
t.equal(err.code, 1, 'should exit with error code') | ||
return err | ||
}) | ||
|
||
t.equal(cmdRes.stderr, '', 'should have no stderr output') | ||
t.matchSnapshot(String(cmdRes.stdout), | ||
'should have expected no args output') | ||
}) | ||
|
||
t.test('npm install prodDep@version', async t => { | ||
const cmd = `${npmBin} install [email protected]` | ||
const cmdRes = await exec(cmd) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,43 @@ | |
* Make sure to inspect the output below. Do not ignore changes! | ||
*/ | ||
'use strict' | ||
exports[`smoke-tests/index.js TAP npm (no args) > should have expected no args output 1`] = ` | ||
npm <command> | ||
Usage: | ||
npm install install all the dependencies in your project | ||
npm install <foo> add the <foo> dependency to your project | ||
npm test run this project's tests | ||
npm run <foo> run the script named <foo> | ||
npm <command> -h quick help on <command> | ||
npm -l display usage info for all commands | ||
npm help <term> search for help on <term> | ||
npm help npm more involved overview | ||
All commands: | ||
access, adduser, audit, bin, bugs, cache, ci, completion, | ||
config, dedupe, deprecate, diff, dist-tag, docs, doctor, | ||
edit, exec, explain, explore, find-dupes, fund, get, help, | ||
hook, init, install, install-ci-test, install-test, link, | ||
ll, login, logout, ls, org, outdated, owner, pack, ping, | ||
prefix, profile, prune, publish, rebuild, repo, restart, | ||
root, run-script, search, set, set-script, shrinkwrap, star, | ||
stars, start, stop, team, test, token, uninstall, unpublish, | ||
unstar, update, version, view, whoami | ||
Specify configs in the ini-formatted file: | ||
{CWD}/smoke-tests/index/.npmrc | ||
or on the command line via: npm <command> --key=value | ||
More configuration info: npm help config | ||
Configuration fields: npm help 7 config | ||
[email protected] {CWD} | ||
` | ||
|
||
exports[`smoke-tests/index.js TAP npm diff > should have expected diff output 1`] = ` | ||
diff --git a/package.json b/package.json | ||
index v1.0.4..v1.1.1 100644 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters