summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/config-save.js
blob: 903bac7ae3a4a2fddee288a6c9919719c764f684 (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
85
86
87
var fs = require('fs')
var ini = require('ini')
var test = require('tap').test
var npmconf = require('../../lib/config/core.js')
var common = require('./00-config-setup.js')

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/',
  'init.version = 1.2.3',
  'proprietary-attribs = false',
  'npm:publishtest = true',
  '_npmjs.org:couch = https://admin:password@localhost:5984/registry',
  'npm-www:nocache = 1',
  'sign-git-tag = false',
  'message = v%s',
  'strict-ssl = false',
  '_auth = dXNlcm5hbWU6cGFzc3dvcmQ=',
  '',
  '[_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/',
  'init.version = 1.2.3',
  'proprietary-attribs = false',
  'npm:publishtest = true',
  '_npmjs.org:couch = https://admin:password@localhost:5984/registry',
  'npm-www:nocache = 1',
  'sign-git-tag = false',
  'message = v%s',
  'strict-ssl = false',
  '_auth = dXNlcm5hbWU6cGFzc3dvcmQ=',
  '',
  '[_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()
  })
})