Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
Qard committed Dec 16, 2011
1 parent a790bee commit db71018
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions test.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env mocha -r should -R spec
var jsonfig = require('./index')
var dotpath = require('dotpath')

// Test different behaviours of the interface.
describe('jsonfig interface', function () {

var path = __dirname + '/config';

it('should default to process env', function () {
jsonfig.env().should.eql(process.env.NODE_ENV || 'development')
})

it('should change env to production', function () {
jsonfig.env('production')
jsonfig.env().should.eql('production')
})

it('should default to __dirname path', function () {
jsonfig.path().should.eql(__dirname)
})

it('should change path to ./config', function () {
jsonfig.path(path)
jsonfig.path().should.eql(path)
})

function next (origin, conf, cb) {
cb()
describe('config interface from '+origin, function () {

it('should use dotpath module', function () {
conf.should.be.an.instanceof(dotpath)
conf.get.should.be.a('function')
})

it('should get evironment-specific configs', function () {
conf.get('redis.host').should.eql('localhost')
})

it('should get environment-agnostic configs', function () {
conf.get('all_envs.some').should.eql('var')
})

})
}

it('should load from stored path()', function (done) {
jsonfig.path(path).load(function (err, conf) {
if (err) { throw new Error(err) }
next('stored path', conf, done)
})
})

it('should load from supplied path', function (done) {
jsonfig.path(__dirname).load(path, function (err, conf) {
if (err) { throw new Error(err) }
next('supplied path', conf, done)
})
})

})

0 comments on commit db71018

Please sign in to comment.