diff options
author | Gar <gar+gh@danger.computer> | 2021-02-25 02:54:50 +0300 |
---|---|---|
committer | Ruy Adorno <ruyadorno@hotmail.com> | 2021-03-05 00:05:08 +0300 |
commit | 4a5dd3a5a200b3f4f7b47168497d8e03dca3a2ca (patch) | |
tree | d34a1ea229b719c3cfbdce85899ceaf67b43e7ab /test/lib/update.js | |
parent | b33c760cea7fe2696d35b5530abc1b455980fef1 (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/update.js')
-rw-r--r-- | test/lib/update.js | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/test/lib/update.js b/test/lib/update.js index 993fbbab5..15195573f 100644 --- a/test/lib/update.js +++ b/test/lib/update.js @@ -16,7 +16,6 @@ const mocks = { '@npmcli/arborist': class { reify () {} }, - '../../lib/npm.js': npm, '../../lib/utils/reify-finish.js': noop, '../../lib/utils/usage.js': () => 'usage instructions', } @@ -47,15 +46,16 @@ t.test('no args', t => { } } - const update = requireInject('../../lib/update.js', { + const Update = requireInject('../../lib/update.js', { ...mocks, - '../../lib/utils/reify-finish.js': (arb) => { + '../../lib/utils/reify-finish.js': (npm, arb) => { t.isLike(arb, Arborist, 'should reify-finish with arborist instance') }, '@npmcli/arborist': Arborist, }) + const update = new Update(npm) - update([], err => { + update.exec([], err => { if (err) throw err }) @@ -80,15 +80,16 @@ t.test('with args', t => { } } - const update = requireInject('../../lib/update.js', { + const Update = requireInject('../../lib/update.js', { ...mocks, - '../../lib/utils/reify-finish.js': (arb) => { + '../../lib/utils/reify-finish.js': (npm, arb) => { t.isLike(arb, Arborist, 'should reify-finish with arborist instance') }, '@npmcli/arborist': Arborist, }) + const update = new Update(npm) - update(['ipt'], err => { + update.exec(['ipt'], err => { if (err) throw err }) @@ -100,7 +101,7 @@ t.test('update --depth=<number>', t => { npm.prefix = '/project/a' npm.flatOptions.depth = 1 - const update = requireInject('../../lib/update.js', { + const Update = requireInject('../../lib/update.js', { ...mocks, npmlog: { warn: (title, msg) => { @@ -113,8 +114,9 @@ t.test('update --depth=<number>', t => { }, }, }) + const update = new Update(npm) - update([], err => { + update.exec([], err => { if (err) throw err }) @@ -150,12 +152,13 @@ t.test('update --global', t => { reify () {} } - const update = requireInject('../../lib/update.js', { + const Update = requireInject('../../lib/update.js', { ...mocks, '@npmcli/arborist': Arborist, }) + const update = new Update(npm) - update([], err => { + update.exec([], err => { if (err) throw err }) |