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 'init.version = 1.2.3',
14 'proprietary-attribs = false',
15 'npm:publishtest = true',
16 '_npmjs.org:couch = https://admin:password@localhost:5984/registry',
17 'npm-www:nocache = 1',
18 'sign-git-tag = false',
19 'message = v%s',
20 'strict-ssl = false',
21 '_auth = dXNlcm5hbWU6cGFzc3dvcmQ=',
22 '',
23 '[_token]',
24 'AuthSession = yabba-dabba-doodle',
25 'version = 1',
26 'expires = 1345001053415',
27 'path = /',
28 'httponly = true',
29 '' ].join('\n')
30var expectFile =
31 [ 'globalconfig = ' + common.globalconfig,
32 'email = i@izs.me',
33 'env-thing = asdf',
34 'init.author.name = Isaac Z. Schlueter',
35 'init.author.email = i@izs.me',
36 'init.author.url = http://blog.izs.me/',
37 'init.version = 1.2.3',
38 'proprietary-attribs = false',
39 'npm:publishtest = true',
40 '_npmjs.org:couch = https://admin:password@localhost:5984/registry',
41 'npm-www:nocache = 1',
42 'sign-git-tag = false',
43 'message = v%s',
44 'strict-ssl = false',
45 '_auth = dXNlcm5hbWU6cGFzc3dvcmQ=',
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})