[Pkg-javascript-commits] [node-findup-sync] 01/07: New upstream version 0.4.3

Sruthi Chandran srud-guest at moszumanska.debian.org
Wed Nov 9 09:18:45 UTC 2016


This is an automated email from the git hooks/post-receive script.

srud-guest pushed a commit to branch master
in repository node-findup-sync.

commit 0c644149797df070e9ea9a00e1d76431ef598c11
Author: Sruthi <srud at disroot.org>
Date:   Wed Nov 9 14:03:44 2016 +0530

    New upstream version 0.4.3
---
 .gitattributes                                     |   7 +
 .gitignore                                         |   6 +-
 .jshintrc                                          |  16 +-
 .travis.yml                                        |  16 +-
 Gruntfile.js                                       |   9 +-
 LICENSE-MIT                                        |   4 +-
 README.md                                          |  64 +++--
 index.js                                           |  85 ++++++
 lib/findup-sync.js                                 |  46 ----
 package.json                                       |  52 ++--
 test/findup-sync_test.js                           |  48 ----
 test/fixtures/Mochafile.txt                        |   1 +
 test/fixtures/a/Mochafile.txt                      |   1 +
 test/fixtures/a/a.txt                              |   1 +
 .npmignore => test/fixtures/a/b/.config/waldo      |   0
 test/fixtures/a/b/Mochafile.txt                    |   1 +
 test/fixtures/{a.txt => a/b/ONE.js}                |   0
 test/fixtures/a/b/{bar.txt => a.md}                |   0
 test/fixtures/a/b/b.txt                            |   1 +
 test/fixtures/a/b/c/Mochafile.txt                  |   1 +
 test/fixtures/a/{foo.txt => b/c/ONE.txt}           |   0
 test/fixtures/a/b/c/c.txt                          |   1 +
 test/fixtures/a/b/c/d/Mochafile.txt                |   1 +
 test/fixtures/a/b/c/d/d.txt                        |   1 +
 test/fixtures/a/b/c/d/e/Mochafile.txt              |   1 +
 test/fixtures/a/b/c/d/e/e.txt                      |   1 +
 test/fixtures/a/b/c/d/e/f/Mochafile.txt            |   1 +
 test/fixtures/a/b/c/d/e/f/f.txt                    |   1 +
 test/fixtures/a/b/c/d/e/f/file.txt                 |   1 +
 test/fixtures/a/b/c/d/e/f/g/Mochafile.txt          |   1 +
 test/fixtures/a/b/c/d/e/f/g/file.txt               |   1 +
 test/fixtures/a/b/c/d/e/f/g/g.txt                  |   1 +
 test/fixtures/a/b/c/d/e/f/g/h/Mochafile.txt        |   1 +
 test/fixtures/a/b/c/d/e/f/g/h/file.txt             |   1 +
 test/fixtures/a/b/c/d/e/f/g/h/h.txt                |   1 +
 test/fixtures/a/b/c/d/e/f/g/h/i/Mochafile.txt      |   1 +
 test/fixtures/a/b/c/d/e/f/g/h/i/file.txt           |   1 +
 test/fixtures/a/b/c/d/e/f/g/h/i/i.txt              |   1 +
 test/fixtures/a/b/c/d/e/f/g/h/i/j/Mochafile.txt    |   1 +
 test/fixtures/a/b/c/d/e/f/g/h/i/j/file.txt         |   1 +
 test/fixtures/a/b/c/d/e/f/g/h/i/j/j.txt            |   1 +
 .../{aaa.txt => a/b/c/d/e/f/g/h/i/j/package.json}  |   0
 .../fixtures/a/b/c/d/e/f/g/h/i/package.json        |   0
 test/fixtures/a/b/c/d/e/f/g/h/package.json         |   4 +
 test/fixtures/a/b/c/d/e/f/g/package.json           |   4 +
 test/fixtures/a/b/c/d/e/f/package.json             |   4 +
 test/fixtures/a/b/c/d/e/file.txt                   |   1 +
 test/fixtures/a/b/c/d/e/package.json               |   4 +
 test/fixtures/a/b/c/d/file.txt                     |   1 +
 .npmignore => test/fixtures/a/b/c/d/one.txt        |   0
 test/fixtures/a/b/c/d/package.json                 |   4 +
 test/fixtures/a/b/c/file.txt                       |   1 +
 test/fixtures/a/b/c/package.json                   |   4 +
 .npmignore => test/fixtures/a/b/c/two.txt          |   0
 test/fixtures/a/b/file.txt                         |   1 +
 .npmignore => test/fixtures/a/b/one.txt            |   0
 test/fixtures/a/b/package.json                     |   4 +
 test/fixtures/a/file.txt                           |   1 +
 .npmignore => test/fixtures/a/one.txt              |   0
 test/fixtures/a/package.json                       |   4 +
 test/fixtures/file.txt                             |   1 +
 test/fixtures/package.json                         |   4 +
 test/fixtures/root.txt                             |   1 +
 test/support/index.js                              |  51 ++++
 test/test.js                                       | 302 +++++++++++++++++++++
 65 files changed, 619 insertions(+), 156 deletions(-)

diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..bd96839
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,7 @@
+# Enforce Unix newlines
+*.*     text eol=lf
+
+*.jpg binary
+*.gif binary
+*.png binary
+*.jpeg binary
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 2ccbe46..cb5fd92 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,5 @@
-/node_modules/
+*.DS_Store
+*.sublime-*
+node_modules
+npm-debug.log
+test/actual
diff --git a/.jshintrc b/.jshintrc
index 8718952..a82080d 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -1,15 +1,19 @@
 {
-  "loopfunc": true,
+  "asi": false,
+  "boss": true,
   "curly": true,
   "eqeqeq": true,
+  "eqnull": true,
+  "esnext": true,
   "immed": true,
-  "latedef": true,
+  "latedef": false,
+  "laxbreak": true,
+  "laxcomma": false,
   "newcap": true,
   "noarg": true,
+  "node": true,
   "sub": true,
   "undef": true,
   "unused": true,
-  "boss": true,
-  "eqnull": true,
-  "node": true
-}
+  "mocha": true
+}
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index b30fcb7..6f7779c 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,15 @@
+sudo: false
 language: node_js
