Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

test

  • Loading branch information...
commit a6799f52b379c74790a09b0cd89deaa0b6a67474 1 parent 0dad382
Isaac Z. Schlueter authored August 14, 2012
1  .gitignore
... ...
@@ -0,0 +1 @@
  1
+/test/fixtures/userconfig-with-gc
27  test/00-setup.js
... ...
@@ -0,0 +1,27 @@
  1
+var path = require('path')
  2
+var userconfigSrc = path.resolve(__dirname, 'fixtures', 'userconfig')
  3
+exports.userconfig = userconfigSrc + '-with-gc'
  4
+exports.globalconfig = path.resolve(__dirname, 'fixtures', 'globalconfig')
  5
+exports.builtin = path.resolve(__dirname, 'fixtures', 'builtin')
  6
+
  7
+// set the userconfig in the env
  8
+// unset anything else that npm might be trying to foist on us
  9
+Object.keys(process.env).forEach(function (k) {
  10
+  if (k.match(/^npm_config_/i)) {
  11
+    delete process.env[k]
  12
+  }
  13
+})
  14
+process.env.npm_config_userconfig = exports.userconfig
  15
+process.env.npm_config_other_env_thing = 1000
  16
+process.env.random_env_var = 'asdf'
  17
+
  18
+if (module === require.main) {
  19
+  // set the globalconfig in the userconfig
  20
+  var fs = require('fs')
  21
+  var uc = fs.readFileSync(userconfigSrc)
  22
+  var gcini = 'globalconfig = ' + exports.globalconfig + '\n'
  23
+  fs.writeFileSync(exports.userconfig, gcini + uc)
  24
+
  25
+  console.log('0..1')
  26
+  console.log('ok 1 setup done')
  27
+}
70  test/basic.js
... ...
@@ -0,0 +1,70 @@
  1
+var test = require('tap').test
  2
+var npmconf = require('../npmconf.js')
  3
+var common = require('./00-setup.js')
  4
+
  5
+var ucData =
  6
+  { globalconfig: common.globalconfig,
  7
+    email: 'i@izs.me',
  8
+    'env-thing': 'asdf',
  9
+    'init.author.name': 'Isaac Z. Schlueter',
  10
+    'init.author.email': 'i@izs.me',
  11
+    'init.author.url': 'http://blog.izs.me/',
  12
+    'proprietary-attribs': false,
  13
+    'npm:publishtest': true,
  14
+    '_npmjs.org:couch': 'https://admin:password@localhost:5984/registry',
  15
+    _auth: 'dXNlcm5hbWU6cGFzc3dvcmQ=',
  16
+    'npm-www:nocache': '1',
  17
+    nodedir: '/Users/isaacs/dev/js/node-v0.8',
  18
+    'sign-git-tag': true,
  19
+    message: 'v%s',
  20
+    'strict-ssl': false,
  21
+    'tmp': process.env.HOME + '/.tmp',
  22
+    _token:
  23
+     { AuthSession: 'yabba-dabba-doodle',
  24
+       version: '1',
  25
+       expires: '1345001053415',
  26
+       path: '/',
  27
+       httponly: true } }
  28
+
  29
+var envData = { userconfig: common.userconfig, 'other-env-thing': '1000' }
  30
+
  31
+var gcData = { 'package-config:foo': 'boo' }
  32
+
  33
+var biData = {}
  34
+
  35
+var cli = { foo: 'bar' }
  36
+
  37
+var expectList =
  38
+[ cli,
  39
+  envData,
  40
+  ucData,
  41
+  gcData,
  42
+  biData ]
  43
+
  44
+var expectSources =
  45
+{ cli: { data: cli },
  46
+  env:
  47
+   { data: envData,
  48
+     source: envData,
  49
+     prefix: '' },
  50
+  user:
  51
+   { path: common.userconfig,
  52
+     type: 'ini',
  53
+     data: ucData },
  54
+  global:
  55
+   { path: common.globalconfig,
  56
+     type: 'ini',
  57
+     data: gcData },
  58
+  builtin: { data: biData } }
  59
+
  60
+test('no builtin', function (t) {
  61
+  npmconf.load(cli, function (er, conf) {
  62
+    if (er) throw er
  63
+    t.same(conf.list, expectList)
  64
+    t.same(conf.sources, expectSources)
  65
+    t.same(npmconf.rootConf.list, [])
  66
+    t.equal(npmconf.rootConf.root, npmconf.defs.defaults)
  67
+    t.equal(conf.root, npmconf.defs.defaults)
  68
+    t.end()
  69
+  })
  70
+})
70  test/builtin.js
... ...
@@ -0,0 +1,70 @@
  1
+var test = require('tap').test
  2
+var npmconf = require('../npmconf.js')
  3
+var common = require('./00-setup.js')
  4
+
  5
+var ucData =
  6
