Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 93cf4a6

Browse files
committedFeb 9, 2016
refactored, now uses micromatch
also: - resolves #26 - resolves #25 - closes #15 - closes #18 - closes #22 - closes #23 - closes #24
1 parent 3d73218 commit 93cf4a6

32 files changed

+474
-165
lines changed
 

‎.gitattributes

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Enforce Unix newlines
2+
*.* text eol=lf
3+
4+
*.jpg binary
5+
*.gif binary
6+
*.png binary
7+
*.jpeg binary

‎.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
/node_modules/
1+
*.DS_Store
2+
*.sublime-*
3+
node_modules
4+
npm-debug.log
5+
test/actual

‎.jshintrc

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
{
2-
"loopfunc": true,
2+
"asi": false,
3+
"boss": true,
34
"curly": true,
45
"eqeqeq": true,
6+
"eqnull": true,
7+
"esnext": true,
58
"immed": true,
6-
"latedef": true,
9+
"latedef": false,
10+
"laxbreak": true,
11+
"laxcomma": false,
712
"newcap": true,
813
"noarg": true,
14+
"node": true,
915
"sub": true,
1016
"undef": true,
1117
"unused": true,
12-
"boss": true,
13-
"eqnull": true,
14-
"node": true
15-
}
18+
"mocha": true
19+
}

‎.npmignore

-4
This file was deleted.

‎.travis.yml

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
sudo: false
12
language: node_js
23
node_js:
3-
- 0.8
4-
- '0.10'
5-
before_install:
6-
- npm update -g npm
7-
- npm install -g grunt-cli
4+
- "stable"
5+
- "5"
6+
- "4"
7+
- "0.12"
8+
- "0.10"
9+
matrix:
10+
fast_finish: true
11+
allow_failures:
12+
- node_js: "0.10"

‎Gruntfile.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,17 @@ module.exports = function(grunt) {
44

55
// Project configuration.
66
grunt.initConfig({
7-
nodeunit: {
8-
files: ['test/**/*_test.js'],
9-
},
107
jshint: {
118
options: {
129
jshintrc: '.jshintrc'
1310
},
14-
all: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js']
11+
all: ['Gruntfile.js', '*.js']
1512
}
1613
});
1714

1815
// Load plugins.
1916
grunt.loadNpmTasks('grunt-contrib-jshint');
20-
grunt.loadNpmTasks('grunt-contrib-nodeunit');
2117

2218
// Default task.
23-
grunt.registerTask('default', ['jshint', 'nodeunit']);
24-
19+
grunt.registerTask('default', ['jshint']);
2520
};

‎LICENSE-MIT

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
Copyright (c) 2013 "Cowboy" Ben Alman
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013-2016, "Cowboy" Ben Alman.
24

35
Permission is hereby granted, free of charge, to any person
46
obtaining a copy of this software and associated documentation

‎README.md

+42-23
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
# findup-sync [![Build Status](https://secure.travis-ci.org/cowboy/node-findup-sync.png?branch=master)](http://travis-ci.org/cowboy/node-findup-sync)
1+
# findup-sync [![Build Status](https://travis-ci.org/cowboy/node-findup-sync.svg)](https://travis-ci.org/cowboy/node-findup-sync) [![NPM version](https://badge.fury.io/js/findup-sync.svg)](http://badge.fury.io/js/findup-sync)
22

3-
Find the first file matching a given pattern in the current directory or the nearest ancestor directory.
3+
> Find the first file matching a given pattern in the current directory or the nearest ancestor directory.
44
5-
## Getting Started
6-
Install the module with: `npm install findup-sync`
5+
Matching is done with [micromatch][], please report any matching related issues on that repository.
6+
7+
## Install with [npm](npmjs.org)
8+
9+
```bash
10+
npm i findup-sync --save
11+
```
12+
13+
## Usage
714

