Skip to content

Commit

Permalink
fix: Refactor for simplification of findConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Kellen authored and phated committed Nov 22, 2021
1 parent d210849 commit 08e61f5
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ Liftoff.prototype.buildEnvironment = function (opts) {
// calculate configPath
var configPath = findConfig({
configNameSearch: configNameSearch,
searchPaths: searchPaths,
configPath: opts.configPath
searchPaths: searchPaths
});

// if we have a config path, save the directory it resides in.
Expand Down
16 changes: 6 additions & 10 deletions lib/find_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@ const fileSearch = require('./file_search');
module.exports = function (opts) {
opts = opts || {};
var configNameSearch = opts.configNameSearch;
var configPath = opts.configPath;
var searchPaths = opts.searchPaths;
// only search for a config if a path to one wasn't explicitly provided
if (!configPath) {
if (!Array.isArray(searchPaths)) {
throw new Error('Please provide an array of paths to search for config in.');
}
if (!configNameSearch) {
throw new Error('Please provide a configNameSearch.');
}
configPath = fileSearch(configNameSearch, searchPaths);
if (!Array.isArray(searchPaths)) {
throw new Error('Please provide an array of paths to search for config in.');
}
if (!configNameSearch) {
throw new Error('Please provide a configNameSearch.');
}
var configPath = fileSearch(configNameSearch, searchPaths);
// confirm the configPath exists and return an absolute path to it
if (fs.existsSync(configPath)) {
return path.resolve(configPath);
Expand Down
6 changes: 0 additions & 6 deletions test/lib/find_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ describe('findConfig', function () {
expect(function(){findConfig({configNameRegex:'dude'});}).to.throw;
});

it('if configPath is explicitly provided, return the absolute path to the file or null if it doesn\'t actually exist', function () {
var configPath = path.resolve('test/fixtures/mochafile.js');
expect(findConfig({configPath:configPath})).to.equal(configPath);
expect(findConfig({configPath:'path/to/nowhere'})).to.equal(null);
});

it('should return the absolute path to the first config file found in searchPaths', function () {
expect(findConfig({
configNameSearch: ['mochafile.js', 'mochafile.coffee'],
Expand Down

0 comments on commit 08e61f5

Please sign in to comment.