diff --git a/__tests__/lib/merge_config.js b/__tests__/lib/merge_config.js index 45a42836a..5cc4e49a8 100644 --- a/__tests__/lib/merge_config.js +++ b/__tests__/lib/merge_config.js @@ -10,7 +10,30 @@ test('bad config', async function() { } }); -test('nc(mergeConfig)', function(done) { +test('right merging package configuration', async function() { + // Omit configuration from output, for simplicity + var nc = _.curryRight(_.omit, 2)([ + 'config', + 'no-package', + 'parseExtension', + 'project-homepage', + 'project-version' + ]); + return mergeConfig({ + config: path.join(__dirname, '../config_fixture/config.json'), + 'no-package': true, + 'project-name': 'cool Documentation' + }) + .then(nc) + .then(res => { + expect(res).toEqual({ + 'project-name': 'cool Documentation', + foo: 'bar' + }); + }); +}); + +test('nc(mergeConfig)', async function() { // Omit configuration from output, for simplicity var nc = _.curryRight(_.omit, 2)([ 'config', @@ -21,7 +44,7 @@ test('nc(mergeConfig)', function(done) { 'project-version' ]); - Promise.all( + return Promise.all( [ [ { config: path.join(__dirname, '../config_fixture/config.json') }, @@ -74,7 +97,5 @@ test('nc(mergeConfig)', function(done) { expect(res).toEqual(pair[1]); }) ) - ).then(res => { - done(); - }); + ); }); diff --git a/src/merge_config.js b/src/merge_config.js index 7d4cd8726..65dcf733d 100644 --- a/src/merge_config.js +++ b/src/merge_config.js @@ -3,7 +3,6 @@ var yaml = require('js-yaml'), fs = require('fs'), pify = require('pify'), - _ = require('lodash'), readPkgUp = require('read-pkg-up'), path = require('path'), stripComments = require('strip-json-comments'); @@ -29,7 +28,7 @@ function processToc(config: DocumentationConfig, absFilePath: string) { * values of `name` and `version` config. * * @param {Object} config the user-provided config, usually via argv - * @returns {Object} configuration with inferred parameters + * @returns {Promise} configuration with inferred parameters * @throws {Error} if the file cannot be read. */ function mergePackage(config: Object): Promise { @@ -38,16 +37,12 @@ function mergePackage(config: Object): Promise { } return ( readPkgUp() - .then(pkg => - _.defaults( - {}, - _.mapKeys( - _.pick(pkg.pkg, ['name', 'homepage', 'version']), - (val, key) => `project-${key}` - ), - config - ) - ) + .then(pkg => { + ['name', 'homepage', 'version'].forEach(key => { + config[`project-${key}`] = config[`project-${key}`] || pkg.pkg[key]; + }); + return config; + }) // Allow this to fail: this inference is not required. .catch(() => config) );