diff options
author | Gar <gar+gh@danger.computer> | 2021-05-07 23:10:48 +0300 |
---|---|---|
committer | Gar <gar+gh@danger.computer> | 2021-05-10 23:55:27 +0300 |
commit | f3a662fcd869653f9753aef3d40cc96ed28ed509 (patch) | |
tree | d207fb53ba11a9c4b4786cfa6f1ea217b7f235bc /test | |
parent | 285976fd12f037f59da47307d98df7ebda5278d9 (diff) |
fix(tests): use config defaults
The mocked npm now uses all config defaults, ensuring we don't have bugs
from the disconnect between our currently heavily mocked tests and
reality. Eventually the npm mock will be closer to reality, this moves
the needle.
PR-URL: https://github.com/npm/cli/pull/3211
Credit: @wraithgar
Close: #3211
Reviewed-by: @ruyadorno
Diffstat (limited to 'test')
-rw-r--r-- | test/fixtures/mock-npm.js | 8 | ||||
-rw-r--r-- | test/lib/dist-tag.js | 9 | ||||
-rw-r--r-- | test/lib/view.js | 20 |
3 files changed, 15 insertions, 22 deletions
diff --git a/test/fixtures/mock-npm.js b/test/fixtures/mock-npm.js index 01f482bde..aa8d44020 100644 --- a/test/fixtures/mock-npm.js +++ b/test/fixtures/mock-npm.js @@ -2,6 +2,8 @@ // npm.config You still need a separate flatOptions but this is the first step // to eventually just using npm itself +const realConfig = require('../../lib/utils/config') + const mockLog = { clearProgress: () => {}, disableProgress: () => {}, @@ -25,10 +27,10 @@ const mockNpm = (base = {}) => { config: { // for now just set `find` to what config.find should return // this works cause `find` is not an existing config entry - find: (k) => config[k], - get: (k) => config[k], + find: (k) => ({...realConfig.defaults, ...config})[k], + get: (k) => ({...realConfig.defaults, ...config})[k], set: (k, v) => config[k] = v, - list: [config] + list: [{ ...realConfig.defaults, ...config}] }, } } diff --git a/test/lib/dist-tag.js b/test/lib/dist-tag.js index 701bdc6e4..6bc17168c 100644 --- a/test/lib/dist-tag.js +++ b/test/lib/dist-tag.js @@ -68,10 +68,9 @@ const DistTag = t.mock('../../lib/dist-tag.js', { }, }) +const config = {} const npm = mockNpm({ - config: { - global: false, - }, + config, output: msg => { result = result ? [result, msg].join('\n') : msg }, @@ -349,6 +348,10 @@ t.test('add using valid semver range as name', (t) => { t.test('add missing args', (t) => { npm.prefix = t.testdir({}) + config.tag = '' + t.teardown(() => { + delete config.tag + }) distTag.exec(['add', '@scoped/another@7.7.7'], (err) => { t.matchSnapshot(err, 'should exit usage error message') t.end() diff --git a/test/lib/view.js b/test/lib/view.js index eb2beb9ff..3816ce023 100644 --- a/test/lib/view.js +++ b/test/lib/view.js @@ -248,7 +248,7 @@ t.test('should log package info', t => { }, }) const npm = mockNpm({ - config: { global: false }, + config: { unicode: false }, }) const view = new View(npm) @@ -268,10 +268,7 @@ t.test('should log package info', t => { }, }) const unicodeNpm = mockNpm({ - config: { - global: false, - unicode: true, - }, + config: { unicode: true }, }) const viewUnicode = new ViewUnicode(unicodeNpm) @@ -358,7 +355,6 @@ t.test('should log info of package in current working dir', t => { prefix: testDir, config: { tag: '1.0.0', - global: false, }, }) const view = new View(npm) @@ -389,7 +385,6 @@ t.test('should log info by field name', t => { const jsonNpm = mockNpm({ config: { json: true, - global: false, }, }) @@ -400,9 +395,7 @@ t.test('should log info by field name', t => { packument, }, }) - const npm = mockNpm({ - config: { global: false }, - }) + const npm = mockNpm() const view = new View(npm) t.test('readme', t => { @@ -489,7 +482,6 @@ t.test('throw ENOENT error if package.json misisng', (t) => { const View = t.mock('../../lib/view.js') const npm = mockNpm({ prefix: testDir, - config: { global: false }, }) const view = new View(npm) view.exec([], (err) => { @@ -506,7 +498,6 @@ t.test('throw EJSONPARSE error if package.json not json', (t) => { const View = t.mock('../../lib/view.js') const npm = mockNpm({ prefix: testDir, - config: { global: false }, }) const view = new View(npm) view.exec([], (err) => { @@ -523,7 +514,6 @@ t.test('throw error if package.json has no name', (t) => { const View = t.mock('../../lib/view.js') const npm = mockNpm({ prefix: testDir, - config: { global: false }, }) const view = new View(npm) view.exec([], (err) => { @@ -541,7 +531,6 @@ t.test('throws when unpublished', (t) => { const npm = mockNpm({ config: { tag: '1.0.1', - global: false, }, }) const view = new View(npm) @@ -581,6 +570,7 @@ t.test('workspaces', t => { }, }) const config = { + unicode: false, tag: 'latest', } let warnMsg @@ -684,7 +674,6 @@ t.test('completion', async t => { const npm = mockNpm({ config: { tag: '1.0.1', - global: false, }, }) const view = new View(npm) @@ -700,7 +689,6 @@ t.test('no registry completion', async t => { const npm = mockNpm({ config: { tag: '1.0.1', - global: false, }, }) const view = new View(npm) |