1var fs = require('fs') 2var ini = require('ini') 3var t = require('tap') 4const test = t.test 5var common = require('../common-config.js') 6var commonTap = require('../common-tap.js') 7var npmconf = require('../../lib/config/core.js') 8 9var expectConf = [ 10 'globalconfig = ' + common.globalconfig, 11 'email = i@izs.me', 12 'env-thing = foo', 13 'init.author.name = Isaac Z. Schlueter', 14 'init.author.email = i@izs.me', 15 'init.author.url = http://blog.izs.me/', 16 'init.version = 1.2.3', 17 'npm:publishtest = true', 18 '_npmjs.org:couch = https://admin:password@localhost:5984/registry', 19 'npm-www:nocache = 1', 20 'sign-git-tag = false', 21 'message = v%s', 22 'strict-ssl = false', 23 '_auth = dXNlcm5hbWU6cGFzc3dvcmQ=', 24 '', 25 '[_token]', 26 'AuthSession = yabba-dabba-doodle', 27 'version = 1', 28 'expires = 1345001053415', 29 'path = /', 30 'httponly = true', 31 '' 32].join('\n') 33 34var expectFile = [ 35 'globalconfig = ' + common.globalconfig, 36 'email = i@izs.me', 37 'env-thing = foo', 38 'init.author.name = Isaac Z. Schlueter', 39 'init.author.email = i@izs.me', 40 'init.author.url = http://blog.izs.me/', 41 'init.version = 1.2.3', 42 'npm:publishtest = true', 43 '_npmjs.org:couch = https://admin:password@localhost:5984/registry', 44 'npm-www:nocache = 1', 45 'sign-git-tag = false', 46 'message = v%s', 47 'strict-ssl = false', 48 '_auth = dXNlcm5hbWU6cGFzc3dvcmQ=', 49 '', 50 '[_token]', 51 'AuthSession = yabba-dabba-doodle', 52 'version = 1', 53 'expires = 1345001053415', 54 'path = /', 55 'httponly = true', 56 '' 57].join('\n') 58 59const userconfig = commonTap.pkg + '/userconfig' 60fs.writeFileSync(userconfig, fs.readFileSync(common.userconfig)) 61process.env.npm_config_userconfig = userconfig 62 63test('saving configs', function (t) { 64 npmconf.load(function (er, conf) { 65 if (er) throw er 66 67 conf.set('sign-git-tag', false, 'user') 68 conf.del('nodedir') 69 conf.del('tmp') 70 var foundConf = ini.stringify(conf.sources.user.data) 71 t.same(ini.parse(foundConf), ini.parse(expectConf)) 72 fs.unlinkSync(common.userconfig) 73 conf.save('user', function (er) { 74 if (er) throw er 75 76 var uc = fs.readFileSync(conf.get('userconfig'), 'utf8') 77 t.same(ini.parse(uc), ini.parse(expectFile)) 78 t.end() 79 }) 80 }) 81}) 82 83test('setting prefix', function (t) { 84 npmconf.load(function (er, conf) { 85 if (er) throw er 86 87 conf.prefix = 'newvalue' 88 t.same(conf.prefix, 'newvalue') 89 t.end() 90 }) 91}) 92