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/link.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/link.js')
-rw-r--r-- | test/lib/link.js | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/test/lib/link.js b/test/lib/link.js index b1048427d..be7af3f52 100644 --- a/test/lib/link.js +++ b/test/lib/link.js @@ -40,11 +40,11 @@ const printLinks = async (opts) => { } const mocks = { - '../../lib/npm.js': npm, '../../lib/utils/reify-output.js': () => reifyOutput(), } -const link = requireInject('../../lib/link.js', mocks) +const Link = requireInject('../../lib/link.js', mocks) +const link = new Link(npm) t.test('link to globalDir when in current working dir of pkg and no args', (t) => { t.plan(2) @@ -83,7 +83,7 @@ t.test('link to globalDir when in current working dir of pkg and no args', (t) = t.matchSnapshot(links, 'should create a global link to current pkg') } - link([], (err) => { + link.exec([], (err) => { t.ifError(err, 'should not error out') }) }) @@ -185,7 +185,7 @@ t.test('link global linked pkg to local nm when using args', (t) => { // - @myscope/bar: prev installed scoped package available in globalDir // - a: prev installed package available in globalDir // - file:./link-me-too: pkg that needs to be reified in globalDir first - link([ + link.exec([ 'test-pkg-link', '@myscope/linked', '@myscope/bar', @@ -254,7 +254,7 @@ t.test('link pkg already in global space', (t) => { // - @myscope/bar: prev installed scoped package available in globalDir // - a: prev installed package available in globalDir // - file:./link-me-too: pkg that needs to be reified in globalDir first - link(['@myscope/linked'], (err) => { + link.exec(['@myscope/linked'], (err) => { t.ifError(err, 'should not error out') }) }) @@ -312,7 +312,7 @@ t.test('link pkg already in global space when prefix is a symlink', (t) => { t.matchSnapshot(links, 'should create a local symlink to global pkg') } - link(['@myscope/linked'], (err) => { + link.exec(['@myscope/linked'], (err) => { t.ifError(err, 'should not error out') }) }) @@ -341,21 +341,18 @@ t.test('completion', async t => { t.end() }) -t.test('--global option', async t => { +t.test('--global option', t => { const _config = npm.config npm.config = { get () { return true } } - try { - await link([]) - t.fail('should not get here') - } catch (err) { + link.exec([], (err) => { npm.config = _config t.match( err.message, /link should never be --global/, 'should throw an useful error' ) - } - t.end() + t.end() + }) }) |