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/repo.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/repo.js')
-rw-r--r--test/lib/repo.js11
1 files changed, 6 insertions, 5 deletions
diff --git a/test/lib/repo.js b/test/lib/repo.js
index 3367f7c88..7abda55ca 100644
--- a/test/lib/repo.js
+++ b/test/lib/repo.js
@@ -108,16 +108,17 @@ const pacote = {
// keep a tally of which urls got opened
const opened = {}
-const openUrl = (url, errMsg, cb) => {
+const openUrl = async (npm, url, errMsg, cb) => {
opened[url] = opened[url] || 0
opened[url]++
process.nextTick(cb)
}
-const repo = requireInject('../../lib/repo.js', {
+const Repo = requireInject('../../lib/repo.js', {
pacote,
'../../lib/utils/open-url.js': openUrl,
})
+const repo = new Repo({ flatOptions: {} })
t.test('open repo urls', t => {
const expect = {
@@ -150,7 +151,7 @@ t.test('open repo urls', t => {
t.plan(keys.length)
keys.forEach(pkg => {
t.test(pkg, t => {
- repo([pkg], (er) => {
+ repo.exec([pkg], (er) => {
if (er)
throw er
const url = expect[pkg]
@@ -173,7 +174,7 @@ t.test('fail if cannot figure out repo url', t => {
cases.forEach(pkg => {
t.test(pkg, t => {
- repo([pkg], er => {
+ repo.exec([pkg], er => {
t.match(er, { pkgid: pkg })
t.end()
})
@@ -182,7 +183,7 @@ t.test('fail if cannot figure out repo url', t => {
})
t.test('open default package if none specified', t => {
- repo([], (er) => {
+ repo.exec([], (er) => {
if (er)
throw er
t.equal(opened['https://example.com/thispkg'], 2, 'opened expected url', {opened})