+os:
+  - linux
+  - osx
 node_js:
-  - 0.8
-before_script:
-  - npm install -g grunt-cli
+  - "6"
+  - "5"
+  - "4"
+  - "0.12"
+  - "0.10"
+matrix:
+  fast_finish: true
+  allow_failures:
+    - node_js: "0.10"
diff --git a/Gruntfile.js b/Gruntfile.js
index 2f964a5..17270d8 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -4,22 +4,17 @@ module.exports = function(grunt) {
 
   // Project configuration.
   grunt.initConfig({
-    nodeunit: {
-      files: ['test/**/*_test.js'],
-    },
     jshint: {
       options: {
         jshintrc: '.jshintrc'
       },
-      all: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js']
+      all: ['*.js', 'test/{,support/}*.js']
     }
   });
 
   // Load plugins.
   grunt.loadNpmTasks('grunt-contrib-jshint');
-  grunt.loadNpmTasks('grunt-contrib-nodeunit');
 
   // Default task.
-  grunt.registerTask('default', ['jshint', 'nodeunit']);
-
+  grunt.registerTask('default', ['jshint']);
 };
diff --git a/LICENSE-MIT b/LICENSE-MIT
index bb2aad6..8bb6566 100644
--- a/LICENSE-MIT
+++ b/LICENSE-MIT
@@ -1,4 +1,6 @@
-Copyright (c) 2013 "Cowboy" Ben Alman
+The MIT License (MIT)
+
+Copyright (c) 2013-2016, "Cowboy" Ben Alman.
 
 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
diff --git a/README.md b/README.md
index 5459b93..c8c4a0b 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,20 @@
-# findup-sync [![Build Status](https://secure.travis-ci.org/cowboy/node-findup-sync.png?branch=master)](http://travis-ci.org/cowboy/node-findup-sync)
+# findup-sync  [![Build Status](https://travis-ci.org/js-cli/node-findup-sync.svg)](https://travis-ci.org/js-cli/node-findup-sync)  [![NPM version](https://badge.fury.io/js/findup-sync.svg)](http://badge.fury.io/js/findup-sync)
 
-Find the first file matching a given pattern in the current directory or the nearest ancestor directory.
+> Find the first file matching a given pattern in the current directory or the nearest ancestor directory.
 
-## Getting Started
-Install the module with: `npm install findup-sync`
+Matching is done with [micromatch][], please report any matching related issues on that repository. 
+
+## Install with [npm](npmjs.org)
+
+```bash
+npm i findup-sync --save
+```
+
+## Usage
 
 ```js
 var findup = require('findup-sync');
+findup(patternOrPatterns [, micromatchOptions]);
 
 // Start looking in the CWD.
 var filepath1 = findup('{a,b}*.txt');
@@ -15,31 +23,45 @@ var filepath1 = findup('{a,b}*.txt');
 var filepath2 = findup('{a,b}*.txt', {cwd: '/some/path', nocase: true});
 ```
 