815
```js
916
var findup = require('findup-sync');
17+
findup(patternOrPatterns [, micromatchOptions]);
1018

1119
// Start looking in the CWD.
1220
var filepath1 = findup('{a,b}*.txt');
@@ -15,34 +23,45 @@ var filepath1 = findup('{a,b}*.txt');
1523
var filepath2 = findup('{a,b}*.txt', {cwd: '/some/path', nocase: true});
1624
```
1725

18-
## Usage
19-
20-
```js
21-
findup(patternOrPatterns [, minimatchOptions])
22-
```
26+
* `patterns` **{String|Array}**: Glob pattern(s) or file path(s) to match against.
27+
* `options` **{Object}**: Options to pass to [micromatch]. Note that if you want to start in a different directory than the current working directory, specify a `cwd` property here.
28+
* `returns` **{String}**: Returns the first matching file.
2329

24-
### patternOrPatterns
25-
Type: `String` or `Array`
26-
Default: none
30+
## Running tests
2731

28-
One or more wildcard glob patterns. Or just filenames.
32+
Install dev dependencies:
2933

30-
### minimatchOptions
31-
Type: `Object`
32-
Default: `{}`
34+
```bash
35+
npm i -d && npm test
36+
```
3337

34-
Options to be passed to [minimatch](https://github.com/isaacs/minimatch).
38+
## Contributing
3539

36-
Note that if you want to start in a different directory than the current working directory, specify a `cwd` property here.
40+
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/)
3741

