11cb0ef41Sopenharmony_ciconst t = require('tap') 21cb0ef41Sopenharmony_ciconst fs = require('fs/promises') 31cb0ef41Sopenharmony_ciconst mockNpm = require('../../fixtures/mock-npm') 41cb0ef41Sopenharmony_ciconst { join } = require('path') 51cb0ef41Sopenharmony_ciconst { cleanNewlines } = require('../../fixtures/clean-snapshot') 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_cit.test('no args', async t => { 81cb0ef41Sopenharmony_ci const { npm } = await mockNpm(t) 91cb0ef41Sopenharmony_ci t.rejects(npm.exec('set', []), /Usage:/, 'prints usage') 101cb0ef41Sopenharmony_ci}) 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cit.test('test-config-item', async t => { 131cb0ef41Sopenharmony_ci const { npm, home, joinedOutput } = await mockNpm(t, { 141cb0ef41Sopenharmony_ci homeDir: { 151cb0ef41Sopenharmony_ci '.npmrc': 'original-config-test=original value', 161cb0ef41Sopenharmony_ci }, 171cb0ef41Sopenharmony_ci }) 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci t.equal( 201cb0ef41Sopenharmony_ci npm.config.get('original-config-test'), 211cb0ef41Sopenharmony_ci 'original value', 221cb0ef41Sopenharmony_ci 'original config is set from npmrc' 231cb0ef41Sopenharmony_ci ) 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci t.not( 261cb0ef41Sopenharmony_ci npm.config.get('fund'), 271cb0ef41Sopenharmony_ci false, 281cb0ef41Sopenharmony_ci 'config is not already new value' 291cb0ef41Sopenharmony_ci ) 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci await npm.exec('set', ['fund=true']) 321cb0ef41Sopenharmony_ci t.equal(joinedOutput(), '', 'outputs nothing') 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci t.equal( 351cb0ef41Sopenharmony_ci npm.config.get('fund'), 361cb0ef41Sopenharmony_ci true, 371cb0ef41Sopenharmony_ci 'config is set to new value' 381cb0ef41Sopenharmony_ci ) 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci t.equal( 411cb0ef41Sopenharmony_ci cleanNewlines(await fs.readFile(join(home, '.npmrc'), 'utf-8')), 421cb0ef41Sopenharmony_ci [ 431cb0ef41Sopenharmony_ci 'original-config-test=original value', 441cb0ef41Sopenharmony_ci 'fund=true', 451cb0ef41Sopenharmony_ci '', 461cb0ef41Sopenharmony_ci ].join('\n'), 471cb0ef41Sopenharmony_ci 'npmrc is written with new value' 481cb0ef41Sopenharmony_ci ) 491cb0ef41Sopenharmony_ci}) 50