+  { globalconfig: common.globalconfig,
  7
+    email: 'i@izs.me',
  8
+    'env-thing': 'asdf',
  9
+    'init.author.name': 'Isaac Z. Schlueter',
  10
+    'init.author.email': 'i@izs.me',
  11
+    'init.author.url': 'http://blog.izs.me/',
  12
+    'proprietary-attribs': false,
  13
+    'npm:publishtest': true,
  14
+    '_npmjs.org:couch': 'https://admin:password@localhost:5984/registry',
  15
+    _auth: 'dXNlcm5hbWU6cGFzc3dvcmQ=',
  16
+    'npm-www:nocache': '1',
  17
+    nodedir: '/Users/isaacs/dev/js/node-v0.8',
  18
+    'sign-git-tag': true,
  19
+    message: 'v%s',
  20
+    'strict-ssl': false,
  21
+    'tmp': process.env.HOME + '/.tmp',
  22
+    _token:
  23
+     { AuthSession: 'yabba-dabba-doodle',
  24
+       version: '1',
  25
+       expires: '1345001053415',
  26
+       path: '/',
  27
+       httponly: true } }
  28
+
  29
+var envData = { userconfig: common.userconfig, 'other-env-thing': '1000' }
  30
+
  31
+var gcData = { 'package-config:foo': 'boo' }
  32
+
  33
+var biData = { 'builtin-config': true }
  34
+
  35
+var cli = { foo: 'bar' }
  36
+
  37
+var expectList =
  38
+[ cli,
  39
+  envData,
  40
+  ucData,
  41
+  gcData,
  42
+  biData ]
  43
+
  44
+var expectSources =
  45
+{ cli: { data: cli },
  46
+  env:
  47
+   { data: envData,
  48
+     source: envData,
  49
+     prefix: '' },
  50
+  user:
  51
+   { path: common.userconfig,
  52
+     type: 'ini',
  53
+     data: ucData },
  54
+  global:
  55
+   { path: common.globalconfig,
  56
+     type: 'ini',
  57
+     data: gcData },
  58
+  builtin: { data: biData } }
  59
+
  60
+test('with builtin', function (t) {
  61
+  npmconf.load(cli, common.builtin, function (er, conf) {
  62
+    if (er) throw er
  63
+    t.same(conf.list, expectList)
  64
+    t.same(conf.sources, expectSources)
  65
+    t.same(npmconf.rootConf.list, [])
  66
+    t.equal(npmconf.rootConf.root, npmconf.defs.defaults)
  67
+    t.equal(conf.root, npmconf.defs.defaults)
  68
+    t.end()
  69
+  })
  70
+})
1  test/fixtures/builtin
... ...
@@ -0,0 +1 @@
  1
+builtin-config = true
1  test/fixtures/globalconfig
... ...
@@ -0,0 +1 @@
  1
+package-config:foo = boo
22  test/fixtures/userconfig
... ...
@@ -0,0 +1,22 @@
  1
+email = i@izs.me
  2
+env-thing = ${random_env_var}
  3
+init.author.name = Isaac Z. Schlueter
  4
+init.author.email = i@izs.me
  5
+init.author.url = http://blog.izs.me/
  6
+proprietary-attribs = false
  7
+npm:publishtest = true
  8
+_npmjs.org:couch = https://admin:password@localhost:5984/registry
  9
+_auth = dXNlcm5hbWU6cGFzc3dvcmQ=
  10
+npm-www:nocache = 1
  11
+nodedir = /Users/isaacs/dev/js/node-v0.8
  12
+sign-git-tag = true
  13
+message = v%s
  14
+strict-ssl = false
  15
+tmp = ~/.tmp
  16
+
  17
+[_token]
  18
+AuthSession = yabba-dabba-doodle
  19
+version = 1
  20
+expires = 1345001053415
  21
+path = /
  22
+httponly = true
48  test/save.js
... ...
@@ -0,0 +1,48 @@
  1
+var test = require('tap').test
  2
+var npmconf = require('../npmconf.js')
  3
+var common = require('./00-setup.js')
  4
+var fs = require('fs')
  5
+var ini = require('ini')
  6
+var expect =
  7
+  [ 'globalconfig = /Users/isaacs/dev/js/npmconf/test/fixtures/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
+    '',
  22
+    '[_token]',
  23
+    'AuthSession = yabba-dabba-doodle',
  24
+    'version = 1',
  25
+    'expires = 1345001053415',
  26
+    'path = /',
  27
+    'httponly = true',
  28
+    '' ].join('\n')
  29
+
  30
+test('saving configs', function (t) {
  31
+  npmconf.load(function (er, conf) {
  32
+    if (er)
  33
+      throw er
  34
+    conf.set('sign-git-tag', false, 'user')
  35
+    conf.del('nodedir')
  36
+    conf.del('tmp')
  37
+    var foundConf = ini.stringify(conf.sources.user.data)
  38
+    t.equal(foundConf, expect)
  39
+    conf.save('user', function (er) {
  40
+      if (er)
  41
+        throw er
  42
+      var uc = fs.readFileSync(conf.get('userconfig'), 'utf8')
  43
+      t.equal(uc, expect)
  44
+      t.end()
  45
+    })
  46
+  })
  47
+})
  48
+

0 notes on commit a6799f5

Please sign in to comment.
Something went wrong with that request. Please try again.