Permalink
Browse files

test

  • Loading branch information...
isaacs committed Aug 15, 2012
1 parent 0dad382 commit a6799f52b379c74790a09b0cd89deaa0b6a67474
Showing with 240 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +27 −0 test/00-setup.js
  3. +70 −0 test/basic.js
  4. +70 −0 test/builtin.js
  5. +1 −0 test/fixtures/builtin
  6. +1 −0 test/fixtures/globalconfig
  7. +22 −0 test/fixtures/userconfig
  8. +48 −0 test/save.js
View
@@ -0,0 +1 @@
+/test/fixtures/userconfig-with-gc
View
@@ -0,0 +1,27 @@
+var path = require('path')
+var userconfigSrc = path.resolve(__dirname, 'fixtures', 'userconfig')
+exports.userconfig = userconfigSrc + '-with-gc'
+exports.globalconfig = path.resolve(__dirname, 'fixtures', 'globalconfig')
+exports.builtin = path.resolve(__dirname, 'fixtures', 'builtin')
+
+// set the userconfig in the env
+// unset anything else that npm might be trying to foist on us
+Object.keys(process.env).forEach(function (k) {
+ if (k.match(/^npm_config_/i)) {
+ delete process.env[k]
+ }
+})
+process.env.npm_config_userconfig = exports.userconfig
+process.env.npm_config_other_env_thing = 1000
+process.env.random_env_var = 'asdf'
+
+if (module === require.main) {
+ // set the globalconfig in the userconfig
+ var fs = require('fs')
+ var uc = fs.readFileSync(userconfigSrc)
+ var gcini = 'globalconfig = ' + exports.globalconfig + '\n'
+ fs.writeFileSync(exports.userconfig, gcini + uc)
+
+ console.log('0..1')
+ console.log('ok 1 setup done')
+}
View
@@ -0,0 +1,70 @@
+var test = require('tap').test
+var npmconf = require('../npmconf.js')
+var common = require('./00-setup.js')
+
+var ucData =
+ { 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',
+ nodedir: '/Users/isaacs/dev/js/node-v0.8',
+ 'sign-git-tag': true,
+ message: 'v%s',
+ 'strict-ssl': false,
+ 'tmp': process.env.HOME + '/.tmp',
+ _token:
+ { AuthSession: 'yabba-dabba-doodle',
+ version: '1',
+ expires: '1345001053415',
+ path: '/',
+ httponly: true } }
+
+var envData = { userconfig: common.userconfig, 'other-env-thing': '1000' }
+
+var gcData = { 'package-config:foo': 'boo' }
+
+var biData = {}
+
+var cli = { foo: 'bar' }
+
+var expectList =
+[ cli,
+ envData,
+ ucData,
+ gcData,
+ biData ]
+
+var expectSources =
+{ cli: { data: cli },
+ env:
+ { data: envData,
+ source: envData,
+ prefix: '' },
+ user:
+ { path: common.userconfig,
+ type: 'ini',
+ data: ucData },
+ global:
+ { path: common.globalconfig,
+ type: 'ini',
+ data: gcData },
+ builtin: { data: biData } }
+
+test('no builtin', function (t) {
+ npmconf.load(cli, function (er, conf) {
+ if (er) throw er
+ t.same(conf.list, expectList)
+ t.same(conf.sources, expectSources)
+ t.same(npmconf.rootConf.list, [])
+ t.equal(npmconf.rootConf.root, npmconf.defs.defaults)
+ t.equal(conf.root, npmconf.defs.defaults)
+ t.end()
+ })
+})
View
@@ -0,0 +1,70 @@
+var test = require('tap').test
+var npmconf = require('../npmconf.js')
+var common = require('./00-setup.js')
+
+var ucData =
+ { 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',
+ nodedir: '/Users/isaacs/dev/js/node-v0.8',
+ 'sign-git-tag': true,
+ message: 'v%s',
+ 'strict-ssl': false,
+ 'tmp': process.env.HOME + '/.tmp',
+ _token:
+ { AuthSession: 'yabba-dabba-doodle',
+ version: '1',
+ expires: '1345001053415',
+ path: '/',
+ httponly: true } }
+
+var envData = { userconfig: common.userconfig, 'other-env-thing': '1000' }
+
+var gcData = { 'package-config:foo': 'boo' }
+
+var biData = { 'builtin-config': true }
+
+var cli = { foo: 'bar' }
+
+var expectList =
+[ cli,
+ envData,
+ ucData,
+ gcData,
+ biData ]
+
+var expectSources =
+{ cli: { data: cli },
+ env:
+ { data: envData,
+ source: envData,
+ prefix: '' },
+ user:
+ { path: common.userconfig,
+ type: 'ini',
+ data: ucData },
+ global:
+ { path: common.globalconfig,
+ type: 'ini',
+ data: gcData },
+ builtin: { data: biData } }
+
+test('with builtin', function (t) {
+ npmconf.load(cli, common.builtin, function (er, conf) {
+ if (er) throw er
+ t.same(conf.list, expectList)
+ t.same(conf.sources, expectSources)
+ t.same(npmconf.rootConf.list, [])
+ t.equal(npmconf.rootConf.root, npmconf.defs.defaults)
+ t.equal(conf.root, npmconf.defs.defaults)
+ t.end()
+ })
+})
View
@@ -0,0 +1 @@
+builtin-config = true
@@ -0,0 +1 @@
+package-config:foo = boo
View
@@ -0,0 +1,22 @@
+email = i@izs.me
+env-thing = ${random_env_var}
+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
+nodedir = /Users/isaacs/dev/js/node-v0.8
+sign-git-tag = true
+message = v%s
+strict-ssl = false
+tmp = ~/.tmp
+
+[_token]
+AuthSession = yabba-dabba-doodle
+version = 1
+expires = 1345001053415
+path = /
+httponly = true
View
@@ -0,0 +1,48 @@
+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 expect =
+ [ 'globalconfig = /Users/isaacs/dev/js/npmconf/test/fixtures/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.equal(foundConf, expect)
+ conf.save('user', function (er) {
+ if (er)
+ throw er
+ var uc = fs.readFileSync(conf.get('userconfig'), 'utf8')
+ t.equal(uc, expect)
+ t.end()
+ })
+ })
+})
+

0 comments on commit a6799f5

Please sign in to comment.