From 9d2ae4ea64b6e2bad2f96e92cfcb273b0f4d0751 Mon Sep 17 00:00:00 2001 From: David Clark Date: Tue, 18 Jul 2017 06:54:02 -0700 Subject: [PATCH] configPath cleanup --- CHANGELOG.md | 1 + README.md | 6 ++++++ test/config-file.test.js | 23 ----------------------- test/successful-directories.test.js | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 23 deletions(-) delete mode 100644 test/config-file.test.js diff --git a/CHANGELOG.md b/CHANGELOG.md index e7678174..b356ae41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Head - Added: `sync` option. +- Fixed: `options.configPath` and `--config` flag are respected. ## 2.1.3 diff --git a/README.md b/README.md index a92211a3..061afe0b 100644 --- a/README.md +++ b/README.md @@ -188,6 +188,12 @@ If the option `sync` is `true`, though, `transform` should be a synchronous func The reason you might use this option instead of simply applying your transform function some other way is that *the transformed result will be cached*. If your transformation involves additional filesystem I/O or other potentially slow processing, you can use this option to avoid repeating those steps every time a given configuration is loaded. +##### configPath + +Type: `string` + +If provided, cosmiconfig will load and parse a config from this path, and will not perform its usual search. + ### Instance methods (on `explorer`) #### `load([searchPath, configPath])` diff --git a/test/config-file.test.js b/test/config-file.test.js deleted file mode 100644 index 5e6d1839..00000000 --- a/test/config-file.test.js +++ /dev/null @@ -1,23 +0,0 @@ -'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); - }); -}); diff --git a/test/successful-directories.test.js b/test/successful-directories.test.js index 5c0b1207..e1b7d043 100644 --- a/test/successful-directories.test.js +++ b/test/successful-directories.test.js @@ -660,3 +660,17 @@ test('with rcExtensions, find .foorc.js in first searched dir', function (assert teardown(assert, err); } }); + +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); + }); +});