Skip to content

Commit

Permalink
Fix --config and configPath option (#68)
Browse files Browse the repository at this point in the history
* Fix --config and configPath option

* Add configPath test
  • Loading branch information
azz authored and davidtheclark committed Jul 18, 2017
1 parent 216797e commit e4baf6d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/createExplorer.js
Expand Up @@ -29,6 +29,10 @@ module.exports = function (options) {
}

function load(searchPath, configPath) {
if (!configPath && options.configPath) {
configPath = options.configPath;
}

if (configPath) {
var absoluteConfigPath = path.resolve(process.cwd(), configPath);
if (fileCache && fileCache.has(absoluteConfigPath)) {
Expand Down
23 changes: 23 additions & 0 deletions test/config-file.test.js
@@ -0,0 +1,23 @@
'use strict';

var test = require('tape');
var path = require('path');
var cosmiconfig = require('..');

function absolutePath(str) {
return path.join(__dirname, str);
}

test('options.configPath is respected', function (assert) {
var configPath = absolutePath('fixtures/foo.json');
var explorer = cosmiconfig('foo', { configPath: configPath });
explorer.load('./path/does/not/exist').then(function (result) {
assert.deepEqual(result.config, {
foo: true,
});
assert.equal(result.filepath, configPath);
assert.end();
}).catch(function (err) {
assert.end(err);
});
});

0 comments on commit e4baf6d

Please sign in to comment.