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/version.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/version.js')
-rw-r--r--test/lib/version.js21
1 files changed, 10 insertions, 11 deletions
diff --git a/test/lib/version.js b/test/lib/version.js
index a69953bb8..e0e07f517 100644
--- a/test/lib/version.js
+++ b/test/lib/version.js
@@ -14,7 +14,6 @@ const npm = {
}
const mocks = {
libnpmversion: noop,
- '../../lib/npm.js': npm,
'../../lib/utils/output.js': (...msg) => {
for (const m of msg)
result.push(m)
@@ -22,7 +21,8 @@ const mocks = {
'../../lib/utils/usage.js': () => 'usage instructions',
}
-const version = requireInject('../../lib/version.js', mocks)
+const Version = requireInject('../../lib/version.js', mocks)
+const version = new Version(npm)
const _processVersions = process.versions
t.afterEach(cb => {
@@ -43,7 +43,7 @@ t.test('no args', t => {
npm.prefix = prefix
Object.defineProperty(process, 'versions', { value: { node: '1.0.0' } })
- version([], err => {
+ version.exec([], err => {
if (err)
throw err
@@ -62,7 +62,7 @@ t.test('no args', t => {
})
t.test('too many args', t => {
- version(['foo', 'bar'], err => {
+ version.exec(['foo', 'bar'], err => {
t.match(
err,
'usage instructions',
@@ -74,10 +74,8 @@ t.test('too many args', t => {
})
t.test('completion', async t => {
- const { completion } = version
-
const testComp = async (argv, expect) => {
- const res = await completion({ conf: { argv: { remain: argv } } })
+ const res = await version.completion({ conf: { argv: { remain: argv } } })
t.strictSame(res, expect, argv.join(' '))
}
@@ -100,7 +98,7 @@ t.test('failure reading package.json', t => {
const prefix = t.testdir({})
npm.prefix = prefix
- version([], err => {
+ version.exec([], err => {
if (err)
throw err
@@ -123,7 +121,7 @@ t.test('--json option', t => {
npm.prefix = prefix
Object.defineProperty(process, 'versions', { value: {} })
- version([], err => {
+ version.exec([], err => {
if (err)
throw err
t.deepEqual(
@@ -136,7 +134,7 @@ t.test('--json option', t => {
})
t.test('with one arg', t => {
- const version = requireInject('../../lib/version.js', {
+ const Version = requireInject('../../lib/version.js', {
...mocks,
libnpmversion: (arg, opts) => {
t.equal(arg, 'major', 'should forward expected value')
@@ -152,8 +150,9 @@ t.test('with one arg', t => {
return '4.0.0'
},
})
+ const version = new Version(npm)
- version(['major'], err => {
+ version.exec(['major'], err => {
if (err)
throw err
t.same(result, ['v4.0.0'], 'outputs the new version prefixed by the tagVersionPrefix')