From 802a8d623fb2a16e517d0f565c79d9d4f788dfdc Mon Sep 17 00:00:00 2001 From: AdrieanKhisbe Date: Sat, 28 Oct 2017 19:49:46 +0200 Subject: [PATCH] test for yargs custom instance (more flexible check isYargs) --- lib/nconf/stores/argv.js | 2 +- test/nconf-argv-test.js | 25 +++++++++++++++++++++++++ test/stores/argv-test.js | 19 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 test/nconf-argv-test.js diff --git a/lib/nconf/stores/argv.js b/lib/nconf/stores/argv.js index c418a2b..b2e13b6 100644 --- a/lib/nconf/stores/argv.js +++ b/lib/nconf/stores/argv.js @@ -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); } diff --git a/test/nconf-argv-test.js b/test/nconf-argv-test.js new file mode 100644 index 0000000..ab1842b --- /dev/null +++ b/test/nconf-argv-test.js @@ -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); diff --git a/test/stores/argv-test.js b/test/stores/argv-test.js index f90c833..ba651da 100644 --- a/test/stores/argv-test.js +++ b/test/stores/argv-test.js @@ -7,6 +7,7 @@ var vows = require('vows'), assert = require('assert'), + yargs = require('yargs') nconf = require('../../lib/nconf'); vows.describe('nconf/stores/argv').addBatch({ @@ -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); \ No newline at end of file