1 var test = require('tap').test
2 var CC = require('../index.js').ConfigChain
4 var env = { foo_blaz : 'blzaa', foo_env : 'myenv' }
5 var jsonObj = { blaz: 'json', json: true }
6 var iniObj = { 'x.y.z': 'xyz', blaz: 'ini' }
9 var ini = require('ini')
11 fs.writeFileSync('/tmp/config-chain-class.json', JSON.stringify(jsonObj))
12 fs.writeFileSync('/tmp/config-chain-class.ini', ini.stringify(iniObj))
14 var http = require('http')
16 http.createServer(function (q, s) {
17 if (++reqs === 2) this.close()
18 if (q.url === '/json') {
19 // make sure that the requests come back from the server
20 // out of order. they should still be ordered properly
21 // in the resulting config object set.
22 setTimeout(function () {
23 s.setHeader('content-type', 'application/json')
24 s.end(JSON.stringify({
31 s.setHeader('content-type', 'application/ini')
41 test('basic class test', function (t) {
44 [ { blaz: 'json', json: true },
45 { 'x.y.z': 'xyz', blaz: 'ini' },
46 { blaz: 'blzaa', env: 'myenv' },
47 { blaz: 'http', http: true, json: true },
48 { blaz: 'http', http: true, ini: true, json: false } ]
50 cc.addFile('/tmp/config-chain-class.json')
51 .addFile('/tmp/config-chain-class.ini')
53 .addUrl('http://localhost:1337/json')
54 .addUrl('http://localhost:1337/ini')
55 .on('load', function () {
56 t.same(cc.list, expectlist)
57 t.same(cc.snapshot, { blaz: 'json',
64 cc.del('blaz', '/tmp/config-chain-class.json')
65 t.same(cc.snapshot, { blaz: 'ini',
72 t.same(cc.snapshot, { json: true,
78 t.same(cc.snapshot, { 'x.y.z': 'xyz',
84 t.same(cc.snapshot, { env: 'myenv',
89 t.same(cc.snapshot, { http: true,
93 t.same(cc.snapshot, { http: true,
97 t.same(cc.snapshot, {})