pax_global_header00006660000000000000000000000064125537257040014524gustar00rootroot0000000000000052 comment=1aafd85aac487171be71891b916c9136c620ac0e js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/000077500000000000000000000000001255372570400205625ustar00rootroot00000000000000js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/.gitignore000066400000000000000000000000251255372570400225470ustar00rootroot00000000000000node_modules egcache js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/.npmignore000066400000000000000000000000051255372570400225540ustar00rootroot00000000000000test js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/.travis.yml000066400000000000000000000013471255372570400227000ustar00rootroot00000000000000sudo: false language: node_js node_js: - "0.10" - "0.12" env: global: - REMOVE_DEPS="" matrix: - "CUSTOM_DEPS=coffee-script@~1.3" - "CUSTOM_DEPS=coffee-script@~1.5" - "CUSTOM_DEPS=coffee-script@~1.7" - "CUSTOM_DEPS=coffee-script@latest" - "CUSTOM_DEPS=iced-coffee-script@1.6.3-j" - "CUSTOM_DEPS=iced-coffee-script@latest" - "CUSTOM_DEPS=LiveScript@1.3.1 REMOVE_DEPS=livescript" - "CUSTOM_DEPS=typescript-require REMOVE_DEPS=typescript-register" matrix: fast_finish: true before_install: - "npm install -g npm" # needs the newest version of npm before_script: - "[ \"${REMOVE_DEPS}\" == \"\" ] || npm rm $REMOVE_DEPS" - "npm install $CUSTOM_DEPS" # install a specific version of dependencies js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/CHANGELOG000066400000000000000000000016001255372570400217710ustar00rootroot00000000000000v0.6.2: date: 2015-07-22 changes: - Return `undefined` when an unknown extension is provided to prepare and the `nothrow` option is specified. v0.6.1: date: 2015-05-22 changes: - Add option for not throwing. v0.6.0: date: 2015-05-20 changes: - Include module name when prepare is successful. v0.5.0: date: 2015-05-20 changes: - Overhaul to support interpret 0.6.0. v0.3.0: date: 2015-01-10 changes: - Breaking: `load` method removed. - Improved extension recognition. - No longer fails upon dots in filenames. - Support confuration objects. - Support and test ES6. - Support legacy module loading. v0.2.2: date: 2014-12-17 changes: - Expose interpret. v0.2.0: date: 2014-04-20 changes: - Simplify loading of coffee-script and iced-coffee-script. v0.1.0: date: 2014-04-20 changes: - Initial public release. js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/LICENSE000066400000000000000000000020401255372570400215630ustar00rootroot00000000000000Copyright (c) 2015 Tyler Kellen 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 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. js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/README.md000066400000000000000000000037421255372570400220470ustar00rootroot00000000000000# rechoir [![Build Status](https://secure.travis-ci.org/tkellen/js-rechoir.png)](http://travis-ci.org/tkellen/js-rechoir) > Require any supported file as a node module. [![NPM](https://nodei.co/npm/rechoir.png)](https://nodei.co/npm/rechoir/) ## What is it? This module, in conjunction with [interpret]-like objects can register any file type the npm ecosystem has a module loader for. This library is a dependency of [Liftoff]. ## API ### prepare(config, filepath, requireFrom) 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). `config` An [interpret]-like configuration object. `filepath` A file whose type you'd like to register a module loader for. `requireFrom` An optional path to start searching for the module required to load the requested file. Defaults to the directory of `filepath`. If calling this method is successful (aka: it doesn't throw), you can now require files of the type you requested natively. An error with a `failures` property will be thrown if the module loader(s) configured for a given extension cannot be registered. If a loader is already registered, this will simply return `true`. **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. #### Usage ```js const config = require('interpret').extensions; const rechoir = require('rechoir'); rechoir.prepare(config, './test/fixtures/test.coffee'); rechoir.prepare(config, './test/fixtures/test.csv'); rechoir.prepare(config, './test/fixtures/test.toml'); console.log(require('./test/fixtures/test.coffee')); console.log(require('./test/fixtures/test.csv')); console.log(require('./test/fixtures/test.toml')); ``` [interpret]: http://github.com/tkellen/js-interpret [Liftoff]: http://github.com/tkellen/js-liftoff js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/index.js000066400000000000000000000025461255372570400222360ustar00rootroot00000000000000const path = require('path'); const extension = require('./lib/extension'); const normalize = require('./lib/normalize'); const register = require('./lib/register'); exports.prepare = function (extensions, filepath, cwd, nothrow) { var option, attempt; var attempts = []; var err; var onlyErrors = false; var ext = extension(filepath); if (Object.keys(require.extensions).indexOf(ext) !== -1) { return true; } var config = normalize(extensions[ext]); if (!config) { if (nothrow) { return; } else { throw new Error('No module loader found for "'+ext+'".'); } } if (!cwd) { cwd = path.dirname(path.resolve(filepath)); } if (!Array.isArray(config)) { config = [config]; } for (var i in config) { option = config[i]; attempt = register(cwd, option.module, option.register); error = (attempt instanceof Error) ? attempt : null; if (error) { attempt = null; } attempts.push({ moduleName: option.module, module: attempt, error: error }); if (!error) { onlyErrors = false; break; } else { onlyErrors = true; } } if (onlyErrors) { err = new Error('Unable to use specified module loaders for "'+ext+'".'); err.failures = attempts; if (nothrow) { return err; } else { throw err; } } return attempts; }; js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/lib/000077500000000000000000000000001255372570400213305ustar00rootroot00000000000000js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/lib/extension.js000066400000000000000000000003321255372570400237000ustar00rootroot00000000000000const path = require('path'); const EXTRE = /^[.]?[^.]+([.].*)$/; module.exports = function (input) { var extension = EXTRE.exec(path.basename(input)); if (!extension) { return; } return extension[1]; }; js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/lib/normalize.js000066400000000000000000000004171255372570400236700ustar00rootroot00000000000000function normalizer (config) { if (typeof config === 'string') { return { module: config } } return config; }; module.exports = function (config) { if (Array.isArray(config)) { return config.map(normalizer); } return normalizer(config); }; js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/lib/register.js000066400000000000000000000005501255372570400235120ustar00rootroot00000000000000const path = require('path'); const resolve = require('resolve'); module.exports = function (cwd, moduleName, register) { try { var modulePath = resolve.sync(moduleName, {basedir: cwd}); var result = require(modulePath); if (typeof register === 'function') { register(result); } } catch (e) { result = e; } return result; }; js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/package.json000066400000000000000000000033361255372570400230550ustar00rootroot00000000000000{ "name": "rechoir", "description": "Require any supported file as a node module.", "version": "0.6.2", "homepage": "https://github.com/tkellen/node-rechoir", "author": { "name": "Tyler Kellen", "url": "http://goingslowly.com/" }, "repository": { "type": "git", "url": "git://github.com/tkellen/node-rechoir.git" }, "bugs": { "url": "https://github.com/tkellen/node-rechoir/issues" }, "licenses": [ { "type": "MIT", "url": "https://github.com/tkellen/node-rechoir/blob/master/LICENSE" } ], "main": "index.js", "engines": { "node": ">= 0.10" }, "scripts": { "test": "mocha -R spec test/index.js" }, "dependencies": { "resolve": "^1.1.6" }, "devDependencies": { "babel": "^5.4.3", "chai": "^2.3.0", "coco": "^0.9.1", "coffee-script": "^1.9.2", "earlgrey": "0.0.9", "iced-coffee-script": "^1.8.0-d", "interpret": "^0.6.1", "json5": "^0.4.0", "livescript": "^1.4.0", "mocha": "^2.2.5", "node-jsx": "^0.13.3", "require-csv": "0.0.1", "require-ini": "0.0.1", "require-uncached": "^1.0.2", "require-xml": "0.0.1", "require-yaml": "0.0.1", "rimraf": "^2.3.4", "semver": "^4.3.4", "sinon": "^1.14.1", "toml-require": "^1.0.1", "typescript-register": "^1.1.0" }, "keywords": [ "require", "cjsx", "co", "coco", "coffee-script", "coffee", "coffee.md", "csv", "earlgrey", "es", "es6", "iced", "iced.md", "iced-coffee-script", "ini", "js", "json", "json5", "jsx", "react", "litcoffee", "liticed", "ls", "livescript", "toml", "ts", "typescript", "xml", "yaml", "yml" ] } js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/000077500000000000000000000000001255372570400215415ustar00rootroot00000000000000js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/000077500000000000000000000000001255372570400234125ustar00rootroot00000000000000js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/.testrc000066400000000000000000000001611255372570400247150ustar00rootroot00000000000000module.exports = { data: { trueKey: true, falseKey: false, subKey: { subProp: 1 } } }; js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/folder.with.dots/000077500000000000000000000000001255372570400266075ustar00rootroot00000000000000js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/folder.with.dots/test.yaml000066400000000000000000000001011255372570400304420ustar00rootroot00000000000000data: trueKey: true falseKey: false subKey: subProp: 1 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.babel.js000066400000000000000000000003551255372570400257760ustar00rootroot00000000000000// Test ES6 arrow functions var fn = () => { var trueKey = true; var falseKey = false; var subKey = { subProp: 1 }; // Test harmony object short notation return { data: { trueKey, falseKey, subKey}}; }; module.exports = fn(); js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.co000066400000000000000000000001561255372570400247160ustar00rootroot00000000000000module.exports = { data: { trueKey: true falseKey: false subKey: { subProp: 1 } } } js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.coffee000066400000000000000000000001341255372570400255400ustar00rootroot00000000000000module.exports = data: trueKey: true falseKey: false subKey: subProp: 1 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.coffee.md000066400000000000000000000002201255372570400261330ustar00rootroot00000000000000Test Fixture ============ module.exports = data: trueKey: true falseKey: false subKey: subProp: 1 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.csv000066400000000000000000000000341255372570400251030ustar00rootroot00000000000000"r1c1","r1c2" "r2c1","r2c2" js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.eg000066400000000000000000000002001255372570400246760ustar00rootroot00000000000000module.exports = { data = { trueKey = true falseKey = false subKey = { subProp = 1 } } } js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.iced000066400000000000000000000001341255372570400252150ustar00rootroot00000000000000module.exports = data: trueKey: true falseKey: false subKey: subProp: 1 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.iced.md000066400000000000000000000002171255372570400256160ustar00rootroot00000000000000Test Fixture ============ module.exports = data: trueKey: true falseKey: false subKey: subProp: 1 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.ini000066400000000000000000000000531255372570400250700ustar00rootroot00000000000000[data] trueKey = true falseKey = false js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.js000066400000000000000000000001611255372570400247250ustar00rootroot00000000000000module.exports = { data: { trueKey: true, falseKey: false, subKey: { subProp: 1 } } }; js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.json000066400000000000000000000001511255372570400252610ustar00rootroot00000000000000{ "data": { "trueKey": true, "falseKey": false, "subKey": { "subProp": 1 } } } js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.json5000066400000000000000000000002121255372570400253440ustar00rootroot00000000000000{ "data": { "trueKey": true, "falseKey": false, "subKey": { "subProp": 1 } } /* omg, a comment in json?? */ } js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.jsx000066400000000000000000000005541255372570400251230ustar00rootroot00000000000000const React = { createElement: function(Component){ return Component(); } }; // Test harmony arrow functions const Component = () => { var trueKey = true; var falseKey = false; var subKey = { subProp: 1 }; // Test harmony object short notation return { data: { trueKey, falseKey, subKey}}; }; // Test JSX syntax module.exports = ; js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.litcoffee000066400000000000000000000001771255372570400262600ustar00rootroot00000000000000# comment module.exports = data: trueKey: true falseKey: false subKey: subProp: 1 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.liticed000066400000000000000000000001771255372570400257350ustar00rootroot00000000000000# comment module.exports = data: trueKey: true falseKey: false subKey: subProp: 1 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.ls000066400000000000000000000001341255372570400247270ustar00rootroot00000000000000module.exports = data: trueKey: true falseKey: false subKey: subProp: 1 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.toml000066400000000000000000000001061255372570400252630ustar00rootroot00000000000000[data] trueKey = true falseKey = false [data.subKey] subProp = 1 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.ts000066400000000000000000000001731255372570400247420ustar00rootroot00000000000000var test = { data: { trueKey: true, falseKey: false, subKey: { subProp: 1 } } }; export = test; js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.xml000066400000000000000000000001461255372570400251140ustar00rootroot00000000000000 true false js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/fixtures/test.yaml000066400000000000000000000001011255372570400252450ustar00rootroot00000000000000data: trueKey: true falseKey: false subKey: subProp: 1 js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/helpers.js000066400000000000000000000025751255372570400235520ustar00rootroot00000000000000const Module = require('module'); const semver = require('semver'); const requireUncached = require('require-uncached'); // save the original Module._extensions const originalExtensions = Object.keys(Module._extensions); const original = originalExtensions.reduce(function (result, key) { result[key] = require.extensions[key]; return result; }, {}); // save the original cache keys const originalCacheKeys = Object.keys(require.cache); // save the original Module.prototype.load because coffee-script overwrites it const originalModuleLoad = Module.prototype.load; function cleanupCache(key) { if (originalCacheKeys.indexOf(key) === -1) { delete require.cache[key]; } } function cleanupExtensions(ext) { if (originalExtensions.indexOf(ext) === -1) { delete Module._extensions[ext]; } else { Module._extensions[ext] = original[ext]; } } function cleanup() { // restore the require.cache to startup state Object.keys(require.cache).forEach(cleanupCache); // restore the original Module.prototype.load Module.prototype.load = originalModuleLoad; // restore the original Module._extensions Object.keys(Module._extensions).forEach(cleanupExtensions); } function skippable(module, minVersion, fn) { if (semver.gte(requireUncached(module).VERSION, minVersion)) { cleanup(); return fn; } } module.exports = { skippable: skippable, cleanup: cleanup }; js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/index.js000066400000000000000000000160721255372570400232140ustar00rootroot00000000000000const path = require('path'); const expect = require('chai').expect; const extensions = require('interpret').extensions; const rechoir = require('../'); const helpers = require('./helpers'); const cleanup = helpers.cleanup; const skippable = helpers.skippable; var expected = { data: { trueKey: true, falseKey: false, subKey: { subProp: 1 } } }; process.env.TYPESCRIPT_REGISTER_USE_CACHE = 'false'; describe('rechoir', function () { require('./lib/extension'); require('./lib/normalize'); require('./lib/register'); describe('prepare', function () { var testFilePath = path.join(__dirname, 'fixtures', 'test.coffee'); beforeEach(cleanup); it('should throw if extension is unknown', function () { expect(function () { rechoir.prepare(extensions, './test/fixtures/test.whatever'); }).to.throw(/No module loader found for/); }); it('should return undefined if an unknown extension is specified when nothrow is enabled', function () { expect(rechoir.prepare(extensions, './test/fixtures/.testrc', null, true)).to.be.undefined; }); it('should throw if a module loader cannot be found or loaded', function () { expect(function () { require(testFilePath); }).to.throw; }); it('should include errors for each module loader that was attempted if they failed to load', function () { try { rechoir.prepare({ '.coffee': [ 'nothere', 'orhere' ] }, testFilePath); } catch (e) { expect(e.failures).to.be.array; expect(e.failures[0].error).to.be.instanceof(Error); expect(e.failures[0].moduleName).to.equal('nothere'); expect(e.failures[0].module).to.be.null; expect(e.failures[1].error).to.be.instanceof(Error); expect(e.failures[1].moduleName).to.equal('orhere'); expect(e.failures[1].module).to.be.null; } }); it('should register a module loader for the specified extension', function () { const result = rechoir.prepare({ '.coffee': [ 'nothere', 'coffee-script/register', 'coffee-script' ] }, testFilePath); expect(function () { require(testFilePath); }).to.not.throw(Error); }); it('should return true if the module loader for the specified extension is already available', function () { rechoir.prepare({ '.coffee': [ 'nothere', 'coffee-script/register', 'coffee-script' ] }, testFilePath); expect(rechoir.prepare({ '.coffee': [ 'nothere', 'coffee-script/register', 'coffee-script' ] }, testFilePath)).to.be.true; }); it('should know babel.js', function () { rechoir.prepare(extensions, './test/fixtures/test.babel.js'); expect(require('./fixtures/test.babel.js')).to.deep.equal(expected); }); it('should know coco', function () { rechoir.prepare(extensions, './test/fixtures/test.co'); expect(require('./fixtures/test.co')).to.deep.equal(expected); }); it('should know coffee-script', function () { rechoir.prepare(extensions, './test/fixtures/test.coffee'); expect(require('./fixtures/test.coffee')).to.deep.equal(expected); }); it('should know csv', function () { rechoir.prepare(extensions, './test/fixtures/test.csv'); expect(require('./fixtures/test.csv')).to.deep.equal([['r1c1','r1c2'],['r2c1','r2c2']]); }); it('should know earl-grey', function () { rechoir.prepare(extensions, './test/fixtures/test.eg'); expect(require('./fixtures/test.eg')).to.deep.equal(expected); }); it('should know iced-coffee-script', function () { rechoir.prepare(extensions, './test/fixtures/test.iced'); expect(require('./fixtures/test.iced')).to.deep.equal(expected); }); it('should know ini', function () { rechoir.prepare(extensions, './test/fixtures/test.ini'); expect(require('./fixtures/test.ini')).to.deep.equal({ data: { trueKey: "true", falseKey: "false" } }); }); it('should know .js', function () { rechoir.prepare(extensions, './test/fixtures/test.js'); expect(require('./fixtures/test.js')).to.deep.equal(expected); }); it('should know .json', function () { rechoir.prepare(extensions, './test/fixtures/test.json'); expect(require('./fixtures/test.json')).to.deep.equal(expected); }); it('should know .json5', function () { rechoir.prepare(extensions, './test/fixtures/test.json5'); expect(require('./fixtures/test.json5')).to.deep.equal(expected); }); it('should know jsx', function () { rechoir.prepare(extensions, './test/fixtures/test.jsx'); expect(require('./fixtures/test.jsx')).to.deep.equal(expected); }); it('should know livescript', function () { rechoir.prepare(extensions, './test/fixtures/test.ls'); expect(require('./fixtures/test.ls')).to.deep.equal(expected); }); it('should know literate coffee-script', skippable('coffee-script', '1.5.0', function () { rechoir.prepare(extensions, './test/fixtures/test.litcoffee'); expect(require('./fixtures/test.litcoffee')).to.deep.equal(expected); })); it('should know literate coffee-script (.md)', skippable('coffee-script', '1.6.3', function () { rechoir.prepare(extensions, './test/fixtures/test.coffee.md'); expect(require('./fixtures/test.coffee.md')).to.deep.equal(expected); })); it('should know literate iced-coffee-script', skippable('iced-coffee-script', '1.7.1', function () { rechoir.prepare(extensions, './test/fixtures/test.liticed'); expect(require('./fixtures/test.liticed')).to.deep.equal(expected); })); it('should know literate iced-coffee-script (.md)', skippable('iced-coffee-script', '1.7.1', function () { rechoir.prepare(extensions, './test/fixtures/test.iced.md'); expect(require('./fixtures/test.iced.md')).to.deep.equal(expected); })); it('should know ts', function () { this.timeout(5000); rechoir.prepare(extensions, './test/fixtures/test.ts'); expect(require('./fixtures/test.ts')).to.deep.equal(expected); }); it('should know toml', function () { rechoir.prepare(extensions, './test/fixtures/test.toml'); expect(require('./fixtures/test.toml')).to.deep.equal(expected); }); it('should know xml', function () { rechoir.prepare(extensions, './test/fixtures/test.xml'); expect(JSON.parse(require('./fixtures/test.xml'))).to.deep.equal(expected); }); it('should know yaml', function () { rechoir.prepare(extensions, './test/fixtures/test.yaml'); expect(require('./fixtures/test.yaml')).to.deep.equal(expected); }); it('must not fail on folders with dots', function () { delete require.cache[require.resolve('require-yaml')]; rechoir.prepare(extensions, './test/fixtures/folder.with.dots/test.yaml'); expect(require('./fixtures/folder.with.dots/test.yaml')).to.deep.equal(expected); }); }); }); js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/lib/000077500000000000000000000000001255372570400223075ustar00rootroot00000000000000js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/lib/extension.js000066400000000000000000000007341255372570400246650ustar00rootroot00000000000000const expect = require('chai').expect; const extension = require('../../lib/extension'); describe('extension', function () { it('should extract extension from filename/path from the first dot', function () { expect(extension('file.js')).to.equal('.js'); expect(extension('file.dot.js')).to.equal('.dot.js'); expect(extension('relative/path/to/file.js')).to.equal('.js'); expect(extension('relative/path/to/file.dot.js')).to.equal('.dot.js'); }); }); js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/lib/normalize.js000066400000000000000000000013011255372570400246400ustar00rootroot00000000000000const chai = require('chai'); const expect = chai.expect; const normalize = require('../../lib/normalize'); describe('normalize', function () { it('should convert a string input into array/object format', function () { expect(normalize('foo')).to.deep.equal({module:'foo'}); }); it('should convert object input into array format', function () { const input = { module: 'foo' }; expect(normalize(input)).to.equal(input); }); it('should iterate an array, normalizing each item', function () { const input = [ { module: 'foo' }, 'bar' ]; expect(normalize(input)).to.deep.equal([ { module: 'foo' }, { module: 'bar' } ]); }); }); js-rechoir-1aafd85aac487171be71891b916c9136c620ac0e/test/lib/register.js000066400000000000000000000012231255372570400244670ustar00rootroot00000000000000const chai = require('chai'); const expect = chai.expect; const register = require('../../lib/register'); describe('register', function () { it('should return the specified module relative to the provided cwd', function () { expect(register(__dirname, 'chai')).to.equal(chai); }); it('should call a register function if provided, passing in the module', function () { register(__dirname, 'chai', function (attempt) { expect(attempt).to.equal(chai); }); }); it('should return an error if the specified module cannot be registered', function () { expect(register(__dirname, 'whatev')).to.be.an.instanceof(Error); }); });