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
diff options
context:
space:
mode:
authorGar <gar+gh@danger.computer>2021-02-25 02:54:50 +0300
committerRuy Adorno <ruyadorno@hotmail.com>2021-03-05 00:05:08 +0300
commit4a5dd3a5a200b3f4f7b47168497d8e03dca3a2ca (patch)
treed34a1ea229b719c3cfbdce85899ceaf67b43e7ab /test/lib/help-search.js
parentb33c760cea7fe2696d35b5530abc1b455980fef1 (diff)
fix(npm) pass npm context everywhere
Instead of files randomly requiring the npm singleton, we pass it where it needs to go so that tests don't need to do so much require mocking everywhere PR-URL: https://github.com/npm/cli/pull/2772 Credit: @wraithgar Close: #2772 Reviewed-by: @ruyadorno
Diffstat (limited to 'test/lib/help-search.js')
-rw-r--r--test/lib/help-search.js22
1 files changed, 11 insertions, 11 deletions
diff --git a/test/lib/help-search.js b/test/lib/help-search.js
index f74e2f1ef..8b1ecd46e 100644
--- a/test/lib/help-search.js
+++ b/test/lib/help-search.js
@@ -24,7 +24,7 @@ const npm = {
}
let npmUsageArg = null
-const npmUsage = (arg) => {
+const npmUsage = (npm, arg) => {
npmUsageArg = arg
}
@@ -43,12 +43,12 @@ const globDir = {
const glob = (p, cb) =>
cb(null, Object.keys(globDir).map((file) => join(globRoot, file)))
-const helpSearch = requireInject('../../lib/help-search.js', {
- '../../lib/npm.js': npm,
+const HelpSearch = requireInject('../../lib/help-search.js', {
'../../lib/utils/npm-usage.js': npmUsage,
'../../lib/utils/output.js': output,
glob,
})
+const helpSearch = new HelpSearch(npm)
test('npm help-search', t => {
globRoot = t.testdir(globDir)
@@ -57,7 +57,7 @@ test('npm help-search', t => {
globRoot = null
})
- return helpSearch(['exec'], (err) => {
+ return helpSearch.exec(['exec'], (err) => {
if (err)
throw err
@@ -74,7 +74,7 @@ test('npm help-search multiple terms', t => {
globRoot = null
})
- return helpSearch(['run', 'script'], (err) => {
+ return helpSearch.exec(['run', 'script'], (err) => {
if (err)
throw err
@@ -92,7 +92,7 @@ test('npm help-search single result prints full section', t => {
globRoot = null
})
- return helpSearch(['does not exist in'], (err) => {
+ return helpSearch.exec(['does not exist in'], (err) => {
if (err)
throw err
@@ -111,7 +111,7 @@ test('npm help-search single result propagates error', t => {
globRoot = null
})
- return helpSearch(['does not exist in'], (err) => {
+ return helpSearch.exec(['does not exist in'], (err) => {
t.strictSame(npmHelpArgs, ['npm-install'], 'identified the correct man page and called help with it')
t.match(err, /help broke/, 'propagated the error from help')
t.end()
@@ -127,7 +127,7 @@ test('npm help-search long output', t => {
globRoot = null
})
- return helpSearch(['exec'], (err) => {
+ return helpSearch.exec(['exec'], (err) => {
if (err)
throw err
@@ -147,7 +147,7 @@ test('npm help-search long output with color', t => {
globRoot = null
})
- return helpSearch(['help-search'], (err) => {
+ return helpSearch.exec(['help-search'], (err) => {
if (err)
throw err
@@ -158,7 +158,7 @@ test('npm help-search long output with color', t => {
})
test('npm help-search no args', t => {
- return helpSearch([], (err) => {
+ return helpSearch.exec([], (err) => {
t.match(err, /npm help-search/, 'throws usage')
t.end()
})
@@ -172,7 +172,7 @@ test('npm help-search no matches', t => {
globRoot = null
})
- return helpSearch(['asdfasdf'], (err) => {
+ return helpSearch.exec(['asdfasdf'], (err) => {
if (err)
throw err