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:
authorLuke Karrys <luke@lukekarrys.com>2021-11-04 00:53:40 +0300
committerLuke Karrys <luke@lukekarrys.com>2021-11-04 23:06:50 +0300
commit22230ef3dd590def31c274b3412106b4cfbd212f (patch)
tree8101180fa461569b8e26b05a199c7dd6487e8516 /test
parenta0d35ff20aed6aab8508123eb540bc9c61fb127d (diff)
fix: make prefixed usage errors more consistent
PR-URL: https://github.com/npm/cli/pull/3987 Credit: @lukekarrys Close: #3987 Reviewed-by: @wraithgar
Diffstat (limited to 'test')
-rw-r--r--test/lib/commands/cache.js10
-rw-r--r--test/lib/commands/help-search.js3
-rw-r--r--test/lib/commands/pkg.js10
3 files changed, 11 insertions, 12 deletions
diff --git a/test/lib/commands/cache.js b/test/lib/commands/cache.js
index c12318f4e..168cfce6d 100644
--- a/test/lib/commands/cache.js
+++ b/test/lib/commands/cache.js
@@ -3,8 +3,6 @@ const { fake: mockNpm } = require('../../fixtures/mock-npm.js')
const path = require('path')
const npa = require('npm-package-arg')
-const usageUtil = () => 'usage instructions'
-
let outputOutput = []
let rimrafPath = ''
@@ -140,7 +138,6 @@ const Cache = t.mock('../../../lib/commands/cache.js', {
npmlog,
pacote,
rimraf,
- '../../../lib/utils/usage.js': usageUtil,
})
const npm = mockNpm({
@@ -161,7 +158,7 @@ const cache = new Cache(npm)
t.test('cache no args', async t => {
await t.rejects(
cache.exec([]),
- 'usage instructions',
+ { code: 'EUSAGE' },
'should throw usage instructions'
)
})
@@ -194,7 +191,10 @@ t.test('cache add no arg', async t => {
await t.rejects(
cache.exec(['add']),
- { code: 'EUSAGE' },
+ {
+ code: 'EUSAGE',
+ message: 'Usage: First argument to `add` is required',
+ },
'throws usage error'
)
t.strictSame(logOutput, [
diff --git a/test/lib/commands/help-search.js b/test/lib/commands/help-search.js
index 9faa38a32..406977b62 100644
--- a/test/lib/commands/help-search.js
+++ b/test/lib/commands/help-search.js
@@ -103,8 +103,7 @@ t.test('npm help-search long output with color', async t => {
})
t.test('npm help-search no args', async t => {
- await helpSearch.exec([])
- t.match(OUTPUT, /npm help-search/, 'outputs usage')
+ t.rejects(helpSearch.exec([]), /npm help-search/, 'outputs usage')
})
t.test('npm help-search no matches', async t => {
diff --git a/test/lib/commands/pkg.js b/test/lib/commands/pkg.js
index 784ea7470..49234e4cc 100644
--- a/test/lib/commands/pkg.js
+++ b/test/lib/commands/pkg.js
@@ -196,7 +196,7 @@ t.test('set no args', async t => {
})
await t.rejects(
pkg.exec(['set']),
- { code: 'EPKGSET' },
+ { code: 'EUSAGE' },
'should throw an error if no args'
)
})
@@ -207,7 +207,7 @@ t.test('set missing value', async t => {
})
await t.rejects(
pkg.exec(['set', 'key=']),
- { code: 'EPKGSET' },
+ { code: 'EUSAGE' },
'should throw an error if missing value'
)
})
@@ -218,7 +218,7 @@ t.test('set missing key', async t => {
})
await t.rejects(
pkg.exec(['set', '=value']),
- { code: 'EPKGSET' },
+ { code: 'EUSAGE' },
'should throw an error if missing key'
)
})
@@ -424,7 +424,7 @@ t.test('delete no args', async t => {
})
await t.rejects(
pkg.exec(['delete']),
- { code: 'EPKGDELETE' },
+ { code: 'EUSAGE' },
'should throw an error if deleting no args'
)
})
@@ -435,7 +435,7 @@ t.test('delete invalid key', async t => {
})
await t.rejects(
pkg.exec(['delete', '']),
- { code: 'EPKGDELETE' },
+ { code: 'EUSAGE' },
'should throw an error if deleting invalid args'
)
})