diff --git a/.ci/.azure-pipelines-steps.yml b/.ci/.azure-pipelines-steps.yml deleted file mode 100644 index b54ea9b..0000000 --- a/.ci/.azure-pipelines-steps.yml +++ /dev/null @@ -1,34 +0,0 @@ -steps: -- task: NodeTool@0 - inputs: - versionSpec: '$(node_version)' - displayName: Use Node $(node_version) - -- script: npm install - displayName: npm install - -- script: npm test - displayName: Run tests - -- script: npm run coveralls - displayName: Run coveralls - env: - # Pretend to be AppVeyor for now - APPVEYOR: true - APPVEYOR_BUILD_NUMBER: $(Build.BuildNumber) - APPVEYOR_BUILD_ID: $(Agent.OS)_$(node_version) - APPVEYOR_REPO_COMMIT: $(Build.SourceVersion) - APPVEYOR_REPO_BRANCH: $(Build.SourceBranchName) - # Overwrite the AppVeyor Service Name - COVERALLS_SERVICE_NAME: Azure Pipelines - COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN_SECRET) - COVERALLS_PARALLEL: true - CI_PULL_REQUEST: $(System.PullRequest.PullRequestNumber) - -- script: npm run azure-pipelines - displayName: Write tests to xml - -- task: PublishTestResults@2 - inputs: - testResultsFiles: '**/test.xunit' - condition: succeededOrFailed() diff --git a/.ci/.azure-pipelines.yml b/.ci/.azure-pipelines.yml deleted file mode 100644 index 5ad879d..0000000 --- a/.ci/.azure-pipelines.yml +++ /dev/null @@ -1,63 +0,0 @@ -trigger: -- master -- releases/* - -jobs: - - job: Test_Linux - displayName: Run Tests on Linux - pool: - vmImage: "Ubuntu 16.04" - strategy: - matrix: - Node_v12: - node_version: 12 - Node_v10: - node_version: 10 - Node_v8: - node_version: 8 - steps: - - template: .azure-pipelines-steps.yml - - - job: Test_Windows - displayName: Run Tests on Windows - pool: - vmImage: vs2017-win2016 - strategy: - matrix: - Node_v12: - node_version: 12 - Node_v10: - node_version: 10 - Node_v8: - node_version: 8 - steps: - - template: .azure-pipelines-steps.yml - - - job: Test_MacOS - displayName: Run Tests on MacOS - pool: - vmImage: macos-10.13 - strategy: - matrix: - Node_v12: - node_version: 12 - Node_v10: - node_version: 10 - Node_v8: - node_version: 8 - steps: - - template: .azure-pipelines-steps.yml - - - job: Notify_Coveralls - displayName: Notify Coveralls that the parallel report is done - pool: - vmImage: "Ubuntu 16.04" - dependsOn: - - Test_Linux - - Test_Windows - - Test_MacOS - steps: - - script: curl -k https://coveralls.io/webhook?repo_token=$COVERALLS_REPO_TOKEN -d "payload[build_num]=$BUILD_NAME&payload[status]=done" - env: - COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN_SECRET) - BUILD_NAME: $(Build.BuildNumber) diff --git a/.eslintrc b/.eslintrc index a5a4a17..85db5b8 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,6 @@ { - "extends": "gulp" + "extends": "gulp", + "rules": { + "max-len": 0 + } } diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 0000000..3b07263 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,75 @@ +name: dev +on: + pull_request: + push: + branches: + - master + - main +env: + CI: true + +jobs: + prettier: + name: Format code + runs-on: ubuntu-latest + if: ${{ github.event_name == 'push' }} + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Prettier + uses: gulpjs/prettier_action@v3.0 + with: + commit_message: 'chore: Run prettier' + prettier_options: '--write .' + + test: + name: Tests for Node ${{ matrix.node }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + node: [10, 12, 14, 16] + os: [ubuntu-latest, windows-latest, macos-latest] + + steps: + - name: Clone repository + uses: actions/checkout@v2 + + - name: Set Node.js version + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + + - run: node --version + - run: npm --version + + - name: Install npm dependencies + run: npm install + + - name: Run lint + run: npm run lint + + - name: Run tests + run: npm test + + - name: Coveralls + uses: coverallsapp/github-action@v1.1.2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + flag-name: ${{matrix.os}}-node-${{ matrix.node }} + parallel: true + + coveralls: + needs: test + name: Finish up + + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished + uses: coverallsapp/github-action@v1.1.2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + parallel-finished: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8a10ce3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,17 @@ +name: release +on: + push: + branches: + - master + - main + +jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: GoogleCloudPlatform/release-please-action@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + release-type: node + package-name: release-please-action + bump-minor-pre-major: true diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..c96ebe0 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +coverage/ +.nyc_output/ +CHANGELOG.md diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7e3369b..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -sudo: false -language: node_js -os: - - linux - - osx -node_js: - - '12' - - '10' - - '8' -after_script: - - npm run coveralls diff --git a/LICENSE b/LICENSE index 188c3fd..531ea4d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2013-2019 Ben Alman , Blaine Bublitz , and Eric Schoffstall +Copyright (c) 2013-2019, 2021 Ben Alman , Blaine Bublitz , and Eric Schoffstall Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 00e7b38..675c127 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ # findup-sync -[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Azure Pipelines Build Status][azure-pipelines-image]][azure-pipelines-url] [![Travis Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url] +[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url] Find the first file matching a given pattern in the current directory or the nearest ancestor directory. @@ -29,31 +29,28 @@ var filepath2 = findup('{a,b}*.txt', {cwd: '/some/path', nocase: true}); ### `findup(patterns, [options])` -* `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. +- `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. ## License MIT -[micromatch]: http://github.com/jonschlinkert/micromatch + -[downloads-image]: https://img.shields.io/npm/dm/findup-sync.svg +[downloads-image]: https://img.shields.io/npm/dm/findup-sync.svg?style=flat-square [npm-url]: https://www.npmjs.com/package/findup-sync -[npm-image]: https://img.shields.io/npm/v/findup-sync.svg - -[azure-pipelines-url]: https://dev.azure.com/gulpjs/gulp/_build/latest?definitionId=7&branchName=master -[azure-pipelines-image]: https://dev.azure.com/gulpjs/gulp/_apis/build/status/findup-sync?branchName=master +[npm-image]: https://img.shields.io/npm/v/findup-sync.svg?style=flat-square +[ci-url]: https://github.com/gulpjs/findup-sync/actions?query=workflow:dev +[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/findup-sync/dev?style=flat-square +[coveralls-url]: https://coveralls.io/r/gulpjs/findup-sync +[coveralls-image]: https://img.shields.io/coveralls/gulpjs/findup-sync/master.svg -[travis-url]: https://travis-ci.org/gulpjs/findup-sync -[travis-image]: https://img.shields.io/travis/gulpjs/findup-sync.svg?label=travis-ci + -[appveyor-url]: https://ci.appveyor.com/project/gulpjs/findup-sync -[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/findup-sync.svg?label=appveyor + -[coveralls-url]: https://coveralls.io/r/gulpjs/findup-sync -[coveralls-image]: https://img.shields.io/coveralls/gulpjs/findup-sync/master.svg +[micromatch]: http://github.com/micromatch/micromatch -[gitter-url]: https://gitter.im/gulpjs/gulp -[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg + diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index a9dc80f..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,28 +0,0 @@ -# http://www.appveyor.com/docs/appveyor-yml -# http://www.appveyor.com/docs/lang/nodejs-iojs - -environment: - matrix: - # node.js - - nodejs_version: "8" - - nodejs_version: "10" - - nodejs_version: "12" - -platform: - - x86 - - x64 - -install: - # https://www.appveyor.com/docs/lang/nodejs-iojs/#installing-any-version-of-nodejs-or-iojs - - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:PLATFORM - - npm install - -test_script: - - node --version - - npm --version - - cmd: npm test - -build: off - -# build version format -version: "{build}" diff --git a/index.js b/index.js index 2a9e117..a2df8b4 100644 --- a/index.js +++ b/index.js @@ -18,7 +18,7 @@ var mm = require('micromatch'); * @api public */ -module.exports = function(patterns, options) { +module.exports = function (patterns, options) { options = options || {}; var cwd = path.resolve(resolveDir(options.cwd || '')); @@ -27,7 +27,9 @@ module.exports = function(patterns, options) { } if (!Array.isArray(patterns)) { - throw new TypeError('findup-sync expects a string or array as the first argument.'); + throw new TypeError( + 'findup-sync expects a string or array as the first argument.' + ); } return lookup(cwd, patterns, options); @@ -73,7 +75,7 @@ function matchFile(cwd, pattern, opts) { } function findFile(cwd, filename, options) { - var fp = cwd ? path.resolve(cwd, filename) : filename; + var fp = path.resolve(cwd, filename); return detect(fp, options); } @@ -83,5 +85,6 @@ function tryReaddirSync(fp) { } catch (err) { // Ignore error } + /* istanbul ignore next */ return []; } diff --git a/package.json b/package.json index af6fc83..7dead6a 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "repository": "gulpjs/findup-sync", "license": "MIT", "engines": { - "node": ">= 8" + "node": ">= 10.13.0" }, "main": "index.js", "files": [ @@ -22,26 +22,33 @@ "scripts": { "lint": "eslint .", "pretest": "npm run lint", - "test": "nyc mocha --async-only", - "azure-pipelines": "nyc mocha --async-only --reporter xunit -O output=test.xunit", - "coveralls": "nyc report --reporter=text-lcov | coveralls" + "test": "nyc mocha --async-only" }, "dependencies": { "detect-file": "^1.0.0", - "is-glob": "^4.0.0", - "micromatch": "^4.0.2", + "is-glob": "^4.0.3", + "micromatch": "^4.0.4", "resolve-dir": "^1.0.1" }, "devDependencies": { - "coveralls": "github:phated/node-coveralls#2.x", - "eslint": "^6.0.1", - "eslint-config-gulp": "^3.0.1", - "expect": "^1.20.2", - "homedir-polyfill": "^1.0.1", + "eslint": "^7.21.0", + "eslint-config-gulp": "^5.0.1", + "eslint-plugin-node": "^11.1.0", + "expect": "^27.3.1", + "homedir-polyfill": "^1.0.3", "mocha": "^6.1.4", "normalize-path": "^3.0.0", - "nyc": "^14.1.1", - "resolve": "^1.4.0" + "nyc": "^15.1.0", + "resolve": "^1.20.0" + }, + "nyc": { + "reporter": [ + "lcov", + "text-summary" + ] + }, + "prettier": { + "singleQuote": true }, "keywords": [ "file", diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index 06b940f..0000000 --- a/test/.eslintrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "gulp/test" -} diff --git a/test/support/index.js b/test/support/index.js index 485fa55..048c791 100644 --- a/test/support/index.js +++ b/test/support/index.js @@ -3,18 +3,17 @@ var path = require('path'); var normalizePath = require('normalize-path'); var resolve = require('resolve'); -var expect = require('expect'); -exports.normalize = function(filepath) { +exports.normalize = function (filepath) { return filepath ? normalizePath(path.relative('.', filepath)) : null; }; -exports.chdir = function(dir) { +exports.chdir = function (dir) { // store current cwd var orig = process.cwd(); // set cwd to the given `dir` process.chdir(dir); - return function() { + return function () { // restore original `cwd` process.chdir(orig); }; @@ -24,25 +23,41 @@ exports.npm = function npm(name) { return path.dirname(resolve.sync(name)); }; +function matcherResult(pass, msg) { + return { + pass: pass, + message: function () { + return msg; + }, + }; +} + exports.expectExtras = { - isPath: function() { - var filepath = this.actual; - expect(filepath).toExist(); - expect(filepath).toBeA('string'); - return this; + isPath: function (actual) { + if (typeof actual === 'string') { + return matcherResult(true, ''); + } + return matcherResult(false, '"' + actual + '" is not a string'); }, - toHaveBasename: function(basename) { - var filepath = this.actual; - expect(filepath).toExist(); - expect(filepath).toBeA('string'); - expect(path.basename(filepath)).toEqual(basename); - return this; + toHaveBasename: function (actual, basename) { + var fileName = path.basename(actual); + if (fileName === basename) { + return matcherResult(true, ''); + } + return matcherResult( + false, + 'The basename of "' + actual + '" is not equal to "' + basename + '".' + ); }, - toHaveDirname: function(dirname) { - var filepath = this.actual; - expect(filepath).toExist(); - expect(filepath).toBeA('string'); - expect(path.dirname(path.resolve(filepath))).toEqual(path.resolve(dirname)); + toHaveDirname: function (actual, dirname) { + var filePath = path.dirname(path.resolve(actual)); + var expected = path.resolve(dirname); + if (filePath === expected) { + return matcherResult(true, ''); + } + return matcherResult( + false, + 'The direname of "' + actual + '" is not equal to "' + expected + '".' + ); }, }; - diff --git a/test/test.js b/test/test.js index be17b2c..59bf098 100644 --- a/test/test.js +++ b/test/test.js @@ -19,104 +19,122 @@ var npm = support.npm; var isLinux = process.platform === 'linux'; var cwd, actual; -describe('findup-sync', function() { - - before(function(done) { +describe('findup-sync', function () { + before(function (done) { fs.writeFileSync(home() + '/_aaa.txt', ''); fs.writeFileSync(home() + '/_bbb.txt', ''); done(); }); - after(function(done) { + after(function (done) { fs.unlinkSync(home() + '/_aaa.txt'); fs.unlinkSync(home() + '/_bbb.txt'); done(); }); - it('should throw when the first arg is not a string or array:', function(cb) { + 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) { - expect(err.message).toEqual('findup-sync expects a string or array as the first argument.'); + expect(err.message).toEqual( + 'findup-sync expects a string or array as the first argument.' + ); cb(); } }); - it('should work when no cwd is given', function(done) { + it('should work when no cwd is given', function (done) { var actual = findup('package.json'); - expect(actual).toExist(); + expect(actual).toBeTruthy(); expect(actual).toHaveDirname(path.resolve(__dirname, '..')); expect(actual).toHaveBasename('package.json'); expect(normalize(findup('package.json'))).toEqual('package.json'); done(); }); - it('should find files in a child directory', function(done) { + it('should find files in a child directory', function (done) { 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'); - expect(actual).toExist(); - expect(exists(actual)).toExist(); + expect(actual).toBeTruthy(); + expect(exists(actual)).toBeTruthy(); expect(actual).toEqual(expected); restore(); done(); }); - it('should find case sensitive files in a child directory', function(done) { - var expected = path.resolve(__dirname, 'fixtures/a/b/', (isLinux ? 'Mochafile.txt' : 'mochafile.txt')); + it('should find case sensitive files in a child directory', function (done) { + 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 }); - expect(actual).toExist(); - expect(exists(actual)).toExist(); + expect(actual).toBeTruthy(); + expect(exists(actual)).toBeTruthy(); expect(actual).toEqual(expected); restore(); done(); }); - it('should find files in a child directory relative to a cwd', function(done) { + it('should find files in a child directory relative to a cwd', function (done) { 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' }); - expect(actualFile).toExist(); - expect(exists(actualFile)).toExist(); + expect(actualFile).toBeTruthy(); + expect(exists(actualFile)).toBeTruthy(); expect(actualFile).toEqual(expectedFile); var actualA = findup('a.txt', { cwd: 'a/b/c/d/e/f' }); - expect(actualA).toExist(); - expect(exists(actualA)).toExist(); + expect(actualA).toBeTruthy(); + expect(exists(actualA)).toBeTruthy(); expect(actualA).toEqual(expectedA); tempDir(); done(); }); - it('should find case sensitive files in a child directory relative to a cwd', function(done) { - var expectedFile = path.resolve(__dirname, 'fixtures/a/b', (isLinux ? 'Mochafile.txt' : 'mochafile.txt')); + it('should find case sensitive files in a child directory relative to a cwd', function (done) { + 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 }); - expect(actualFile).toExist(); - expect(exists(actualFile)).toExist(); + var actualFile = findup('a/b/mochafile.txt', { + cwd: 'a/b/c/d', + nocase: true, + }); + expect(actualFile).toBeTruthy(); + expect(exists(actualFile)).toBeTruthy(); expect(actualFile).toEqual(expectedFile); var actualA = findup('a.txt', { cwd: 'a/b/c/d/e/f' }); - expect(actualA).toExist(); - expect(exists(actualA)).toExist(); + expect(actualA).toBeTruthy(); + expect(exists(actualA)).toBeTruthy(); expect(actualA).toEqual(expectedA); tempDir(); done(); }); - it('should support normal (non-glob) file paths:', function(done) { - var normPath = normalize(findup('package.json', { cwd: path.dirname(resolve.sync('normalize-path')) })); + it('should support normal (non-glob) file paths:', function (done) { + var normPath = normalize( + findup('package.json', { + cwd: path.dirname(resolve.sync('normalize-path')), + }) + ); expect(normPath).toEqual('node_modules/normalize-path/package.json'); - var isGlob = normalize(findup('package.json', { cwd: path.dirname(resolve.sync('is-glob')) })); + var isGlob = normalize( + findup('package.json', { cwd: path.dirname(resolve.sync('is-glob')) }) + ); expect(isGlob).toEqual('node_modules/is-glob/package.json'); cwd = path.dirname(resolve.sync('normalize-path')); @@ -135,17 +153,28 @@ describe('findup-sync', function() { done(); }); - it('should support normal (non-glob) case sensitive file paths:', function(done) { - actual = findup('c/mochafile.txt', { cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true }); + it('should support normal (non-glob) case sensitive file paths:', function (done) { + actual = findup('c/mochafile.txt', { + cwd: 'test/fixtures/a/b/c/d/e/f/g', + nocase: true, + }); expect(actual).toHaveBasename(isLinux ? 'Mochafile.txt' : 'mochafile.txt'); expect(actual).toHaveDirname('test/fixtures/a/b/c'); done(); }); - it('should support glob patterns', function(done) { - expect(normalize(findup('**/c/package.json', { cwd: 'test/fixtures/a/b/c/d/e/f/g' }))).toEqual('test/fixtures/a/b/c/package.json'); - expect(normalize(findup('**/one.txt', { cwd: 'test/fixtures/a/b/c/d/e/f/g' }))).toEqual('test/fixtures/a/b/c/d/one.txt'); - expect(normalize(findup('**/two.txt', { cwd: 'test/fixtures/a/b/c/d/e/f/g' }))).toEqual('test/fixtures/a/b/c/two.txt'); + it('should support glob patterns', function (done) { + expect( + normalize( + findup('**/c/package.json', { cwd: 'test/fixtures/a/b/c/d/e/f/g' }) + ) + ).toEqual('test/fixtures/a/b/c/package.json'); + expect( + normalize(findup('**/one.txt', { cwd: 'test/fixtures/a/b/c/d/e/f/g' })) + ).toEqual('test/fixtures/a/b/c/d/one.txt'); + expect( + normalize(findup('**/two.txt', { cwd: 'test/fixtures/a/b/c/d/e/f/g' })) + ).toEqual('test/fixtures/a/b/c/two.txt'); var pkg = normalize(findup('p*.json', { cwd: npm('micromatch') })); expect(pkg).toEqual('node_modules/micromatch/package.json'); @@ -175,12 +204,35 @@ describe('findup-sync', function() { done(); }); - it('should support case sensitive glob patterns', function(done) { - expect(normalize(findup('**/c/mochafile.txt', { cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true }))).toEqual('test/fixtures/a/b/c/Mochafile.txt'); - expect(normalize(findup('**/one.txt', { cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true }))).toEqual('test/fixtures/a/b/c/d/one.txt'); - expect(normalize(findup('**/two.txt', { cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true }))).toEqual('test/fixtures/a/b/c/two.txt'); - - expect(normalize(findup('mocha*', { cwd: 'test/fixtures/a/b/c', nocase: true }))).toEqual('test/fixtures/a/b/c/Mochafile.txt'); + it('should support case sensitive glob patterns', function (done) { + expect( + normalize( + findup('**/c/mochafile.txt', { + cwd: 'test/fixtures/a/b/c/d/e/f/g', + nocase: true, + }) + ) + ).toEqual('test/fixtures/a/b/c/Mochafile.txt'); + expect( + normalize( + findup('**/one.txt', { + cwd: 'test/fixtures/a/b/c/d/e/f/g', + nocase: true, + }) + ) + ).toEqual('test/fixtures/a/b/c/d/one.txt'); + expect( + normalize( + findup('**/two.txt', { + cwd: 'test/fixtures/a/b/c/d/e/f/g', + nocase: true, + }) + ) + ).toEqual('test/fixtures/a/b/c/two.txt'); + + expect( + normalize(findup('mocha*', { cwd: 'test/fixtures/a/b/c', nocase: true })) + ).toEqual('test/fixtures/a/b/c/Mochafile.txt'); var opts = { cwd: 'test/fixtures/a/b/c/d/e/f/g', nocase: true }; @@ -203,10 +255,18 @@ describe('findup-sync', function() { done(); }); - it('should support arrays of glob patterns', function(done) { - expect(normalize(findup(['**/c/package.json'], { cwd: 'test/fixtures/a/b/c/d/e/f/g' }))).toEqual('test/fixtures/a/b/c/package.json'); - expect(normalize(findup(['**/one.txt'], { cwd: 'test/fixtures/a/b/c/d/e/f/g' }))).toEqual('test/fixtures/a/b/c/d/one.txt'); - expect(normalize(findup(['**/two.txt'], { cwd: 'test/fixtures/a/b/c/d/e/f/g' }))).toEqual('test/fixtures/a/b/c/two.txt'); + it('should support arrays of glob patterns', function (done) { + expect( + normalize( + findup(['**/c/package.json'], { cwd: 'test/fixtures/a/b/c/d/e/f/g' }) + ) + ).toEqual('test/fixtures/a/b/c/package.json'); + expect( + normalize(findup(['**/one.txt'], { cwd: 'test/fixtures/a/b/c/d/e/f/g' })) + ).toEqual('test/fixtures/a/b/c/d/one.txt'); + expect( + normalize(findup(['**/two.txt'], { cwd: 'test/fixtures/a/b/c/d/e/f/g' })) + ).toEqual('test/fixtures/a/b/c/two.txt'); var opts = { cwd: 'test/fixtures/a/b/c/d/e/f/g' }; @@ -227,7 +287,7 @@ describe('findup-sync', function() { expect(actual).toHaveBasename('two.txt'); actual = findup(['lslsl', '**/blah.txt'], opts); - expect(actual === null).toExist(); + expect(actual === null).toBeTruthy(); cwd = npm('is-glob'); actual = findup(['lslsl', 'p*.json'], { cwd: cwd }); @@ -236,11 +296,17 @@ describe('findup-sync', function() { done(); }); - it('should support micromatch `matchBase` option:', function(done) { + it('should support micromatch `matchBase` option:', function (done) { var opts = { matchBase: true, cwd: 'test/fixtures/a/b/c/d/e/f/g' }; - expect(normalize(findup('package.json', opts))).toEqual('test/fixtures/a/b/c/d/e/f/g/package.json'); - expect(normalize(findup('one.txt', opts))).toEqual('test/fixtures/a/b/c/d/one.txt'); - expect(normalize(findup('two.txt', opts))).toEqual('test/fixtures/a/b/c/two.txt'); + expect(normalize(findup('package.json', opts))).toEqual( + 'test/fixtures/a/b/c/d/e/f/g/package.json' + ); + expect(normalize(findup('one.txt', opts))).toEqual( + 'test/fixtures/a/b/c/d/one.txt' + ); + expect(normalize(findup('two.txt', opts))).toEqual( + 'test/fixtures/a/b/c/two.txt' + ); actual = findup('package.json', opts); expect(actual).toHaveBasename('package.json'); @@ -256,16 +322,25 @@ describe('findup-sync', function() { done(); }); - it('should return `null` when no files are found:', function(done) { - var dep = normalize(findup('*.foo', { cwd: path.dirname(resolve.sync('micromatch')) })); + it('should return `null` when no files are found:', function (done) { + var dep = normalize( + findup('*.foo', { cwd: path.dirname(resolve.sync('micromatch')) }) + ); expect(dep).toEqual(null); expect(findup('**/b*.json', { cwd: npm('is-glob') })).toEqual(null); - expect(findup('foo.json', { cwd: 'test/fixtures/a/b/c/d/e/f/g' })).toEqual(null); - expect(findup('foo.json', { cwd: 'test/fixtures/a/b/c/d/e/f/g', matchBase: true })).toEqual(null); + expect(findup('foo.json', { cwd: 'test/fixtures/a/b/c/d/e/f/g' })).toEqual( + null + ); + expect( + findup('foo.json', { + cwd: 'test/fixtures/a/b/c/d/e/f/g', + matchBase: true, + }) + ).toEqual(null); done(); }); - it('should support finding file in immediate parent dir', function(done) { + it('should support finding file in immediate parent dir', function (done) { cwd = path.resolve(__dirname, 'fixtures/a/b/c'); var actual = findup('a.md', { cwd: cwd }); expect(actual).toHaveDirname(path.dirname(cwd)); @@ -273,7 +348,7 @@ describe('findup-sync', function() { done(); }); - it('should support micromatch `nocase` option:', function(done) { + it('should support micromatch `nocase` option:', function (done) { actual = findup('ONE.*', { cwd: 'test/fixtures/a/b/c/d' }); expect(actual).toHaveBasename('ONE.txt'); expect(actual).toHaveDirname('test/fixtures/a/b/c'); @@ -284,7 +359,7 @@ describe('findup-sync', function() { done(); }); - it('should find files from absolute paths:', function(done) { + it('should find files from absolute paths:', function (done) { var actual = findup('package.json', { cwd: __dirname }); expect(actual).toHaveBasename('package.json'); @@ -300,24 +375,26 @@ describe('findup-sync', function() { done(); }); - it('should find files in user home:', function(done) { + it('should find files in user home:', function (done) { var actual = findup('*', { cwd: home() }); expect(actual).isPath(); - expect(exists(actual)).toExist(); + expect(exists(actual)).toBeTruthy(); expect(actual).toHaveDirname(home()); done(); }); - it('should find files in user home using tilde expansion:', function(done) { + it('should find files in user home using tilde expansion:', function (done) { var actual = findup('*', { cwd: '~' }); expect(actual).isPath(); - expect(exists(actual)).toExist(); + expect(exists(actual)).toBeTruthy(); expect(actual).toHaveDirname(home()); done(); }); - it('should match files in cwd before searching up', function(done) { - var actual = findup(['a.txt', 'a.md'], { cwd: __dirname + '/fixtures/a/b' }); + it('should match files in cwd before searching up', function (done) { + var actual = findup(['a.txt', 'a.md'], { + cwd: __dirname + '/fixtures/a/b', + }); expect(actual).toHaveBasename('a.md'); expect(actual).toHaveDirname('test/fixtures/a/b'); done();