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/dist-tag.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/dist-tag.js')
-rw-r--r--test/lib/dist-tag.js49
1 files changed, 25 insertions, 24 deletions
diff --git a/test/lib/dist-tag.js b/test/lib/dist-tag.js
index c18935230..b761fb103 100644
--- a/test/lib/dist-tag.js
+++ b/test/lib/dist-tag.js
@@ -48,7 +48,7 @@ const logger = (...msgs) => {
log += '\n'
}
-const distTag = requireInject('../../lib/dist-tag.js', {
+const DistTag = requireInject('../../lib/dist-tag.js', {
npmlog: {
error: logger,
info: logger,
@@ -58,26 +58,27 @@ const distTag = requireInject('../../lib/dist-tag.js', {
get 'npm-registry-fetch' () {
return npmRegistryFetchMock
},
- '../../lib/npm.js': {
- flatOptions: _flatOptions,
- config: {
- get (key) {
- return _flatOptions[key]
- },
- },
- },
'../../lib/utils/output.js': msg => {
result = msg
},
})
+const distTag = new DistTag({
+ flatOptions: _flatOptions,
+ config: {
+ get (key) {
+ return _flatOptions[key]
+ },
+ },
+})
+
test('ls in current package', (t) => {
prefix = t.testdir({
'package.json': JSON.stringify({
name: '@scoped/pkg',
}),
})
- distTag(['ls'], (err) => {
+ distTag.exec(['ls'], (err) => {
t.ifError(err, 'npm dist-tags ls')
t.matchSnapshot(
result,
@@ -95,7 +96,7 @@ test('no args in current package', (t) => {
name: '@scoped/pkg',
}),
})
- distTag([], (err) => {
+ distTag.exec([], (err) => {
t.ifError(err, 'npm dist-tags ls')
t.matchSnapshot(
result,
@@ -109,7 +110,7 @@ test('no args in current package', (t) => {
test('borked cmd usage', (t) => {
prefix = t.testdir({})
- distTag(['borked', '@scoped/pkg'], (err) => {
+ distTag.exec(['borked', '@scoped/pkg'], (err) => {
t.matchSnapshot(err, 'should show usage error')
result = ''
log = ''
@@ -119,7 +120,7 @@ test('borked cmd usage', (t) => {
test('ls on named package', (t) => {
prefix = t.testdir({})
- distTag(['ls', '@scoped/another'], (err) => {
+ distTag.exec(['ls', '@scoped/another'], (err) => {
t.ifError(err, 'npm dist-tags ls')
t.matchSnapshot(
result,
@@ -133,7 +134,7 @@ test('ls on named package', (t) => {
test('ls on missing package', (t) => {
prefix = t.testdir({})
- distTag(['ls', 'foo'], (err) => {
+ distTag.exec(['ls', 'foo'], (err) => {
t.matchSnapshot(
log,
'should log no dist-tag found msg'
@@ -154,7 +155,7 @@ test('ls on missing name in current package', (t) => {
version: '1.0.0',
}),
})
- distTag(['ls'], (err) => {
+ distTag.exec(['ls'], (err) => {
t.matchSnapshot(
err,
'should throw usage error message'
@@ -167,7 +168,7 @@ test('ls on missing name in current package', (t) => {
test('only named package arg', (t) => {
prefix = t.testdir({})
- distTag(['@scoped/another'], (err) => {
+ distTag.exec(['@scoped/another'], (err) => {
t.ifError(err, 'npm dist-tags ls')
t.matchSnapshot(
result,
@@ -186,7 +187,7 @@ test('add new tag', (t) => {
t.equal(opts.body, '7.7.7', 'should point to expected version')
}
prefix = t.testdir({})
- distTag(['add', '@scoped/another@7.7.7', 'c'], (err) => {
+ distTag.exec(['add', '@scoped/another@7.7.7', 'c'], (err) => {
t.ifError(err, 'npm dist-tags add')
t.matchSnapshot(
result,
@@ -201,7 +202,7 @@ test('add new tag', (t) => {
test('add using valid semver range as name', (t) => {
prefix = t.testdir({})
- distTag(['add', '@scoped/another@7.7.7', '1.0.0'], (err) => {
+ distTag.exec(['add', '@scoped/another@7.7.7', '1.0.0'], (err) => {
t.match(
err,
/Error: Tag name must not be a valid SemVer range: 1.0.0/,
@@ -219,7 +220,7 @@ test('add using valid semver range as name', (t) => {
test('add missing args', (t) => {
prefix = t.testdir({})
- distTag(['add', '@scoped/another@7.7.7'], (err) => {
+ distTag.exec(['add', '@scoped/another@7.7.7'], (err) => {
t.matchSnapshot(err, 'should exit usage error message')
result = ''
log = ''
@@ -229,7 +230,7 @@ test('add missing args', (t) => {
test('add missing pkg name', (t) => {
prefix = t.testdir({})
- distTag(['add', null], (err) => {
+ distTag.exec(['add', null], (err) => {
t.matchSnapshot(err, 'should exit usage error message')
result = ''
log = ''
@@ -239,7 +240,7 @@ test('add missing pkg name', (t) => {
test('set existing version', (t) => {
prefix = t.testdir({})
- distTag(['set', '@scoped/another@0.6.0', 'b'], (err) => {
+ distTag.exec(['set', '@scoped/another@0.6.0', 'b'], (err) => {
t.ifError(err, 'npm dist-tags set')
t.matchSnapshot(
log,
@@ -256,7 +257,7 @@ test('remove existing tag', (t) => {
t.equal(opts.method, 'DELETE', 'should trigger request to remove tag')
}
prefix = t.testdir({})
- distTag(['rm', '@scoped/another', 'c'], (err) => {
+ distTag.exec(['rm', '@scoped/another', 'c'], (err) => {
t.ifError(err, 'npm dist-tags rm')
t.matchSnapshot(log, 'should log remove info')
t.matchSnapshot(result, 'should return success msg')
@@ -269,7 +270,7 @@ test('remove existing tag', (t) => {
test('remove non-existing tag', (t) => {
prefix = t.testdir({})
- distTag(['rm', '@scoped/another', 'nonexistent'], (err) => {
+ distTag.exec(['rm', '@scoped/another', 'nonexistent'], (err) => {
t.match(
err,
/Error: nonexistent is not a dist-tag on @scoped\/another/,
@@ -284,7 +285,7 @@ test('remove non-existing tag', (t) => {
test('remove missing pkg name', (t) => {
prefix = t.testdir({})
- distTag(['rm', null], (err) => {
+ distTag.exec(['rm', null], (err) => {
t.matchSnapshot(err, 'should exit usage error message')
result = ''
log = ''