Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRuy Adorno <ruyadorno@hotmail.com>2021-03-29 18:00:44 +0300
committerRuy Adorno <ruyadorno@hotmail.com>2021-03-29 20:52:19 +0300
commit9dd2ed5189b6f283094664e9e192cf1598ec3f79 (patch)
tree2b6ec9c0a15b013aaba73cf52c35bbd43382145c /test
parenta28f89572a708cced69cc938f877eaa969dbad9e (diff)
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: https://github.com/nodejs/node/pull/37678#issuecomment-808734374 Co-authored-by: Gar <gar+gh@danger.computer>
Diffstat (limited to 'test')
-rw-r--r--test/lib/cli.js29
1 files changed, 25 insertions, 4 deletions
diff --git a/test/lib/cli.js b/test/lib/cli.js
index 40da77bf4..28e44394e 100644
--- a/test/lib/cli.js
+++ b/test/lib/cli.js
@@ -172,17 +172,37 @@ t.test('gracefully handles error printing usage', t => {
t.teardown(() => {
npmock.output = output
errorHandlerCb = null
+ errorHandlerCalled = null
})
const proc = {
- argv: ['node', 'npm', 'asdf'],
+ argv: ['node', 'npm'],
on: () => {},
}
npmock.argv = []
- npmock.output = (msg) => {
- throw new Error('test exception')
+ errorHandlerCb = () => {
+ t.match(errorHandlerCalled, [], 'should call errorHandler with no args')
+ t.end()
+ }
+ cli(proc)
+})
+
+t.test('handles output error', t => {
+ const { output } = npmock
+ t.teardown(() => {
+ npmock.output = output
+ errorHandlerCb = null
+ errorHandlerCalled = null
+ })
+ const proc = {
+ argv: ['node', 'npm'],
+ on: () => {},
+ }
+ npmock.argv = []
+ npmock.output = () => {
+ throw new Error('ERR')
}
errorHandlerCb = () => {
- t.match(errorHandlerCalled, /test exception/)
+ t.match(errorHandlerCalled, /ERR/, 'should call errorHandler with error')
t.end()
}
cli(proc)
@@ -191,6 +211,7 @@ t.test('gracefully handles error printing usage', t => {
t.test('load error calls error handler', t => {
t.teardown(() => {
errorHandlerCb = null
+ errorHandlerCalled = null
LOAD_ERROR = null
})