-## Usage
-
-```js
-findup(patternOrPatterns [, minimatchOptions])
-```
+* `patterns` **{String|Array}**: Glob pattern(s) or file path(s) to match against.    
+* `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.    
+* `returns` **{String}**: Returns the first matching file.
 
-### patternOrPatterns
-Type: `String` or `Array`  
-Default: none
+## Running tests
 
-One or more wildcard glob patterns. Or just filenames.
+Install dev dependencies:
 
-### minimatchOptions
-Type: `Object`  
-Default: `{}`
+```bash
+npm i -d && npm test
+```
 
-Options to be passed to [minimatch](https://github.com/isaacs/minimatch).
+## Contributing
 
-Note that if you want to start in a different directory than the current working directory, specify a `cwd` property here.
+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/)
 
-## Contributing
-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/).
+For bugs and feature requests, [please create an issue](https://github.com/cowboy/node-findup-sync/issues).
 
 ## Release History
+
+2015-01-30 - v0.4.0 - Refactored, not also uses [micromatch][] instead of minimatch.  
+2015-09-14 - v0.3.0 - updated glob to ~5.0.  
+2014-12-17 - v0.2.1 - Updated to glob 4.3.  
+2014-12-16 - v0.2.0 - Removed lodash, updated to glob 4.x.  
 2014-03-14 - v0.1.3 - Updated dependencies.  
 2013-03-08 - v0.1.2 - Updated dependencies. Fixed a Node 0.9.x bug. Updated unit tests to work cross-platform.  
 2012-11-15 - v0.1.1 - Now works without an options object.  
-2012-11-01 - v0.1.0 - Initial release.
+2012-11-01 - v0.1.0 - Initial release.  
+
+## Authors
+
+**"Cowboy" Ben Alman**
+ 
++ [github/cowboy](https://github.com/cowboy)
++ [twitter/cowboy](http://twitter.com/cowboy) 
+
+## License
+
+Copyright (c) 2012-2016 "Cowboy" Ben Alman  
+Released under the MIT license
+
+[micromatch]: http://github.com/jonschlinkert/micromatch
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..b843495
--- /dev/null
+++ b/index.js
@@ -0,0 +1,85 @@
+'use strict';
+
+/**
+ * Module dependencies
+ */
+
+var fs = require('fs');
+var path = require('path');
+var isGlob = require('is-glob');
+var resolveDir = require('resolve-dir');
+var detect = require('detect-file');
+var mm = require('micromatch');
+
+/**
+ * @param  {String|Array} `pattern` Glob pattern or file path(s) to match against.
+ * @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.
+ * @return {String} Returns the first matching file.
+ * @api public
+ */
+
+module.exports = function(patterns, options) {
+  options = options || {};
+  var cwd = path.resolve(resolveDir(options.cwd || ''));
+
+  if (typeof patterns === 'string') {
+    return lookup(cwd, [patterns], options);
+  }
+
+  if (!Array.isArray(patterns)) {
+    throw new TypeError('findup-sync expects a string or array as the first argument.');
+  }
+
+  return lookup(cwd, patterns, options);
+};
+
+function lookup(cwd, patterns, options) {
+  var len = patterns.length;
+  var idx = -1;
+  var res;
+
+  while (++idx < len) {
+    if (isGlob(patterns[idx])) {
+      res = matchFile(cwd, patterns[idx], options);
+    } else {
+      res = findFile(cwd, patterns[idx], options);
+    }
+    if (res) {
+      return res;
+    }
+  }
+
+  var dir = path.dirname(cwd);
+  if (dir === cwd) {
+    return null;
+  }
+  return lookup(dir, patterns, options);
+}
+
+function matchFile(cwd, pattern, opts) {
+  var isMatch = mm.matcher(pattern, opts);
+  var files = tryReaddirSync(cwd);
+  var len = files.length;
+  var idx = -1;
+
+  while (++idx < len) {
+    var name = files[idx];
+    var fp = path.join(cwd, name);
+    if (isMatch(name) || isMatch(fp)) {
+      return fp;
+    }
+  }
+  return null;
+}
+
+function findFile(cwd, filename, options) {
+  var fp = cwd ? path.resolve(cwd, filename) : filename;
+  return detect(fp, options);
+}
+
+function tryReaddirSync(fp) {
+  try {
+    return fs.readdirSync(fp);
+  } catch(err) {}
+  return [];
+}
diff --git a/lib/findup-sync.js b/lib/findup-sync.js
deleted file mode 100644
index 742a478..0000000
--- a/lib/findup-sync.js
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * findup-sync
- * https://github.com/cowboy/node-findup-sync
- *
- * Copyright (c) 2013 "Cowboy" Ben Alman
- * Licensed under the MIT license.
- */
-
-'use strict';
-
-// Nodejs libs.
-var path = require('path');
-
-// External libs.
-var glob = require('glob');
-var _ = require('lodash');
-
-// Search for a filename in the given directory or all parent directories.
-module.exports = function(patterns, options) {
-  // Normalize patterns to an array.
-  if (!Array.isArray(patterns)) { patterns = [patterns]; }
-  // Create globOptions so that it can be modified without mutating the
-  // original object.
-  var globOptions = Object.create(options || {});
-  globOptions.maxDepth = 1;
-  globOptions.cwd = path.resolve(globOptions.cwd || '.');
-
-  var files, lastpath;
-  do {
-    // Search for files matching patterns.
-    files = _(patterns).map(function(pattern) {
-      return glob.sync(pattern, globOptions);
-    }).flatten().uniq().value();
-    // Return file if found.
-    if (files.length > 0) {
-      return path.resolve(path.join(globOptions.cwd, files[0]));
-    }
-    // Go up a directory.
-    lastpath = globOptions.cwd;
-    globOptions.cwd = path.resolve(globOptions.cwd, '..');
-  // If parentpath is the same as basedir, we can't go any higher.
-  } while (globOptions.cwd !== lastpath);
-
-  // No files were found!
-  return null;
-};
diff --git a/package.json b/package.json
index 7242b91..7068dd0 100644
--- a/package.json
+++ b/package.json
@@ -1,44 +1,50 @@
 {
   "name": "findup-sync",
   "description": "Find the first file matching a given pattern in the current directory or the nearest ancestor directory.",
-  "version": "0.1.3",
+  "version": "0.4.3",
   "homepage": "https://github.com/cowboy/node-findup-sync",
-  "author": {
-    "name": "\"Cowboy\" Ben Alman",
-    "url": "http://benalman.com/"
-  },
-  "repository": {
-    "type": "git",
-    "url": "git://github.com/cowboy/node-findup-sync.git"
-  },
+  "author": "\"Cowboy\" Ben Alman (http://benalman.com)",
+  "repository": "cowboy/node-findup-sync",
   "bugs": {
     "url": "https://github.com/cowboy/node-findup-sync/issues"
   },
-  "licenses": [
-    {
-      "type": "MIT",
-      "url": "https://github.com/cowboy/node-findup-sync/blob/master/LICENSE-MIT"
-    }
+  "license": "MIT",
+  "files": [
+    "index.js"
   ],
-  "main": "lib/findup-sync",
+  "main": "index.js",
   "engines": {
-    "node": ">= 0.6.0"
+    "node": ">= 0.8.0"
   },
   "scripts": {
-    "test": "grunt nodeunit"
+    "test": "grunt && mocha"
   },
   "dependencies": {
-    "glob": "~3.2.9",
-    "lodash": "~2.4.1"
+    "detect-file": "^0.1.0",
+    "is-glob": "^2.0.1",
+    "micromatch": "^2.3.7",
+    "resolve-dir": "^0.1.0"
   },
   "devDependencies": {
-    "grunt": "~0.4.4",
-    "grunt-contrib-jshint": "~0.9.2",
-    "grunt-contrib-nodeunit": "~0.3.3"
+    "fs-exists-sync": "^0.1.0",
+    "grunt": "^1.0.1",
+    "grunt-contrib-jshint": "^0.12.0",
+    "is-absolute": "^0.2.3",
+    "minimist": "^1.2.0",
+    "mocha": "^2.4.5",
+    "normalize-path": "^2.0.1",
+    "os-homedir": "^1.0.1",
+    "resolve": "^1.1.7"
   },
   "keywords": [
+    "file",
     "find",
+    "find-up",
+    "findup",
     "glob",
-    "file"
+    "match",
+    "pattern",
+    "resolve",
+    "search"
   ]
 }
diff --git a/test/findup-sync_test.js b/test/findup-sync_test.js
deleted file mode 100644
index f8baf9e..0000000
--- a/test/findup-sync_test.js
+++ /dev/null
@@ -1,48 +0,0 @@
-'use strict';
-
-// Nodejs lib.
-var path = require('path');
-
-var findup = require('../lib/findup-sync.js');
-
-// Get a relative path.
-var rel = function(abspath) {
-  return typeof abspath === 'string' ? path.relative('.', abspath) : abspath;
-};
-
-exports['findup'] = {
-  setUp: function(done) {
-    this.cwd = process.cwd();
-    done();
-  },
-  tearDown: function(done) {
-    process.chdir(this.cwd);
-    done();
-  },
-  'simple': function(test) {
-    test.expect(8);
-    var opts = {cwd: 'test/fixtures/a/b'};
-    test.equal(rel(findup('foo.txt', opts)), path.normalize('test/fixtures/a/foo.txt'), 'should find files');
-    test.equal(rel(findup('bar.txt', opts)), path.normalize('test/fixtures/a/b/bar.txt'), 'should find files');
-    test.equal(rel(findup('a.txt', opts)), path.normalize('test/fixtures/a.txt'), 'should find files');
-    test.equal(rel(findup('?.txt', opts)), path.normalize('test/fixtures/a.txt'), 'should support glob patterns');
-    test.equal(rel(findup('*.txt', opts)), path.normalize('test/fixtures/a/b/bar.txt'), 'should find the first thing that matches the glob pattern');
-    test.equal(rel(findup(['b*.txt', 'f*.txt'], opts)), path.normalize('test/fixtures/a/b/bar.txt'), 'should find the first thing that matches any of the glob patterns');
-    test.equal(rel(findup(['f*.txt', 'b*.txt'], opts)), path.normalize('test/fixtures/a/b/bar.txt'), 'should find the first thing that matches any of the glob patterns');
-    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')), path.normalize('../foo.txt'), 'should find files');
-    test.equal(rel(findup('bar.txt')), 'bar.txt', 'should find files');
-    test.equal(rel(findup('a.txt')), path.normalize('../../a.txt'), 'should find files');
-    test.equal(rel(findup('?.txt')), path.normalize('../../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();
-  },
-};
diff --git a/test/fixtures/Mochafile.txt b/test/fixtures/Mochafile.txt
new file mode 100644
index 0000000..d8649da
--- /dev/null
+++ b/test/fixtures/Mochafile.txt
@@ -0,0 +1 @@
+root
diff --git a/test/fixtures/a/Mochafile.txt b/test/fixtures/a/Mochafile.txt
new file mode 100644
index 0000000..7898192
--- /dev/null
+++ b/test/fixtures/a/Mochafile.txt
@@ -0,0 +1 @@
+a
diff --git a/test/fixtures/a/a.txt b/test/fixtures/a/a.txt
new file mode 100644
index 0000000..7898192
--- /dev/null
+++ b/test/fixtures/a/a.txt
@@ -0,0 +1 @@
+a
diff --git a/.npmignore b/test/fixtures/a/b/.config/waldo
similarity index 100%
copy from .npmignore
copy to test/fixtures/a/b/.config/waldo
diff --git a/test/fixtures/a/b/Mochafile.txt b/test/fixtures/a/b/Mochafile.txt
new file mode 100644
index 0000000..6178079
--- /dev/null
+++ b/test/fixtures/a/b/Mochafile.txt
@@ -0,0 +1 @@
+b
diff --git a/test/fixtures/a.txt b/test/fixtures/a/b/ONE.js
similarity index 100%
rename from test/fixtures/a.txt
rename to test/fixtures/a/b/ONE.js
diff --git a/test/fixtures/a/b/bar.txt b/test/fixtures/a/b/a.md
similarity index 100%
rename from test/fixtures/a/b/bar.txt
rename to test/fixtures/a/b/a.md
diff --git a/test/fixtures/a/b/b.txt b/test/fixtures/a/b/b.txt
new file mode 100644
index 0000000..6178079
--- /dev/null
+++ b/test/fixtures/a/b/b.txt
@@ -0,0 +1 @@
+b
diff --git a/test/fixtures/a/b/c/Mochafile.txt b/test/fixtures/a/b/c/Mochafile.txt
new file mode 100644
index 0000000..f2ad6c7
--- /dev/null
+++ b/test/fixtures/a/b/c/Mochafile.txt
@@ -0,0 +1 @@
+c
diff --git a/test/fixtures/a/foo.txt b/test/fixtures/a/b/c/ONE.txt
similarity index 100%
rename from test/fixtures/a/foo.txt
rename to test/fixtures/a/b/c/ONE.txt
diff --git a/test/fixtures/a/b/c/c.txt b/test/fixtures/a/b/c/c.txt
new file mode 100644
index 0000000..f2ad6c7
--- /dev/null
+++ b/test/fixtures/a/b/c/c.txt
@@ -0,0 +1 @@
+c
diff --git a/test/fixtures/a/b/c/d/Mochafile.txt b/test/fixtures/a/b/c/d/Mochafile.txt
new file mode 100644
index 0000000..4bcfe98
--- /dev/null
+++ b/test/fixtures/a/b/c/d/Mochafile.txt
@@ -0,0 +1 @@
+d
diff --git a/test/fixtures/a/b/c/d/d.txt b/test/fixtures/a/b/c/d/d.txt
new file mode 100644
index 0000000..4bcfe98
--- /dev/null
+++ b/test/fixtures/a/b/c/d/d.txt
@@ -0,0 +1 @@
+d
diff --git a/test/fixtures/a/b/c/d/e/Mochafile.txt b/test/fixtures/a/b/c/d/e/Mochafile.txt
new file mode 100644
index 0000000..d905d9d
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/Mochafile.txt
@@ -0,0 +1 @@
+e
diff --git a/test/fixtures/a/b/c/d/e/e.txt b/test/fixtures/a/b/c/d/e/e.txt
new file mode 100644
index 0000000..d905d9d
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/e.txt
@@ -0,0 +1 @@
+e
diff --git a/test/fixtures/a/b/c/d/e/f/Mochafile.txt b/test/fixtures/a/b/c/d/e/f/Mochafile.txt
new file mode 100644
index 0000000..6a69f92
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/Mochafile.txt
@@ -0,0 +1 @@
+f
diff --git a/test/fixtures/a/b/c/d/e/f/f.txt b/test/fixtures/a/b/c/d/e/f/f.txt
new file mode 100644
index 0000000..6a69f92
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/f.txt
@@ -0,0 +1 @@
+f
diff --git a/test/fixtures/a/b/c/d/e/f/file.txt b/test/fixtures/a/b/c/d/e/f/file.txt
new file mode 100644
index 0000000..6a69f92
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/file.txt
@@ -0,0 +1 @@
+f
diff --git a/test/fixtures/a/b/c/d/e/f/g/Mochafile.txt b/test/fixtures/a/b/c/d/e/f/g/Mochafile.txt
new file mode 100644
index 0000000..01058d8
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/g/Mochafile.txt
@@ -0,0 +1 @@
+g
diff --git a/test/fixtures/a/b/c/d/e/f/g/file.txt b/test/fixtures/a/b/c/d/e/f/g/file.txt
new file mode 100644
index 0000000..01058d8
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/g/file.txt
@@ -0,0 +1 @@
+g
diff --git a/test/fixtures/a/b/c/d/e/f/g/g.txt b/test/fixtures/a/b/c/d/e/f/g/g.txt
new file mode 100644
index 0000000..01058d8
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/g/g.txt
@@ -0,0 +1 @@
+g
diff --git a/test/fixtures/a/b/c/d/e/f/g/h/Mochafile.txt b/test/fixtures/a/b/c/d/e/f/g/h/Mochafile.txt
new file mode 100644
index 0000000..6e9f0da
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/g/h/Mochafile.txt
@@ -0,0 +1 @@
+h
diff --git a/test/fixtures/a/b/c/d/e/f/g/h/file.txt b/test/fixtures/a/b/c/d/e/f/g/h/file.txt
new file mode 100644
index 0000000..6e9f0da
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/g/h/file.txt
@@ -0,0 +1 @@
+h
diff --git a/test/fixtures/a/b/c/d/e/f/g/h/h.txt b/test/fixtures/a/b/c/d/e/f/g/h/h.txt
new file mode 100644
index 0000000..6e9f0da
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/g/h/h.txt
@@ -0,0 +1 @@
+h
diff --git a/test/fixtures/a/b/c/d/e/f/g/h/i/Mochafile.txt b/test/fixtures/a/b/c/d/e/f/g/h/i/Mochafile.txt
new file mode 100644
index 0000000..0ddf2ba
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/g/h/i/Mochafile.txt
@@ -0,0 +1 @@
+i
diff --git a/test/fixtures/a/b/c/d/e/f/g/h/i/file.txt b/test/fixtures/a/b/c/d/e/f/g/h/i/file.txt
new file mode 100644
index 0000000..0ddf2ba
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/g/h/i/file.txt
@@ -0,0 +1 @@
+i
diff --git a/test/fixtures/a/b/c/d/e/f/g/h/i/i.txt b/test/fixtures/a/b/c/d/e/f/g/h/i/i.txt
new file mode 100644
index 0000000..0ddf2ba
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/g/h/i/i.txt
@@ -0,0 +1 @@
+i
diff --git a/test/fixtures/a/b/c/d/e/f/g/h/i/j/Mochafile.txt b/test/fixtures/a/b/c/d/e/f/g/h/i/j/Mochafile.txt
new file mode 100644
index 0000000..4c559f7
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/g/h/i/j/Mochafile.txt
@@ -0,0 +1 @@
+j
diff --git a/test/fixtures/a/b/c/d/e/f/g/h/i/j/file.txt b/test/fixtures/a/b/c/d/e/f/g/h/i/j/file.txt
new file mode 100644
index 0000000..4c559f7
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/g/h/i/j/file.txt
@@ -0,0 +1 @@
+j
diff --git a/test/fixtures/a/b/c/d/e/f/g/h/i/j/j.txt b/test/fixtures/a/b/c/d/e/f/g/h/i/j/j.txt
new file mode 100644
index 0000000..4c559f7
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/g/h/i/j/j.txt
@@ -0,0 +1 @@
+j
diff --git a/test/fixtures/aaa.txt b/test/fixtures/a/b/c/d/e/f/g/h/i/j/package.json
similarity index 100%
rename from test/fixtures/aaa.txt
rename to test/fixtures/a/b/c/d/e/f/g/h/i/j/package.json
diff --git a/.npmignore b/test/fixtures/a/b/c/d/e/f/g/h/i/package.json
similarity index 100%
copy from .npmignore
copy to test/fixtures/a/b/c/d/e/f/g/h/i/package.json
diff --git a/test/fixtures/a/b/c/d/e/f/g/h/package.json b/test/fixtures/a/b/c/d/e/f/g/h/package.json
new file mode 100644
index 0000000..755d1eb
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/g/h/package.json
@@ -0,0 +1,4 @@
+{
+  "name": "h",
+  "description": "package.json from h."
+}
diff --git a/test/fixtures/a/b/c/d/e/f/g/package.json b/test/fixtures/a/b/c/d/e/f/g/package.json
new file mode 100644
index 0000000..1dfe7a9
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/g/package.json
@@ -0,0 +1,4 @@
+{
+  "name": "g",
+  "description": "package.json from g."
+}
diff --git a/test/fixtures/a/b/c/d/e/f/package.json b/test/fixtures/a/b/c/d/e/f/package.json
new file mode 100644
index 0000000..9800c88
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/f/package.json
@@ -0,0 +1,4 @@
+{
+  "name": "f",
+  "description": "package.json from f."
+}
diff --git a/test/fixtures/a/b/c/d/e/file.txt b/test/fixtures/a/b/c/d/e/file.txt
new file mode 100644
index 0000000..d905d9d
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/file.txt
@@ -0,0 +1 @@
+e
diff --git a/test/fixtures/a/b/c/d/e/package.json b/test/fixtures/a/b/c/d/e/package.json
new file mode 100644
index 0000000..9648987
--- /dev/null
+++ b/test/fixtures/a/b/c/d/e/package.json
@@ -0,0 +1,4 @@
+{
+  "name": "e",
+  "description": "package.json from e."
+}
diff --git a/test/fixtures/a/b/c/d/file.txt b/test/fixtures/a/b/c/d/file.txt
new file mode 100644
index 0000000..4bcfe98
--- /dev/null
+++ b/test/fixtures/a/b/c/d/file.txt
@@ -0,0 +1 @@
+d
diff --git a/.npmignore b/test/fixtures/a/b/c/d/one.txt
similarity index 100%
copy from .npmignore
copy to test/fixtures/a/b/c/d/one.txt
diff --git a/test/fixtures/a/b/c/d/package.json b/test/fixtures/a/b/c/d/package.json
new file mode 100644
index 0000000..3134281
--- /dev/null
+++ b/test/fixtures/a/b/c/d/package.json
@@ -0,0 +1,4 @@
+{
+  "name": "d",
+  "description": "package.json from d."
+}
diff --git a/test/fixtures/a/b/c/file.txt b/test/fixtures/a/b/c/file.txt
new file mode 100644
index 0000000..f2ad6c7
--- /dev/null
+++ b/test/fixtures/a/b/c/file.txt
@@ -0,0 +1 @@
+c
diff --git a/test/fixtures/a/b/c/package.json b/test/fixtures/a/b/c/package.json
new file mode 100644
index 0000000..fc3b934
--- /dev/null
+++ b/test/fixtures/a/b/c/package.json
@@ -0,0 +1,4 @@
+{
+  "name": "c",
+  "description": "package.json from c."
+}
diff --git a/.npmignore b/test/fixtures/a/b/c/two.txt
similarity index 100%
copy from .npmignore
copy to test/fixtures/a/b/c/two.txt
diff --git a/test/fixtures/a/b/file.txt b/test/fixtures/a/b/file.txt
new file mode 100644
index 0000000..6178079
--- /dev/null
+++ b/test/fixtures/a/b/file.txt
@@ -0,0 +1 @@
+b
diff --git a/.npmignore b/test/fixtures/a/b/one.txt
similarity index 100%
copy from .npmignore
copy to test/fixtures/a/b/one.txt
diff --git a/test/fixtures/a/b/package.json b/test/fixtures/a/b/package.json
new file mode 100644
index 0000000..82b7ba8
--- /dev/null
+++ b/test/fixtures/a/b/package.json
@@ -0,0 +1,4 @@
+{
+  "name": "b",
+  "description": "package.json from b."
+}
diff --git a/test/fixtures/a/file.txt b/test/fixtures/a/file.txt
new file mode 100644
index 0000000..7898192
--- /dev/null
+++ b/test/fixtures/a/file.txt
@@ -0,0 +1 @@
+a
diff --git a/.npmignore b/test/fixtures/a/one.txt
similarity index 100%
rename from .npmignore
rename to test/fixtures/a/one.txt
diff --git a/test/fixtures/a/package.json b/test/fixtures/a/package.json
new file mode 100644
index 0000000..d67dd39
--- /dev/null
+++ b/test/fixtures/a/package.json
@@ -0,0 +1,4 @@
+{
+  "name": "a",
+  "description": "package.json from a."
+}
diff --git a/test/fixtures/file.txt b/test/fixtures/file.txt
new file mode 100644
index 0000000..d8649da
--- /dev/null
+++ b/test/fixtures/file.txt
@@ -0,0 +1 @@
+root
diff --git a/test/fixtures/package.json b/test/fixtures/package.json
new file mode 100644
index 0000000..3703b8e
--- /dev/null
+++ b/test/fixtures/package.json
@@ -0,0 +1,4 @@
+{
+  "name": "fixtures",
+  "description": "package.json from ./fixtures."
+}
diff --git a/test/fixtures/root.txt b/test/fixtures/root.txt
new file mode 100644
index 0000000..d8649da
--- /dev/null
+++ b/test/fixtures/root.txt
@@ -0,0 +1 @@
+root
diff --git a/test/support/index.js b/test/support/index.js
new file mode 100644
index 0000000..399311b
--- /dev/null
+++ b/test/support/index.js
@@ -0,0 +1,51 @@
+'use strict';
+
+var path = require('path');
+var normalizePath = require('normalize-path');
+var isAbsolute = require('is-absolute');
+var resolve = require('resolve');
+
+exports.normalize = function(filepath) {
+  return filepath ? normalizePath(path.relative('.', filepath)) : null;
+};
+
+exports.chdir = function(dir) {
+  // store current cwd
+  var orig = process.cwd();
+  // set cwd to the given `dir`
+  process.chdir(dir);
+  return function() {
+    // restore original `cwd`
+    process.chdir(orig);
+  };
+};
+
+exports.npm = function npm(name) {
+  return path.dirname(resolve.sync(name));
+};
+
+exports.assert = function(assert) {
+  assert.isPath = function (filepath) {
+    assert(filepath);
+    assert.equal(typeof filepath, 'string');
+  };
+
+  assert.isAbsolute = function (filepath) {
+    assert(filepath);
+    assert.equal(typeof filepath, 'string');
+    assert(isAbsolute(filepath));
+  };
+
+  assert.basename = function (filepath, basename) {
+    assert(filepath);
+    assert.equal(typeof filepath, 'string');
+    assert.equal(path.basename(filepath), basename);
+  };
+
+  assert.dirname = function (filepath, dirname) {
+    assert(filepath);
+    assert.equal(typeof filepath, 'string');
+    assert.equal(path.dirname(path.resolve(filepath)), path.resolve(dirname));
+  };
+};
+
diff --git a/test/test.js b/test/test.js
new file mode 100644
index 0000000..2df39c2
--- /dev/null
+++ b/test/test.js
@@ -0,0 +1,302 @@
+'use strict';
+
+require('mocha');
+var fs = require('fs');
+var path = require('path');
+var assert = require('assert');
+var support = require('./support');
+support.assert(assert);
+var home = require('os-homedir');
+var exists = require('fs-exists-sync');
+var resolve = require('resolve');
+var findup = require('../');
+var normalize = support.normalize;
+var chdir = support.chdir;
+var npm = support.npm;
+var cwd;
+var actual;
+var isLinux = process.platform === 'linux';
+
+
+describe('findup-sync', function () {
+  before(function () {
+    fs.writeFileSync(home() + '/_aaa.txt', '');
+    fs.writeFileSync(home() + '/_bbb.txt', '');
+  });
+  after(function () {
+    fs.unlinkSync(home() + '/_aaa.txt');
+    fs.unlinkSync(home() + '/_bbb.txt');
+  });
+
+  it('should throw when the first arg is not a string or array:', function(cb) {
+    try {
+      findup();
+      cb(new Error('expected an error'));
+    } catch (err) {
+      assert.equal(err.message, 'findup-sync expects a string or array as the first argument.');
+      cb();
+    }
+  });
+
+  it('should work when no cwd is given', function () {
+    var actual = findup('package.json');
+    assert(actual);
+    assert.dirname(actual, path.resolve(__dirname, '..'));
+    assert.basename(actual, 'package.json');
+    assert.equal(normalize(findup('package.json')), 'package.json');
+  });
+
+  it('should find files in a child directory', function () {
+    var expected = path.resolve(__dirname, 'fixtures/a/b/file.txt');
+    var restore = chdir(path.resolve(__dirname, 'fixtures/a/b/c/d/e/f/g/h'));
+
+    var actual = findup('a/b/file.txt');
+    assert(actual);
+    assert(exists(actual));
+    assert.equal(actual, expected);
+    restore();
+  });
+
+  it('should find case sensitive files in a child directory', function () {
+    var expected = path.resolve(__dirname, 'fixtures/a/b/', (isLinux ? 'Mochafile.txt' : 'mochafile.txt'));
+    var restore = chdir(path.resolve(__dirname, 'fixtures/a/b/c/d/e/f/g/h'));
+
+    var actual = findup('a/b/mochafile.txt', {nocase: true});
+    assert(actual);
+    assert(exists(actual));
+    assert.equal(actual, expected);
+    restore();
+  });
+
+  it('should find files in a child directory relative to a cwd', function () {
+    var expectedFile = path.resolve(__dirname, 'fixtures/a/b/file.txt');
+    var expectedA = path.resolve(__dirname, 'fixtures/a/a.txt');
+    var tempDir = chdir(path.resolve(__dirname, 'fixtures'));
+
+    var actualFile = findup('a/b/file.txt', {cwd: 'a/b/c/d'});
+    assert(actualFile);
+    assert(exists(actualFile));
+    assert.equal(actualFile, expectedFile);
+
+    var actualA = findup('a.txt', {cwd: 'a/b/c/d/e/f'});
+    assert(actualA);
+    assert(exists(actualA));
+    assert.equal(actualA, expectedA);
+    tempDir();
+  });
+
+  it('should find case sensitive files in a child directory relative to a cwd', function () {
+    var expectedFile = path.resolve(__dirname, 'fixtures/a/b', (isLinux ? 'Mochafile.txt' : 'mochafile.txt'));
+    var expectedA = path.resolve(__dirname, 'fixtures/a/a.txt');
+    var tempDir = chdir(path.resolve(__dirname, 'fixtures'));
+
+    var actualFile = findup('a/b/mochafile.txt', {cwd: 'a/b/c/d', nocase: true});
+    assert(actualFile);
+    assert(exists(actualFile));
+    assert.equal(actualFile, expectedFile);
+
+    var actualA = findup('a.txt', {cwd: 'a/b/c/d/e/f'});
+    assert(actualA);
+    assert(exists(actualA));
+    assert.equal(actualA, expectedA);
+    tempDir();
+  });
+
+  it('should support normal (non-glob) file paths:', function () {
+    var normPath = normalize(findup('package.json', {cwd: path.dirname(resolve.sync('normalize-path'))}));
+    assert.equal(normPath, 'node_modules/normalize-path/package.json');
+
+    var isGlob = normalize(findup('package.json', {cwd: path.dirname(resolve.sync('is-glob'))}));
+    assert.equal(isGlob, 'node_modules/is-glob/package.json');
+
+    cwd = path.dirname(resolve.sync('normalize-path'));
+    var actual = findup('package.json', {cwd: cwd});
+    assert.dirname(actual, cwd);
+    assert.basename(actual, 'package.json');
+
+    actual = findup('c/package.json', {cwd: 'test/fixtures/a/b/c/d/e/f/g'});
+    assert.basename(actual, 'package.json');
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+
+    cwd = path.dirname(resolve.sync('is-glob'));
+    actual = findup('package.json', {cwd: cwd});
+    assert.dirname(actual, cwd);
+    assert.basename(actual, 'package.json');
+  });
+
+  it('should support normal (non-glob) case sensitive file paths:', function () {
+    actual = findup('c/mochafile.txt', {cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true});
+    assert.basename(actual, (isLinux ? 'Mochafile.txt' : 'mochafile.txt'));
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+  });
+
+  it('should support glob patterns', function() {
+    assert.equal(normalize(findup('**/c/package.json', {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/package.json');
+    assert.equal(normalize(findup('**/one.txt', {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/d/one.txt');
+    assert.equal(normalize(findup('**/two.txt', {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/two.txt');
+
+    var pkg = normalize(findup('p*.json', {cwd: npm('micromatch')}));
+    assert.equal(pkg, 'node_modules/micromatch/package.json');
+
+    var opts = {cwd: 'test/fixtures/a/b/c/d/e/f/g'};
+
+    actual = findup('**/c/package.json', opts);
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+    assert.basename(actual, 'package.json');
+
+    actual = findup('c/package.json', opts);
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+    assert.basename(actual, 'package.json');
+
+    actual = findup('**/ONE.txt', opts);
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+    assert.basename(actual, 'ONE.txt');
+
+    actual = findup('**/two.txt', opts);
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+    assert.basename(actual, 'two.txt');
+
+    cwd = npm('is-glob');
+    actual = findup('p*.json', {cwd: cwd});
+    assert.dirname(actual, cwd);
+    assert.basename(actual, 'package.json');
+  });
+
+  it('should support case sensitive glob patterns', function() {
+    assert.equal(normalize(findup('**/c/mochafile.txt', {cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true})), 'test/fixtures/a/b/c/Mochafile.txt');
+    assert.equal(normalize(findup('**/one.txt', {cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true})), 'test/fixtures/a/b/c/d/one.txt');
+    assert.equal(normalize(findup('**/two.txt', {cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true})), 'test/fixtures/a/b/c/two.txt');
+
+    assert.equal(normalize(findup('mocha*', {cwd: 'test/fixtures/a/b/c', nocase: true})), 'test/fixtures/a/b/c/Mochafile.txt');
+
+    var opts = {cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true};
+
+    actual = findup('**/c/mochafile.txt', opts);
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+    assert.basename(actual, 'Mochafile.txt');
+
+    actual = findup('c/mochafile.txt', opts);
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+    assert.basename(actual, (isLinux ? 'Mochafile.txt' : 'mochafile.txt'));
+
+    opts.nocase = false;
+    actual = findup('**/ONE.txt', opts);
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+    assert.basename(actual, 'ONE.txt');
+
+    actual = findup('**/two.txt', opts);
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+    assert.basename(actual, 'two.txt');
+  });
+
+  it('should support arrays of glob patterns', function() {
+    assert.equal(normalize(findup(['**/c/package.json'], {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/package.json');
+    assert.equal(normalize(findup(['**/one.txt'], {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/d/one.txt');
+    assert.equal(normalize(findup(['**/two.txt'], {cwd: 'test/fixtures/a/b/c/d/e/f/g'})), 'test/fixtures/a/b/c/two.txt');
+
+    var opts = {cwd: 'test/fixtures/a/b/c/d/e/f/g'};
+
+    actual = findup(['lslsl', '**/c/package.json'], opts);
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+    assert.basename(actual, 'package.json');
+
+    actual = findup(['lslsl', 'c/package.json'], opts);
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+    assert.basename(actual, 'package.json');
+
+    actual = findup(['lslsl', '**/ONE.txt'], opts);
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+    assert.basename(actual, 'ONE.txt');
+
+    actual = findup(['lslsl', '**/two.txt'], opts);
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+    assert.basename(actual, 'two.txt');
+
+    actual = findup(['lslsl', '**/blah.txt'], opts);
+    assert(actual === null);
+
+    cwd = npm('is-glob');
+    actual = findup(['lslsl', 'p*.json'], {cwd: cwd});
+    assert.dirname(actual, cwd);
+    assert.basename(actual, 'package.json');
+  });
+
+  it('should support micromatch `matchBase` option:', function() {
+    var opts = { matchBase: true, cwd: 'test/fixtures/a/b/c/d/e/f/g' };
+    assert.equal(normalize(findup('package.json', opts)), 'test/fixtures/a/b/c/d/e/f/g/package.json');
+    assert.equal(normalize(findup('one.txt', opts)), 'test/fixtures/a/b/c/d/one.txt');
+    assert.equal(normalize(findup('two.txt', opts)), 'test/fixtures/a/b/c/two.txt');
+
+    actual = findup('package.json', opts);
+    assert.basename(actual, 'package.json');
+    assert.dirname(actual, 'test/fixtures/a/b/c/d/e/f/g');
+
+    actual = findup('one.txt', opts);
+    assert.basename(actual, 'one.txt');
+    assert.dirname(actual, 'test/fixtures/a/b/c/d');
+
+    actual = findup('two.txt', opts);
+    assert.basename(actual, 'two.txt');
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+  });
+
+  it('should return `null` when no files are found:', function() {
+    var dep = normalize(findup('*.foo', {cwd: path.dirname(resolve.sync('micromatch'))}));
+    assert.equal(dep, null);
+    assert.equal(findup('**/b*.json', {cwd: npm('is-glob')}), null);
+    assert.equal(findup('foo.json', {cwd: 'test/fixtures/a/b/c/d/e/f/g'}), null);
+    assert.equal(findup('foo.json', {cwd: 'test/fixtures/a/b/c/d/e/f/g', matchBase: true}), null);
+  });
+
+  it('should support finding file in immediate parent dir', function () {
+    cwd = path.resolve(__dirname, 'fixtures/a/b/c');
+    var actual = findup('a.md', { cwd: cwd });
+    assert.dirname(actual, path.dirname(cwd));
+    assert.basename(actual, 'a.md');
+  });
+
+  it('should support micromatch `nocase` option:', function () {
+    actual = findup('ONE.*', { cwd: 'test/fixtures/a/b/c/d' });
+    assert.basename(actual, 'ONE.txt');
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+
+    actual = findup('ONE.*', { cwd: 'test/fixtures/a/b/c/d', nocase: true });
+    assert.basename(actual, 'one.txt');
+    assert.dirname(actual, 'test/fixtures/a/b/c/d');
+  });
+
+  it('should find files from absolute paths:', function () {
+    var actual = findup('package.json', { cwd: __dirname });
+
+    assert.basename(actual, 'package.json');
+    assert.dirname(actual, path.resolve(__dirname, '..'));
+
+    actual = findup('one.txt', { cwd: __dirname + '/fixtures/a' });
+    assert.basename(actual, 'one.txt');
+    assert.dirname(actual, 'test/fixtures/a');
+
+    actual = findup('two.txt', { cwd: __dirname + '/fixtures/a/b/c' });
+    assert.basename(actual, 'two.txt');
+    assert.dirname(actual, 'test/fixtures/a/b/c');
+  });
+
+  it('should find files in user home:', function () {
+    var actual = findup('*', { cwd: home() });
+    assert.isPath(actual);
+    assert(exists(actual));
+    assert.dirname(actual, home());
+  });
+
+  it('should find files in user home using tilde expansion:', function () {
+    var actual = findup('*', { cwd: '~' });
+    assert.isPath(actual);
+    assert(exists(actual));
+    assert.dirname(actual, home());
+  });
+
+  it('should match files in cwd before searching up', function() {
+    var actual = findup(['a.txt', 'a.md'], { cwd: __dirname + '/fixtures/a/b' });
+    assert.basename(actual, 'a.md');
+    assert.dirname(actual, 'test/fixtures/a/b');
+  });
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-findup-sync.git



More information about the Pkg-javascript-commits mailing list