Skip to content

Commit

Permalink
Fix: Ensure API can be used without an options object (closes #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorccu authored and phated committed Dec 28, 2018
1 parent 18a2bba commit 4e39fc8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/findup-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function(patterns, options) {
if (!Array.isArray(patterns)) { patterns = [patterns]; }
// Create globOptions so that it can be modified without mutating the
// original object.
var globOptions = Object.create(options);
var globOptions = Object.create(options || {});
globOptions.maxDepth = 1;
globOptions.cwd = path.resolve(globOptions.cwd);

Expand Down
19 changes: 18 additions & 1 deletion test/findup-sync_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ var rel = function(abspath) {

exports['findup'] = {
setUp: function(done) {
// setup here
this.cwd = process.cwd();
done();
},
tearDown: function(done) {
process.chdir(this.cwd);
done();
},
'simple': function(test) {
Expand All @@ -28,4 +32,17 @@ exports['findup'] = {
test.equal(findup('not-gonna-exist-i-hope.txt', opts), null, 'should returning null if no files found');
test.done();
},
'cwd': function(test) {
test.expect(8);
process.chdir('test/fixtures/a/b');
test.equal(rel(findup('foo.txt')), '../foo.txt', 'should find files');
test.equal(rel(findup('bar.txt')), 'bar.txt', 'should find files');
test.equal(rel(findup('a.txt')), '../../a.txt', 'should find files');
test.equal(rel(findup('?.txt')), '../../a.txt', 'should support glob patterns');
test.equal(rel(findup('*.txt')), 'bar.txt', 'should find the first thing that matches the glob pattern');
test.equal(rel(findup(['b*.txt', 'f*.txt'])), 'bar.txt', 'should find the first thing that matches any of the glob patterns');
test.equal(rel(findup(['f*.txt', 'b*.txt'])), 'bar.txt', 'should find the first thing that matches any of the glob patterns');
test.equal(findup('not-gonna-exist-i-hope.txt'), null, 'should returning null if no files found');
test.done();
},
};

0 comments on commit 4e39fc8

Please sign in to comment.