38-
## Contributing
39-
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
42+
For bugs and feature requests, [please create an issue](https://github.com/cowboy/node-findup-sync/issues).
4043

4144
## Release History
42-
2015-09-14 0 v0.3.0 - updated glob to ~5.0.
43-
2014-12-17 - v0.2.1 - updated to glob ~4.3.
45+
46+
2015-01-30 - v0.4.0 - Refactored, not also uses [micromatch][] instead of minimatch.
47+
2015-09-14 - v0.3.0 - updated glob to ~5.0. 2014-12-17 - v0.2.1 - updated to glob ~4.3.
48+
2014-12-17 - v0.2.1 - Updated to glob 4.3.
4449
2014-12-16 - v0.2.0 - Removed lodash, updated to glob 4.x.
4550
2014-03-14 - v0.1.3 - Updated dependencies.
4651
2013-03-08 - v0.1.2 - Updated dependencies. Fixed a Node 0.9.x bug. Updated unit tests to work cross-platform.
4752
2012-11-15 - v0.1.1 - Now works without an options object.
48-
2012-11-01 - v0.1.0 - Initial release.
53+
2012-11-01 - v0.1.0 - Initial release.
54+
55+
## Authors
56+
57+
**"Cowboy" Ben Alman**
58+
59+
+ [github/cowboy](https://github.com/cowboy)
60+
+ [twitter/cowboy](http://twitter.com/cowboy)
61+
62+
## License
63+
64+
Copyright (c) 2012-2016 "Cowboy" Ben Alman
65+
Released under the MIT license
66+
67+
[micromatch]: http://github.com/jonschlinkert/micromatch

‎index.js

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies
5+
*/
6+
7+
var fs = require('fs');
8+
var path = require('path');
9+
var isGlob = require('is-glob');
10+
var resolveDir = require('resolve-dir');
11+
var mm = require('micromatch');
12+
13+
/**
14+
* @param {String|Array} `pattern` Glob pattern or file path(s) to match against.
15+
* @param {Object} `options` Options to pass to [micromatch]. Note that if you want to start in a different directory than the current working directory, specify the `options.cwd` property here.
16+
* @return {String} Returns the first matching file.
17+
* @api public
18+
*/
19+
20+
module.exports = function(patterns, options) {
21+
if (typeof patterns === 'string') {
22+
return lookup(patterns, options);
23+
}
24+
25+
if (!Array.isArray(patterns)) {
26+
throw new TypeError('findup-sync expects a string or array as the first argument.');
27+
}
28+
29+
var len = patterns.length, i = -1;
30+
while (++i < len) {
31+
var res = lookup(patterns[i], options);
32+
if (res) {
33+
return res;
34+
}
35+
}
36+
37+
return null;
38+
};
39+
40+
function lookup(pattern, options) {
41+
options = options || {};
42+
var cwd = resolveDir(options.cwd || '');
43+
if (isGlob(pattern)) {
44+
return matchFile(cwd, pattern, options);
45+
} else {
46+
return findFile(cwd, pattern);
47+
}
48+
}
49+
50+
function matchFile(cwd, pattern, opts) {
51+
var isMatch = mm.matcher(pattern, opts);
52+
var files = fs.readdirSync(cwd);
53+
var len = files.length, i = -1;
54+
55+
while (++i < len) {
56+
var name = files[i];
57+
var fp = path.join(cwd, name);
58+
if (isMatch(name) || isMatch(fp)) {
59+
return fp;
60+
}
61+
}
62+
63+
var dir = path.dirname(cwd);
64+
if (dir === cwd) {
65+
return null;
66+
}
67+
return matchFile(dir, pattern, opts);
68+
}
69+
70+
function findFile(cwd, filename) {
71+
var fp = cwd ? (cwd + '/' + filename) : filename;
72+
if (fs.existsSync(fp)) {
73+
return fp;
74+
}
75+
76+
var segs = cwd.split(path.sep);
77+
var len = segs.length;
78+
79+
while (len--) {
80+
cwd = segs.slice(0, len).join('/');
81+
fp = cwd + '/' + filename;
82+
if (fs.existsSync(fp)) {
83+
return fp;
84+
}
85+
}
86+
return null;
87+
}

‎lib/findup-sync.js

-49
This file was deleted.

‎package.json

+26-21
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,46 @@
33
"description": "Find the first file matching a given pattern in the current directory or the nearest ancestor directory.",
44
"version": "0.3.0",
55
"homepage": "https://github.com/cowboy/node-findup-sync",
6-
"author": {
7-
"name": "\"Cowboy\" Ben Alman",
8-
"url": "http://benalman.com/"
9-
},
10-
"repository": {
11-
"type": "git",
12-
"url": "git://github.com/cowboy/node-findup-sync.git"
13-
},
6+
"author": "\"Cowboy\" Ben Alman (http://benalman.com)",
7+
"repository": "cowboy/node-findup-sync",
148
"bugs": {
159
"url": "https://github.com/cowboy/node-findup-sync/issues"
1610
},
17-
"licenses": [
18-
{
19-
"type": "MIT",
20-
"url": "https://github.com/cowboy/node-findup-sync/blob/master/LICENSE-MIT"
21-
}
11+
"license": "MIT",
12+
"files": [
13+
"index.js"
2214
],
23-
"main": "lib/findup-sync",
15+
"main": "index.js",
2416
"engines": {
25-
"node": ">= 0.6.0"
17+
"node": ">= 0.8.0"
2618
},
2719
"scripts": {
28-
"test": "grunt nodeunit"
20+
"test": "grunt && mocha"
2921
},
3022
"dependencies": {
31-
"glob": "~5.0.0"
23+
"is-glob": "^2.0.1",
24+
"micromatch": "^2.3.7",
25+
"resolve-dir": "^0.1.0"
3226
},
3327
"devDependencies": {
34-
"grunt": "~0.4.5",
35-
"grunt-contrib-jshint": "~0.11.3",
36-
"grunt-contrib-nodeunit": "~0.3.3"
28+
"grunt": "^0.4.5",
29+
"grunt-contrib-jshint": "^0.12.0",
30+
"is-absolute": "^0.2.3",
31+
"minimist": "^1.2.0",
32+
"mocha": "^2.4.5",
33+
"normalize-path": "^2.0.1",
34+
"resolve": "^1.1.7",
35+
"user-home": "^2.0.0"
3736
},
3837
"keywords": [
38+
"file",
3939
"find",
40+
"find-up",
41+
"findup",
4042
"glob",
41-
"file"
43+
"match",
44+
"pattern",
45+
"resolve",
46+
"search"
4247
]
4348
}

‎test/findup-sync_test.js

-48
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎test/fixtures/a/b/c/d/e/f/g/h/i/j/package.json

Whitespace-only changes.

‎test/fixtures/a/b/c/d/e/f/g/h/i/package.json

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "h",
3+
"description": "package.json from h."
4+
}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "g",
3+
"description": "package.json from g."
4+
}
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "f",
3+
"description": "package.json from f."
4+
}

