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/bin.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/bin.js')
-rw-r--r-- | test/lib/bin.js | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/test/lib/bin.js b/test/lib/bin.js index c5ed2a91b..e96eb91af 100644 --- a/test/lib/bin.js +++ b/test/lib/bin.js @@ -5,14 +5,15 @@ test('bin', (t) => { t.plan(3) const dir = '/bin/dir' - const bin = requireInject('../../lib/bin.js', { - '../../lib/npm.js': { bin: dir, flatOptions: { global: false } }, + const Bin = requireInject('../../lib/bin.js', { '../../lib/utils/output.js': (output) => { t.equal(output, dir, 'prints the correct directory') }, }) - bin([], (err) => { + const bin = new Bin({ bin: dir, flatOptions: { global: false } }) + + bin.exec([], (err) => { t.ifError(err, 'npm bin') t.ok('should have printed directory') }) @@ -30,15 +31,16 @@ test('bin -g', (t) => { } const dir = '/bin/dir' - const bin = requireInject('../../lib/bin.js', { - '../../lib/npm.js': { bin: dir, flatOptions: { global: true } }, + const Bin = requireInject('../../lib/bin.js', { '../../lib/utils/path.js': [dir], '../../lib/utils/output.js': (output) => { t.equal(output, dir, 'prints the correct directory') }, }) - bin([], (err) => { + const bin = new Bin({ bin: dir, flatOptions: { global: true } }) + + bin.exec([], (err) => { t.ifError(err, 'npm bin') t.ok('should have printed directory') }) @@ -56,15 +58,15 @@ test('bin -g (not in path)', (t) => { } const dir = '/bin/dir' - const bin = requireInject('../../lib/bin.js', { - '../../lib/npm.js': { bin: dir, flatOptions: { global: true } }, + const Bin = requireInject('../../lib/bin.js', { '../../lib/utils/path.js': ['/not/my/dir'], '../../lib/utils/output.js': (output) => { t.equal(output, dir, 'prints the correct directory') }, }) + const bin = new Bin({ bin: dir, flatOptions: { global: true } }) - bin([], (err) => { + bin.exec([], (err) => { t.ifError(err, 'npm bin') t.ok('should have printed directory') }) |