From 00f59689d0eb9668d939a85e06428a0906587a6f Mon Sep 17 00:00:00 2001 From: Takayuki Sato Date: Sat, 24 Jul 2021 13:31:09 +0900 Subject: [PATCH] chore!: Normalize repository, dropping node <10.13 support (#40) Co-authored-by: Blaine Bublitz --- .eslintrc | 5 +- .github/security.md | 4 - .github/workflows/dev.yml | 75 +++++++++++ .github/workflows/release.yml | 16 +++ .gitignore | 50 ++++++-- .prettierignore | 3 + .travis.yml | 11 -- LICENSE | 35 +++--- README.md | 44 +++---- appveyor.yml | 26 ---- index.js | 10 +- lib/extension.js | 2 +- lib/normalize.js | 2 +- lib/register.js | 2 +- package.json | 28 +++-- test/.eslintrc | 3 - test/{lib => }/extension.test.js | 52 ++++---- test/fixtures/cwd/test.foo | 0 test/index.js | 205 ++++++++++++++++++------------- 19 files changed, 344 insertions(+), 229 deletions(-) delete mode 100644 .github/security.md create mode 100644 .github/workflows/dev.yml create mode 100644 .github/workflows/release.yml create mode 100644 .prettierignore delete mode 100644 .travis.yml delete mode 100644 appveyor.yml delete mode 100644 test/.eslintrc rename test/{lib => }/extension.test.js (69%) create mode 100644 test/fixtures/cwd/test.foo diff --git a/.eslintrc b/.eslintrc index a5a4a17..76e7721 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,6 @@ { - "extends": "gulp" + "extends": "gulp", + "rules": { + "max-statements": 0 + } } diff --git a/.github/security.md b/.github/security.md deleted file mode 100644 index 6cb3e3b..0000000 --- a/.github/security.md +++ /dev/null @@ -1,4 +0,0 @@ -## Security contact information - -To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). -Tidelift will coordinate the fix and disclosure. 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..87cd13c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,16 @@ +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 diff --git a/.gitignore b/.gitignore index 6f63646..58a757a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,15 @@ # Logs logs *.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* # Runtime data pids *.pid *.seed +*.pid.lock # Directory for instrumented libs generated by jscoverage/JSCover lib-cov @@ -13,19 +17,51 @@ lib-cov # Coverage directory used by tools like istanbul coverage +# nyc test coverage +.nyc_output + # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) .grunt -# Compiled binary addons (http://nodejs.org/api/addons.html) +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) build/Release -# Dependency directory -# Commenting this out is preferred by some people, see -# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- -node_modules +# Dependency directories +node_modules/ +jspm_packages/ -# Users Environment Variables -.lock-wscript +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# next.js build output +.next # Garbage files .DS_Store + +# Test results +test.xunit 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 7e14b19..0000000 --- a/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -sudo: false -language: node_js -node_js: - - '10' - - '8' - - '6' - - '4' - - '0.12' - - '0.10' -after_script: - - npm run coveralls diff --git a/LICENSE b/LICENSE index 41ed300..4f92523 100644 --- a/LICENSE +++ b/LICENSE @@ -1,24 +1,21 @@ The MIT License (MIT) -Copyright (c) 2014-2019 Tyler Kellen , Blaine Bublitz , and Eric Schoffstall +Copyright (c) 2014-2019, 2021 Tyler Kellen , 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 in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index cf96e4f..6e65abb 100644 --- a/README.md +++ b/README.md @@ -6,24 +6,16 @@ # rechoir -[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-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] Prepare a node environment to require files with different extensions. ## What is it? -This module, in conjunction with [interpret]-like objects, can register any filetype the npm ecosystem has a module loader for. This library is a dependency of [Liftoff]. +This module, in conjunction with [interpret]-like objects, can register any filetype the npm ecosystem has a module loader for. This library is a dependency of [liftoff]. **Note:** While `rechoir` will automatically load and register transpilers like `coffee-script`, you must provide a local installation. The transpilers are **not** bundled with this module. - -## rechoir for enterprise - -Available as part of the Tidelift Subscription - -The maintainers of rechoir and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-rechoir?utm_source=npm-rechoir&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) - - ## Usage ```js @@ -42,13 +34,13 @@ console.log(require('./test/fixtures/test.toml')); ### `prepare(config, filepath, [cwd], [noThrow])` -Look for a module loader associated with the provided file and attempt require it. If necessary, run any setup required to inject it into [require.extensions](http://nodejs.org/api/globals.html#globals_require_extensions). +Look for a module loader associated with the provided file and attempt require it. If necessary, run any setup required to inject it into [require.extensions]. `config` An [interpret]-like configuration object. `filepath` A file whose type you'd like to register a module loader for. -`cwd` An optional path to start searching for the module required to load the requested file. Defaults to the directory of `filepath`. +`cwd` An optional path to start searching for the module required to load the requested file. Defaults to the directory of `filepath`. `noThrow` An optional boolean indicating if the method should avoid throwing. @@ -62,22 +54,20 @@ If a loader is already registered, this will simply return `true`. MIT -[interpret]: http://github.com/gulpjs/interpret -[Liftoff]: http://github.com/gulpjs/liftoff - -[downloads-image]: http://img.shields.io/npm/dm/rechoir.svg + +[downloads-image]: https://img.shields.io/npm/dm/rechoir.svg?style=flat-square [npm-url]: https://www.npmjs.com/package/rechoir -[npm-image]: http://img.shields.io/npm/v/rechoir.svg - -[travis-url]: https://travis-ci.org/gulpjs/rechoir -[travis-image]: http://img.shields.io/travis/gulpjs/rechoir.svg?label=travis-ci +[npm-image]: https://img.shields.io/npm/v/rechoir.svg?style=flat-square -[appveyor-url]: https://ci.appveyor.com/project/gulpjs/rechoir -[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/rechoir.svg?label=appveyor +[ci-url]: https://github.com/gulpjs/rechoir/actions?query=workflow:dev +[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/rechoir/dev?style=flat-square [coveralls-url]: https://coveralls.io/r/gulpjs/rechoir -[coveralls-image]: http://img.shields.io/coveralls/gulpjs/rechoir/master.svg - -[gitter-url]: https://gitter.im/gulpjs/gulp -[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg - +[coveralls-image]: https://img.shields.io/coveralls/gulpjs/rechoir/master.svg + + + +[interpret]: https://github.com/gulpjs/interpret +[require.extensions]: https://nodejs.org/api/modules.html#modules_require_extensions +[liftoff]: https://github.com/js-cli/js-liftoff + diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index bd65027..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,26 +0,0 @@ -# http://www.appveyor.com/docs/appveyor-yml -# http://www.appveyor.com/docs/lang/nodejs-iojs - -environment: - matrix: - # node.js - - nodejs_version: "0.10" - - nodejs_version: "0.12" - - nodejs_version: "4" - - nodejs_version: "6" - - nodejs_version: "8" - - nodejs_version: "10" - -install: - - ps: Install-Product node $env:nodejs_version - - 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 eb9ec70..cc76ae3 100644 --- a/index.js +++ b/index.js @@ -4,14 +4,14 @@ var extension = require('./lib/extension'); var normalize = require('./lib/normalize'); var register = require('./lib/register'); -exports.prepare = function(extensions, filepath, cwd, nothrow) { +exports.prepare = function (extensions, filepath, cwd, nothrow) { var config, usedExtension, err, option, attempt, error; var attempts = []; var onlyErrors = true; var exts = extension(filepath); if (exts) { - exts.some(function(ext) { + exts.some(function (ext) { usedExtension = ext; config = normalize(extensions[ext]); return !!config; @@ -40,7 +40,7 @@ exports.prepare = function(extensions, filepath, cwd, nothrow) { for (var i in config) { option = config[i]; attempt = register(cwd, option.module, option.register); - error = (attempt instanceof Error) ? attempt : null; + error = attempt instanceof Error ? attempt : null; if (error) { attempt = null; } @@ -55,7 +55,9 @@ exports.prepare = function(extensions, filepath, cwd, nothrow) { } } if (onlyErrors) { - err = new Error('Unable to use specified module loaders for "' + usedExtension + '".'); + err = new Error( + 'Unable to use specified module loaders for "' + usedExtension + '".' + ); err.failures = attempts; if (nothrow) { return err; diff --git a/lib/extension.js b/lib/extension.js index cc8070d..a5e4585 100644 --- a/lib/extension.js +++ b/lib/extension.js @@ -34,7 +34,7 @@ function getPossibleExtensions(longExtension) { return arr; } -module.exports = function(input) { +module.exports = function (input) { var basename = path.basename(input); var longExtension = getLongExtension(basename); if (!longExtension) { diff --git a/lib/normalize.js b/lib/normalize.js index 7e974f6..af1122f 100644 --- a/lib/normalize.js +++ b/lib/normalize.js @@ -5,7 +5,7 @@ function normalizer(config) { return config; } -module.exports = function(config) { +module.exports = function (config) { if (Array.isArray(config)) { return config.map(normalizer); } diff --git a/lib/register.js b/lib/register.js index f5d2336..843e8ad 100644 --- a/lib/register.js +++ b/lib/register.js @@ -1,6 +1,6 @@ var resolve = require('resolve'); -module.exports = function(cwd, moduleName, register) { +module.exports = function (cwd, moduleName, register) { var result; try { var modulePath = resolve.sync(moduleName, { basedir: cwd }); diff --git a/package.json b/package.json index 00d125c..84249e8 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "repository": "gulpjs/rechoir", "license": "MIT", "engines": { - "node": ">= 0.10" + "node": ">= 10.13.0" }, "main": "index.js", "files": [ @@ -21,20 +21,26 @@ "scripts": { "lint": "eslint .", "pretest": "rm -rf tmp/ && npm run lint", - "test": "mocha --async-only test test/lib", - "cover": "istanbul cover _mocha --report lcovonly test test/lib", - "coveralls": "npm run cover && istanbul-coveralls" + "test": "nyc mocha --async-only" }, "dependencies": { - "resolve": "^1.9.0" + "resolve": "^1.20.0" }, "devDependencies": { - "eslint": "^2.13.0", - "eslint-config-gulp": "^3.0.1", - "expect": "^1.20.2", - "istanbul": "^0.4.3", - "istanbul-coveralls": "^1.0.3", - "mocha": "^3.5.3" + "eslint": "^7.21.0", + "eslint-config-gulp": "^5.0.1", + "expect": "^27.0.0", + "mocha": "^8.3.0", + "nyc": "^15.1.0" + }, + "nyc": { + "reporter": [ + "lcov", + "text-summary" + ] + }, + "prettier": { + "singleQuote": true }, "keywords": [ "require", 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/lib/extension.test.js b/test/extension.test.js similarity index 69% rename from test/lib/extension.test.js rename to test/extension.test.js index 2901f72..b320fea 100644 --- a/test/lib/extension.test.js +++ b/test/extension.test.js @@ -1,125 +1,125 @@ 'use strict'; var expect = require('expect'); -var extension = require('../../lib/extension'); +var extension = require('../lib/extension'); -describe('Take out possible extensions from a file path', function() { +describe('Take out possible extensions from a file path', function () { - it('should return an extension: ".js" from "app.js"', function(done) { - expect(extension('app.js')).toEqual('.js'); - expect(extension('a/b/c/app.js')).toEqual('.js'); + it('should return an extension: ".js" from "app.js"', function (done) { + expect(extension('app.js')).toEqual(['.js']); + expect(extension('a/b/c/app.js')).toEqual(['.js']); done(); }); - it('should return extensions: ".babel.js" and ".js" from "app.babel.js"', function(done) { + it('should return extensions: ".babel.js" and ".js" from "app.babel.js"', function (done) { expect(extension('app.babel.js')).toEqual(['.babel.js', '.js']); expect(extension('a/b/c/app.babel.js')).toEqual(['.babel.js', '.js']); done(); }); - it('should return extensions: ".aaa.bbb.ccc", ".aaa.bbb" and ".ccc" from "app.aaa.bbb.ccc"', function(done) { + it('should return extensions: ".aaa.bbb.ccc", ".aaa.bbb" and ".ccc" from "app.aaa.bbb.ccc"', function (done) { expect(extension('app.aaa.bbb.ccc')).toEqual(['.aaa.bbb.ccc', '.bbb.ccc', '.ccc']); expect(extension('a/b/c/app.aaa.bbb.ccc')).toEqual(['.aaa.bbb.ccc', '.bbb.ccc', '.ccc']); done(); }); - it('should return an extension: ".j" from "app.j"', function(done) { - expect(extension('app.j')).toEqual('.j'); - expect(extension('a/b/c/app.j')).toEqual('.j'); + it('should return an extension: ".j" from "app.j"', function (done) { + expect(extension('app.j')).toEqual(['.j']); + expect(extension('a/b/c/app.j')).toEqual(['.j']); done(); }); - it('should return extensions: ".b.j" and ".j" from "app.b.j"', function(done) { + it('should return extensions: ".b.j" and ".j" from "app.b.j"', function (done) { expect(extension('app.b.j')).toEqual(['.b.j', '.j']); expect(extension('a/b/c/app.b.j')).toEqual(['.b.j', '.j']); done(); }); - it('should return extensions: ".a.b.c", ".a.b" and ".c" from "app.a.b.c"', function(done) { + it('should return extensions: ".a.b.c", ".a.b" and ".c" from "app.a.b.c"', function (done) { expect(extension('app.a.b.c')).toEqual(['.a.b.c', '.b.c', '.c']); expect(extension('a/b/c/app.a.b.c')).toEqual(['.a.b.c', '.b.c', '.c']); done(); }); - it('should return undefined from "."', function(done) { + it('should return undefined from "."', function (done) { expect(extension('.')).toBe(undefined); expect(extension('a/b/c/.')).toBe(undefined); done(); }); - it('should return undefined from ".."', function(done) { + it('should return undefined from ".."', function (done) { expect(extension('..')).toBe(undefined); expect(extension('a/b/c/..')).toBe(undefined); done(); }); - it('should return undefined from "..."', function(done) { + it('should return undefined from "..."', function (done) { expect(extension('...')).toBe(undefined); expect(extension('a/b/c/...')).toBe(undefined); done(); }); - it('should return undefined from "a."', function(done) { + it('should return undefined from "a."', function (done) { expect(extension('a.')).toBe(undefined); expect(extension('a/b/c/a.')).toBe(undefined); done(); }); - it('should return undefined from "app."', function(done) { + it('should return undefined from "app."', function (done) { expect(extension('app.')).toBe(undefined); expect(extension('a/b/c/app.')).toBe(undefined); done(); }); - it('should return undefined from "a.b.c."', function(done) { + it('should return undefined from "a.b.c."', function (done) { expect(extension('a.b.c.')).toBe(undefined); expect(extension('a/b/c/a.b.c.')).toBe(undefined); done(); }); - it('should return undefined from ".a"', function(done) { + it('should return undefined from ".a"', function (done) { expect(extension('.a')).toBe(undefined); expect(extension('a/b/c/.a')).toBe(undefined); done(); }); - it('should return undefined from ".app"', function(done) { + it('should return undefined from ".app"', function (done) { expect(extension('.app')).toBe(undefined); expect(extension('a/b/c/.app')).toBe(undefined); done(); }); - it('should return undefined from ".a."', function(done) { + it('should return undefined from ".a."', function (done) { expect(extension('.a.')).toBe(undefined); expect(extension('a/b/c/.a.')).toBe(undefined); done(); }); - it('should return undefined from ".app."', function(done) { + it('should return undefined from ".app."', function (done) { expect(extension('.app.')).toBe(undefined); expect(extension('a/b/c/.app.')).toBe(undefined); done(); }); - it('should return undefined from ".a.b.c."', function(done) { + it('should return undefined from ".a.b.c."', function (done) { expect(extension('.a.b.c.')).toBe(undefined); expect(extension('a/b/c/.a.b.c.')).toBe(undefined); done(); }); - it('should return ".b.c" and ".c" from ".a.b.c"', function(done) { + it('should return ".b.c" and ".c" from ".a.b.c"', function (done) { expect(extension('.a.b.c')).toEqual(['.b.c', '.c']); expect(extension('a/b/c/.a.b.c')).toEqual(['.b.c', '.c']); done(); }); - it('should return ".bb.cc" and ".cc" from ".aa.bb.cc"', function(done) { + it('should return ".bb.cc" and ".cc" from ".aa.bb.cc"', function (done) { expect(extension('.aa.bb.cc')).toEqual(['.bb.cc', '.cc']); expect(extension('a/b/c/.aa.bb.cc')).toEqual(['.bb.cc', '.cc']); done(); }); - it('should return "..b" and ".b" from ".a..b"', function(done) { + it('should return "..b" and ".b" from ".a..b"', function (done) { expect(extension('.a..b')).toEqual(['..b', '.b']); expect(extension('a/b/c/.a..b')).toEqual(['..b', '.b']); done(); diff --git a/test/fixtures/cwd/test.foo b/test/fixtures/cwd/test.foo new file mode 100644 index 0000000..e69de29 diff --git a/test/index.js b/test/index.js index a0a0f3c..875ed4a 100644 --- a/test/index.js +++ b/test/index.js @@ -10,7 +10,7 @@ var register = require('../lib/register'); // save the original Module._extensions var originalExtensions = Object.keys(Module._extensions); -var original = originalExtensions.reduce(function(result, key) { +var original = originalExtensions.reduce(function (result, key) { result[key] = require.extensions[key]; return result; }, {}); @@ -40,11 +40,9 @@ function cleanup(done) { done(); } -describe('rechoir', function() { - - describe('extension', function() { - - it('should extract extension from filename/path from the first dot', function(done) { +describe('rechoir', function () { + describe('extension', function () { + it('should extract extension from filename/path from the first dot', function (done) { expect(extension('file.js')[0]).toEqual('.js'); expect(extension('file.tmp.dot.js')[0]).toEqual('.tmp.dot.js'); expect(extension('file.tmp.dot.js')[1]).toEqual('.dot.js'); @@ -52,45 +50,66 @@ describe('rechoir', function() { expect(extension('relative/path/to/file.js')[0]).toEqual('.js'); expect(extension('relative/path/to/file.dot.js')[0]).toEqual('.dot.js'); expect(extension('relative/path/to/file.dot.js')[1]).toEqual('.js'); - expect(extension('relative/path.with.dot/to/file.dot.js')[0]).toEqual('.dot.js'); - expect(extension('relative/path.with.dot/to/file.dot.js')[1]).toEqual('.js'); + expect(extension('relative/path.with.dot/to/file.dot.js')[0]).toEqual( + '.dot.js' + ); + expect(extension('relative/path.with.dot/to/file.dot.js')[1]).toEqual( + '.js' + ); done(); }); - it('does not match any if the path ends in a dot', function(done) { + it('does not match any if the path ends in a dot', function (done) { expect(extension('file.js.')).toEqual(undefined); done(); }); - it('treats additional dots as a separate extension', function(done) { + it('treats additional dots as a separate extension', function (done) { // Double - expect(extension('file.babel..js')).toEqual(['.babel..js', '..js', '.js']); - expect(extension('file..babel.js')).toEqual(['..babel.js', '.babel.js', '.js']); + expect(extension('file.babel..js')).toEqual([ + '.babel..js', + '..js', + '.js', + ]); + expect(extension('file..babel.js')).toEqual([ + '..babel.js', + '.babel.js', + '.js', + ]); // Triple - expect(extension('file.babel...js')).toEqual(['.babel...js', '...js', '..js', '.js']); - expect(extension('file...babel.js')).toEqual(['...babel.js', '..babel.js', '.babel.js', '.js']); + expect(extension('file.babel...js')).toEqual([ + '.babel...js', + '...js', + '..js', + '.js', + ]); + expect(extension('file...babel.js')).toEqual([ + '...babel.js', + '..babel.js', + '.babel.js', + '.js', + ]); done(); }); - it('does not consider a leading dot to be an extension', function(done) { + it('does not consider a leading dot to be an extension', function (done) { expect(extension('.config')).toEqual(undefined); done(); }); }); - describe('normalize', function() { - - it('should convert a string input into array/object format', function(done) { + describe('normalize', function () { + it('should convert a string input into array/object format', function (done) { expect(normalize('foo')).toEqual({ module: 'foo' }); done(); }); - it('should convert object input into array format', function(done) { + it('should convert object input into array format', function (done) { var input = { module: 'foo', }; @@ -99,93 +118,88 @@ describe('rechoir', function() { done(); }); - it('should iterate an array, normalizing each item', function(done) { - var input = [ - { module: 'foo' }, - 'bar', - ]; - expect(normalize(input)).toEqual([ - { module: 'foo' }, - { module: 'bar' }, - ]); + it('should iterate an array, normalizing each item', function (done) { + var input = [{ module: 'foo' }, 'bar']; + expect(normalize(input)).toEqual([{ module: 'foo' }, { module: 'bar' }]); done(); }); }); - describe('register', function() { - - it('should return the specified module relative to the provided cwd', function(done) { + describe('register', function () { + it('should return the specified module relative to the provided cwd', function (done) { expect(register(__dirname, 'expect')).toEqual(expect); done(); }); - it('should call a register function if provided, passing in the module', function(done) { - register(__dirname, 'expect', function(attempt) { + it('should call a register function if provided, passing in the module', function (done) { + register(__dirname, 'expect', function (attempt) { expect(attempt).toEqual(expect); }); done(); }); - it('should return an error if the specified module cannot be registered', function(done) { - expect(register(__dirname, 'whatev')).toBeAn(Error); + it('should return an error if the specified module cannot be registered', function (done) { + expect(register(__dirname, 'whatev')).toBeInstanceOf(Error); done(); }); }); - describe('prepare', function() { + describe('prepare', function () { var testFilePath = path.join(__dirname, 'fixtures', 'test.stub'); beforeEach(cleanup); - it('should throw if extension is unknown', function(done) { - expect(function() { + it('should throw if extension is unknown', function (done) { + expect(function () { rechoir.prepare({}, './test/fixtures/test.whatever'); }).toThrow(/No module loader found for/); done(); }); - it('should return undefined if an unknown extension is specified when nothrow is enabled', function(done) { - expect(rechoir.prepare({}, './test/fixtures/.testrc', null, true)).toEqual(undefined); + it('should return undefined if an unknown extension is specified when nothrow is enabled', function (done) { + expect( + rechoir.prepare({}, './test/fixtures/.testrc', null, true) + ).toEqual(undefined); done(); }); - it('should throw if a module loader cannot be found or loaded', function(done) { - expect(function() { - rechoir.prepare({ - '.stub': ['nothere'], - }, testFilePath); + it('should throw if a module loader cannot be found or loaded', function (done) { + expect(function () { + rechoir.prepare( + { + '.stub': ['nothere'], + }, + testFilePath + ); require(testFilePath); }).toThrow(); done(); }); - describe('all module loaders that were attempted failed to load', function() { + describe('all module loaders that were attempted failed to load', function () { var exts = { - '.stub': [ - 'nothere', - 'orhere', - ], + '.stub': ['nothere', 'orhere'], }; // Check the failure entries in the thrown or returned error object. function checkFailures(e) { - expect(e.failures).toBeAn('array'); - expect(e.failures[0].error).toBeAn(Error); + expect(e.failures).toBeInstanceOf(Array); + expect(e.failures[0].error).toBeInstanceOf(Error); expect(e.failures[0].moduleName).toEqual('nothere'); expect(e.failures[0].module).toEqual(null); - expect(e.failures[1].error).toBeAn(Error); + expect(e.failures[1].error).toBeInstanceOf(Error); expect(e.failures[1].moduleName).toEqual('orhere'); expect(e.failures[1].module).toEqual(null); } - it('should throw error listing each module loader that was attempted when nothrow = false', function(done) { + it('should throw error listing each module loader that was attempted when nothrow = false', function (done) { var err; try { rechoir.prepare(exts, testFilePath); @@ -193,53 +207,56 @@ describe('rechoir', function() { err = e; checkFailures(e); } - expect(err).toBeAn(Error); + expect(err).toBeInstanceOf(Error); done(); }); - it('should return error listing each module loader that was attempted when nothrow = true', function(done) { - checkFailures( - rechoir.prepare(exts, testFilePath, null, true) - ); + it('should return error listing each module loader that was attempted when nothrow = true', function (done) { + checkFailures(rechoir.prepare(exts, testFilePath, null, true)); done(); }); }); - it('should register a module loader for the specified extension', function(done) { - rechoir.prepare({ - '.stub': [ - 'nothere', - '../require-stub', - ], - }, testFilePath); - expect(function() { + it('should register a module loader for the specified extension', function (done) { + rechoir.prepare( + { + '.stub': ['nothere', '../require-stub'], + }, + testFilePath + ); + expect(function () { require(testFilePath); - }).toNotThrow(Error); + }).not.toThrow(Error); done(); }); - it('should return true if the module loader for the specified extension is already available', function(done) { - rechoir.prepare({ - '.stub': [ - 'nothere', - '../require-stub', - ], - }, testFilePath); - expect(rechoir.prepare({ - '.stub': [ - 'nothere', - '../require-stub', - ], - }, testFilePath)).toEqual(true); + it('should return true if the module loader for the specified extension is already available', function (done) { + rechoir.prepare( + { + '.stub': ['nothere', '../require-stub'], + }, + testFilePath + ); + expect( + rechoir.prepare( + { + '.stub': ['nothere', '../require-stub'], + }, + testFilePath + ) + ).toEqual(true); done(); }); - it('must not fail on folders with dots', function(done) { - rechoir.prepare({ '.stub': '../../require-stub' }, './test/fixtures/folder.with.dots/test.stub'); + it('must not fail on folders with dots', function (done) { + rechoir.prepare( + { '.stub': '../../require-stub' }, + './test/fixtures/folder.with.dots/test.stub' + ); expect(require('./fixtures/folder.with.dots/test.stub')).toEqual({ data: { trueKey: true, @@ -253,7 +270,7 @@ describe('rechoir', function() { done(); }); - it('should register a module loader even if the extension is single character (issue #38)', function(done) { + it('should register a module loader even if the extension is single character (issue #38)', function (done) { var fpath = path.join(__dirname, 'fixtures', 'test.s'); rechoir.prepare({ '.s': [ @@ -262,12 +279,26 @@ describe('rechoir', function() { ], }, fpath); - expect(function() { + expect(function () { require(fpath); - }).toNotThrow(Error); + }).not.toThrow(Error); done(); }); - }); + it('should register a module loader for the specified extension with cwd', function (done) { + rechoir.prepare( + { + '.foo': ['nothere', '../require-stub'], + }, + path.join('cwd', 'test.foo'), + path.join(__dirname, 'fixtures') + ); + expect(function () { + require(testFilePath); + }).not.toThrow(Error); + + done(); + }); + }); });