summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/npmconf/test/save.js
blob: 64b114449eed74799a435f68035863aba63e0c6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
var test = require('tap').test
var npmconf = require('../npmconf.js')
var common = require('./00-setup.js')
var fs = require('fs')
var ini = require('ini')
var expectConf =
  [ 'globalconfig = ' + common.globalconfig,
    'email = i@izs.me',
    'env-thing = asdf',
    'init.author.name = Isaac Z. Schlueter',
    'init.author.email = i@izs.me',
    'init.author.url = http://blog.izs.me/',
    'proprietary-attribs = false',
    'npm:publishtest = true',
    '_npmjs.org:couch = https://admin:password@localhost:5984/registry',
    '_auth = dXNlcm5hbWU6cGFzc3dvcmQ=',
    'npm-www:nocache = 1',
    'sign-git-tag = false',
    'message = v%s',
    'strict-ssl = false',
    'username = username',
    '_password = password',
    '',
    '[_token]',
    'AuthSession = yabba-dabba-doodle',
    'version = 1',
    'expires = 1345001053415',
    'path = /',
    'httponly = true',
    '' ].join('\n')
var expectFile =
  [ 'globalconfig = ' + common.globalconfig,
    'email = i@izs.me',
    'env-thing = asdf',
    'init.author.name = Isaac Z. Schlueter',
    'init.author.email = i@izs.me',
    'init.author.url = http://blog.izs.me/',
    'proprietary-attribs = false',
    'npm:publishtest = true',
    '_npmjs.org:couch = https://admin:password@localhost:5984/registry',
    '_auth = dXNlcm5hbWU6cGFzc3dvcmQ=',
    'npm-www:nocache = 1',
    'sign-git-tag = false',
    'message = v%s',
    'strict-ssl = false',
    '',
    '[_token]',
    'AuthSession = yabba-dabba-doodle',
    'version = 1',
    'expires = 1345001053415',
    'path = /',
    'httponly = true',
    '' ].join('\n')

test('saving configs', function (t) {
  npmconf.load(function (er, conf) {
    if (er)
      throw er
    conf.set('sign-git-tag', false, 'user')
    conf.del('nodedir')
    conf.del('tmp')
    var foundConf = ini.stringify(conf.sources.user.data)
    t.same(ini.parse(foundConf), ini.parse(expectConf))
    fs.unlinkSync(common.userconfig)
    conf.save('user', function (er) {
      if (er)
        throw er
      var uc = fs.readFileSync(conf.get('userconfig'), 'utf8')
      t.same(ini.parse(uc), ini.parse(expectFile))
      t.end()
    })
  })
})

test('setting prefix', function (t) {
  npmconf.load(function (er, conf) {
    if (er)
      throw er

    conf.prefix = 'newvalue'
    t.same(conf.prefix, 'newvalue');
    t.end();
  })
})