1const t = require('tap') 2const fs = require('fs/promises') 3const mockNpm = require('../../fixtures/mock-npm') 4const { join } = require('path') 5const { cleanNewlines } = require('../../fixtures/clean-snapshot') 6 7t.test('no args', async t => { 8 const { npm } = await mockNpm(t) 9 t.rejects(npm.exec('set', []), /Usage:/, 'prints usage') 10}) 11 12t.test('test-config-item', async t => { 13 const { npm, home, joinedOutput } = await mockNpm(t, { 14 homeDir: { 15 '.npmrc': 'original-config-test=original value', 16 }, 17 }) 18 19 t.equal( 20 npm.config.get('original-config-test'), 21 'original value', 22 'original config is set from npmrc' 23 ) 24 25 t.not( 26 npm.config.get('fund'), 27 false, 28 'config is not already new value' 29 ) 30 31 await npm.exec('set', ['fund=true']) 32 t.equal(joinedOutput(), '', 'outputs nothing') 33 34 t.equal( 35 npm.config.get('fund'), 36 true, 37 'config is set to new value' 38 ) 39 40 t.equal( 41 cleanNewlines(await fs.readFile(join(home, '.npmrc'), 'utf-8')), 42 [ 43 'original-config-test=original value', 44 'fund=true', 45 '', 46 ].join('\n'), 47 'npmrc is written with new value' 48 ) 49}) 50