UNPKG

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