test for yargs custom instance (more flexible check isYargs)

This commit is contained in:
AdrieanKhisbe 2017-10-28 19:49:46 +02:00 committed by Matt Hamann
parent 3e26bb2756
commit 802a8d623f
3 changed files with 45 additions and 1 deletions

View file

@ -87,5 +87,5 @@ Argv.prototype.loadArgv = function () {
}; };
function isYargs(obj) { function isYargs(obj) {
return (typeof obj === 'function') && ('argv' in obj); return (typeof obj === 'function' || typeof obj === 'object') && ('argv' in obj);
} }

25
test/nconf-argv-test.js Normal file
View file

@ -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);

View file

@ -7,6 +7,7 @@
var vows = require('vows'), var vows = require('vows'),
assert = require('assert'), assert = require('assert'),
yargs = require('yargs')
nconf = require('../../lib/nconf'); nconf = require('../../lib/nconf');
vows.describe('nconf/stores/argv').addBatch({ vows.describe('nconf/stores/argv').addBatch({
@ -16,6 +17,24 @@ vows.describe('nconf/stores/argv').addBatch({
assert.isFunction(argv.loadSync); assert.isFunction(argv.loadSync);
assert.isFunction(argv.loadArgv); assert.isFunction(argv.loadArgv);
assert.deepEqual(argv.options, {}); 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); }).export(module);