Skip to content

Commit

Permalink
test for yargs custom instance (more flexible check isYargs)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrieanKhisbe authored and mhamann committed Oct 28, 2017
1 parent 3e26bb2 commit 802a8d6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/nconf/stores/argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,5 @@ Argv.prototype.loadArgv = function () {
};

function isYargs(obj) {
return (typeof obj === 'function') && ('argv' in obj);
return (typeof obj === 'function' || typeof obj === 'object') && ('argv' in obj);
}
25 changes: 25 additions & 0 deletions test/nconf-argv-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* file-store-test.js: Tests for the nconf File store.
*
* (C) 2011, Charlie Robbins and the Contributors.
*
*/

var fs = require('fs'),
path = require('path'),
vows = require('vows'),
assert = require('assert'),
nconf = require('../lib/nconf'),
yargs = require('yargs')

vows.describe('nconf/argv').addBatch({
"When using the nconf": {
"with a custom yargs": {
topic: function () {
fs.readFile(path.join(__dirname, '..', 'package.json'), this.callback);
},
},
"with the default yars": {
}
}
}).export(module);
19 changes: 19 additions & 0 deletions test/stores/argv-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

var vows = require('vows'),
assert = require('assert'),
yargs = require('yargs')
nconf = require('../../lib/nconf');

vows.describe('nconf/stores/argv').addBatch({
Expand All @@ -16,6 +17,24 @@ vows.describe('nconf/stores/argv').addBatch({
assert.isFunction(argv.loadSync);
assert.isFunction(argv.loadArgv);
assert.deepEqual(argv.options, {});
},
"can be created with a custom yargs":{
topic: function(){
var yargsInstance = yargs.alias('v', 'verbose').default('v', 'false');
console.log(yargsInstance)
return [yargsInstance, new nconf.Argv(yargsInstance)];
},
"and can give access to them": function (argv) {
var yargsInstance = argv[0];
argv = argv[1]
assert.equal(argv.options, yargsInstance)
},
"values are the one from the custom yargv": function (argv) {
argv = argv[1]
argv.loadSync()
assert.equal(argv.get('verbose'), 'false');
assert.equal(argv.get('v'), 'false');
}
}
}
}).export(module);

0 comments on commit 802a8d6

Please sign in to comment.