‎test/fixtures/a/b/c/d/e/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "e",
3+
"description": "package.json from e."
4+
}

‎test/fixtures/a/b/c/d/one.txt

Whitespace-only changes.

‎test/fixtures/a/b/c/d/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "d",
3+
"description": "package.json from d."
4+
}

‎test/fixtures/a/b/c/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "c",
3+
"description": "package.json from c."
4+
}

‎test/fixtures/a/b/c/two.txt

Whitespace-only changes.

‎test/fixtures/a/b/one.txt

Whitespace-only changes.

‎test/fixtures/a/b/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "b",
3+
"description": "package.json from b."
4+
}

‎test/fixtures/a/one.txt

Whitespace-only changes.

‎test/fixtures/a/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "a",
3+
"description": "package.json from a."
4+
}

‎test/fixtures/package.json

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "fixtures",
3+
"description": "package.json from ./fixtures."
4+
}

‎test/test.js

+246
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
'use strict';
2+
3+
require('mocha');
4+
var argv = require('minimist')(process.argv.slice(2));
5+
var fs = require('fs');
6+
var path = require('path');
7+
var assert = require('assert');
8+
var expand = require('resolve-dir');
9+
var norm = require('normalize-path');
10+
var home = require('user-home');
11+
var isAbsolute = require('is-absolute');
12+
var resolve = require('resolve');
13+
var cwd, actual, opts;
14+
15+
var findup = require('../');
16+
17+
function normalize(fp) {
18+
return fp ? norm(path.relative('.', fp)) : null;
19+
}
20+
21+
if (argv.bench) {
22+
var b = path.join(__dirname, 'benchmark/code', argv.bench);
23+
console.log(b);
24+
findup = require(b);
25+
}
26+
27+
assert.isPath = function (fp, basename) {
28+
assert(fp);
29+
assert.equal(typeof fp, 'string');
30+
};
31+
32+
assert.isAbsolute = function (fp) {
33+
assert(fp);
34+
assert(isAbsolute(fp));
35+
};
36+
37+
assert.exists = function (fp) {
38+
assert(fp);
39+
try {
40+
fs.statSync(fp);
41+
} catch(err) {
42+
assert(fp, err);
43+
}
44+
};
45+
46+
assert.basename = function (fp, basename) {
47+
assert(fp);
48+
assert.equal(path.basename(fp), basename);
49+
};
50+
51+
assert.dirname = function (fp, dirname) {
52+
assert(fp);
53+
assert.equal(path.dirname(path.resolve(fp)), path.resolve(dirname));
54+
};
55+
56+
function npm(name) {
57+
return path.dirname(resolve.sync(name));
58+
}
59+
60+
describe('findup-sync', function () {
61+
before(function () {
62+
fs.writeFileSync(home + '/_aaa.txt', '');
63+
fs.writeFileSync(home + '/_bbb.txt', '');
64+
});
65+
after(function () {
66+
fs.unlinkSync(home + '/_aaa.txt');
67+
fs.unlinkSync(home + '/_bbb.txt');
68+
});
69+
70+
it('should throw when the first arg is not a string or array:', function(cb) {
71+
try {
72+
findup();
73+
cb(new Error('expected an error'));
74+
} catch (err) {
75+
assert.equal(err.message, 'findup-sync expects a string or array as the first argument.');
76+
cb();
77+
}
78+
});
79+
80+
it('should work when no cwd is given', function () {
81+
var actual = findup('package.json');
82+
assert(actual);
83+
assert.dirname(actual, path.resolve(__dirname, '..'));
84+
assert.basename(actual, 'package.json');
85+
assert.equal(normalize(findup('package.json')), 'package.json');
86+
});
87+
88+
it('should support normal (non-glob) file paths:', function () {
89+
var normPath = normalize(findup('package.json', {cwd: path.dirname(resolve.sync('normalize-path'))}));
90+
assert.equal(normPath, 'node_modules/normalize-path/package.json');
91+
92+
var isGlob = normalize(findup('package.json', {cwd: path.dirname(resolve.sync('is-glob'))}));
93+
assert.equal(isGlob, 'node_modules/is-glob/package.json');
94+
95+
cwd = path.dirname(resolve.sync('normalize-path'));
96+
var actual = findup('package.json', {cwd: cwd});
97+
assert.dirname(actual, cwd);
98+
assert.basename(actual, 'package.json');
99+
100+
actual = findup('c/package.json', {cwd: 'test/fixtures/a/b/c/d/e/f/g'});
101+
assert.basename(actual, 'package.json');
102+
assert.dirname(actual, 'test/fixtures/a/b/c');
103+
104+
cwd = path.dirname(resolve.sync('is-glob'));
105+
actual = findup('package.json', {cwd: cwd});
106+
assert.dirname(actual, cwd);
107+
assert.basename(actual, 'package.json');
108+
});
109+
110+
it('should support glob patterns', function() {
111+
assert.equal(normalize(findup('**/c/package.json', {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/package.json');
112+
assert.equal(normalize(findup('**/one.txt', {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/d/one.txt');
113+
assert.equal(normalize(findup('**/two.txt', {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/two.txt');
114+
115+
var pkg = normalize(findup('p*.json', {cwd: npm('micromatch')}));
116+
assert.equal(pkg, 'node_modules/micromatch/package.json');
117+
118+
var opts = {cwd: 'test/fixtures/a/b/c/d/e/f/g'};
119+
120+
actual = findup('**/c/package.json', opts);
121+
assert.dirname(actual, 'test/fixtures/a/b/c');
122+
assert.basename(actual, 'package.json');
123+
124+
actual = findup('c/package.json', opts);
125+
assert.dirname(actual, 'test/fixtures/a/b/c');
126+
assert.basename(actual, 'package.json');
127+
128+
actual = findup('**/ONE.txt', opts);
129+
assert.dirname(actual, 'test/fixtures/a/b/c');
130+
assert.basename(actual, 'ONE.txt');
131+
132+
actual = findup('**/two.txt', opts);
133+
assert.dirname(actual, 'test/fixtures/a/b/c');
134+
assert.basename(actual, 'two.txt');
135+
136+
cwd = npm('is-glob');
137+
actual = findup('p*.json', {cwd: cwd});
138+
assert.dirname(actual, cwd);
139+
assert.basename(actual, 'package.json');
140+
});
141+
142+
it('should support arrays of glob patterns', function() {
143+
assert.equal(normalize(findup(['**/c/package.json'], {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/package.json');
144+
assert.equal(normalize(findup(['**/one.txt'], {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/d/one.txt');
145+
assert.equal(normalize(findup(['**/two.txt'], {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/two.txt');
146+
147+
var opts = {cwd: 'test/fixtures/a/b/c/d/e/f/g'};
148+
149+
actual = findup(['lslsl', '**/c/package.json'], opts);
150+
assert.dirname(actual, 'test/fixtures/a/b/c');
151+
assert.basename(actual, 'package.json');
152+
153+
actual = findup(['lslsl', 'c/package.json'], opts);
154+
assert.dirname(actual, 'test/fixtures/a/b/c');
155+
assert.basename(actual, 'package.json');
156+
157+
actual = findup(['lslsl', '**/ONE.txt'], opts);
158+
assert.dirname(actual, 'test/fixtures/a/b/c');
159+
assert.basename(actual, 'ONE.txt');
160+
161+
actual = findup(['lslsl', '**/two.txt'], opts);
162+
assert.dirname(actual, 'test/fixtures/a/b/c');
163+
assert.basename(actual, 'two.txt');
164+
165+
actual = findup(['lslsl', '**/blah.txt'], opts);
166+
assert(actual === null);
167+
168+
cwd = npm('is-glob');
169+
actual = findup(['lslsl', 'p*.json'], {cwd: cwd});
170+
assert.dirname(actual, cwd);
171+
assert.basename(actual, 'package.json');
172+
});
173+
174+
it('should support micromatch `matchBase` option:', function() {
175+
var opts = { matchBase: true, cwd: 'test/fixtures/a/b/c/d/e/f/g' };
176+
assert.equal(normalize(findup('package.json', opts)), 'test/fixtures/a/b/c/d/e/f/g/package.json');
177+
assert.equal(normalize(findup('one.txt', opts)), 'test/fixtures/a/b/c/d/one.txt');
178+
assert.equal(normalize(findup('two.txt', opts)), 'test/fixtures/a/b/c/two.txt');
179+
180+
actual = findup('package.json', opts);
181+
assert.basename(actual, 'package.json');
182+
assert.dirname(actual, 'test/fixtures/a/b/c/d/e/f/g');
183+
184+
actual = findup('one.txt', opts);
185+
assert.basename(actual, 'one.txt');
186+
assert.dirname(actual, 'test/fixtures/a/b/c/d');
187+
188+
actual = findup('two.txt', opts);
189+
assert.basename(actual, 'two.txt');
190+
assert.dirname(actual, 'test/fixtures/a/b/c');
191+
});
192+
193+
it('should return `null` when no files are found:', function() {
194+
var dep = normalize(findup('*.foo', {cwd: path.dirname(resolve.sync('micromatch'))}));
195+
assert.equal(dep, null);
196+
assert.equal(findup('**/b*.json', {cwd: npm('is-glob')}), null);
197+
assert.equal(findup('foo.json', {cwd: 'test/fixtures/a/b/c/d/e/f/g'}), null);
198+
assert.equal(findup('foo.json', {cwd: 'test/fixtures/a/b/c/d/e/f/g', matchBase: true}), null);
199+
});
200+
201+
it('should support finding file in immediate parent dir', function () {
202+
cwd = path.resolve(__dirname, 'fixtures/a/b/c');
203+
var actual = findup('a.md', { cwd: cwd });
204+
assert.dirname(actual, path.dirname(cwd));
205+
assert.basename(actual, 'a.md');
206+
});
207+
208+
it('should support micromatch `nocase` option:', function () {
209+
actual = findup('ONE.*', { cwd: 'test/fixtures/a/b/c/d' });
210+
assert.basename(actual, 'ONE.txt');
211+
assert.dirname(actual, 'test/fixtures/a/b/c');
212+
213+
actual = findup('ONE.*', { cwd: 'test/fixtures/a/b/c/d', nocase: true });
214+
assert.basename(actual, 'one.txt');
215+
assert.dirname(actual, 'test/fixtures/a/b/c/d');
216+
});
217+
218+
it('should find files from absolute paths:', function () {
219+
var actual = findup('package.json', { cwd: __dirname })
220+
221+
assert.basename(actual, 'package.json');
222+
assert.dirname(actual, path.resolve(__dirname, '..'));
223+
224+
actual = findup('one.txt', { cwd: __dirname + '/fixtures/a' });
225+
assert.basename(actual, 'one.txt');
226+
assert.dirname(actual, 'test/fixtures/a');
227+
228+
actual = findup('two.txt', { cwd: __dirname + '/fixtures/a/b/c' });
229+
assert.basename(actual, 'two.txt');
230+
assert.dirname(actual, 'test/fixtures/a/b/c');
231+
});
232+
233+
it('should find files in user home:', function () {
234+
var actual = findup('*', { cwd: home });
235+
assert.isPath(actual);
236+
assert.exists(actual);
237+
assert.dirname(actual, home);
238+
});
239+
240+
it('should find files in user home using tilde expansion:', function () {
241+
var actual = findup('*', { cwd: '~' });
242+
assert.isPath(actual);
243+
assert.exists(actual);
244+
assert.dirname(actual, home);
245+
});
246+
});

0 commit comments

Comments
 (0)
Please sign in to comment.