Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added test

  • Loading branch information...
commit db71018976dd576f9d321cf0b8b1bb4a390e99ef 1 parent a790bee
@Qard authored
Showing with 62 additions and 0 deletions.
  1. +62 −0 test.js
View
62 test.js
@@ -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)
+ })
+ })
+
+})
Please sign in to comment.
Something went wrong with that request. Please try again.