diff --git a/.eslintrc.json b/.eslintrc.json index c9807b8..5d5f81b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,5 +1,5 @@ { - "extends": "skelp/v3/es6", + "extends": "notninja/es6", "env": { "node": true }, diff --git a/.travis.yml b/.travis.yml index 41f2138..35862fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,14 @@ +sudo: false language: node_js node_js: - "6" - "7" script: - - npm test + - npm run ci after_script: - - npm run coveralls + - npm run report-coverage +notifications: + slack: + rooms: + - secure: hiJNVw5FKod3veWv+h5PQby2G1n/xmFJZQlkr0YH3ISzLVIxYnOPzWlwfnK6F6BI4t8Dd76Q/n/dvxJdLI8O8B6neuE667MdVShctgcYUxtnR7ZYjJz4SKokmmGRS0Fl864Sxp/jBkNYezWljaDu35mnxIwY8ApKhmPboDxfHYHZ0hdYqNleRFN9rPNaisijpP48iAFcg+nksMkrdOB8Ritj29raPRTpmFVcwYJaEX/lpv8IhVErVHqe+RQrRIo2eWC6DxZKqTxksjZFNjcaDmRoIoXUG9sfCR7p+fMSVOXPnYqbQWO5QxOWTuoCrxsHHzkWzKbFOSTtsfq7+BVtIWR7PhoR8GJrl9a7P9+SoO/jf2rfPi4MiXXIoBqiNoGvH5IDrgvTX7ZkUecBxQAvUxmZIK8z+l/RX4oahTHuESZkAQ8CzhLlbLk1vAuojvq2Hm7Mz7wmSbQeV8qPrfQ575sssyRRndWwyrDVdhFdwyHRedLgFz4JsdFMWWVCkU3z6RyJ5nNv9Kd3MHhihHjBUsIDqk6z3ImbrLJSjEuKSzVOAcNDzrwwr6ed3OHPCNDAPuypULOATzDUH1gL5xmGFHRX3tRAQ4nRTERahojveMmFPtce32SaEXJb8Vt7pXyWoSaDH1XmYewmFd+Lhl+5z7btwY44yPIDuDcGbQqf/aQ= + on_success: change diff --git a/AUTHORS.md b/AUTHORS.md index 62f2a88..3849918 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -1,3 +1,3 @@ # Authors ordered by first contribution -* Alasdair Mercer +* Alasdair Mercer diff --git a/CHANGES.md b/CHANGES.md index 762f241..d9fb257 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,8 +1,13 @@ +## Version 0.3.0, 2017.05.16 + +* Move to !ninja [#9](https://github.com/NotNinja/routerify/issues/9) +* Switch to Codecov for code coverage [#10](https://github.com/NotNinja/routerify/issues/10) + ## Version 0.2.0, 2016.12.18 -* Add unit tests [#3](https://github.com/Skelp/routerify/issues/3) -* Simplify configuration of mounters and registrars [#4](https://github.com/Skelp/routerify/issues/4), [#6](https://github.com/Skelp/routerify/issues/6) -* Change default value for `registrar` option to `"index"` [#7](https://github.com/Skelp/routerify/issues/7) +* Add unit tests [#3](https://github.com/NotNinja/routerify/issues/3) +* Simplify configuration of mounters and registrars [#4](https://github.com/NotNinja/routerify/issues/4), [#6](https://github.com/NotNinja/routerify/issues/6) +* Change default value for `registrar` option to `"index"` [#7](https://github.com/NotNinja/routerify/issues/7) ## Version 0.1.0, 2016.12.15 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1550e55..26ec0ed 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,9 +1,9 @@ # Contributing -If you have any questions about [Routerify](https://github.com/Skelp/routerify) please feel free to -[raise an issue](https://github.com/Skelp/routerify/issues/new). +If you have any questions about [Routerify](https://github.com/NotNinja/routerify) please feel free to +[raise an issue](https://github.com/NotNinja/routerify/issues/new). -Please [search existing issues](https://github.com/Skelp/routerify/issues) for the same feature and/or issue before +Please [search existing issues](https://github.com/NotNinja/routerify/issues) for the same feature and/or issue before raising a new issue. Commenting on an existing issue is usually preferred over raising duplicate issues. Please ensure that all files conform to the coding standards, using the same coding style as the rest of the code base. @@ -21,5 +21,5 @@ You must have at least [Node.js](https://nodejs.org) 6 or newer. All pull requests should be made to the `develop` branch. Don't forget to add your details to the list of -[AUTHORS.md](https://github.com/Skelp/routerify/blob/master/AUTHORS.md) if you want your contribution to be recognized -by others. +[AUTHORS.md](https://github.com/NotNinja/routerify/blob/master/AUTHORS.md) if you want your contribution to be +recognized by others. diff --git a/LICENSE.md b/LICENSE.md index 03779e7..6cc536a 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (C) 2016 Alasdair Mercer, Skelp +Copyright (C) 2017 Alasdair Mercer, !ninja 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 ff27b56..2fb48f1 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,13 @@ Y8b d88P "Y88P" -[Routerify](https://github.com/Skelp/routerify) is an opinionated router loader for Express-like applications. +[Routerify](https://github.com/NotNinja/routerify) is an opinionated router loader for Express-like applications. -[![Build](https://img.shields.io/travis/Skelp/routerify/develop.svg?style=flat-square)](https://travis-ci.org/Skelp/routerify) -[![Coverage](https://img.shields.io/coveralls/Skelp/routerify/develop.svg?style=flat-square)](https://coveralls.io/github/Skelp/routerify) -[![Dependencies](https://img.shields.io/david/Skelp/routerify.svg?style=flat-square)](https://david-dm.org/Skelp/routerify) -[![Dev Dependencies](https://img.shields.io/david/dev/Skelp/routerify.svg?style=flat-square)](https://david-dm.org/Skelp/routerify#info=devDependencies) -[![License](https://img.shields.io/npm/l/routerify.svg?style=flat-square)](https://github.com/Skelp/routerify/blob/master/LICENSE.md) +[![Build](https://img.shields.io/travis/NotNinja/routerify/develop.svg?style=flat-square)](https://travis-ci.org/NotNinja/routerify) +[![Coverage](https://img.shields.io/codecov/c/github/NotNinja/routerify/develop.svg?style=flat-square)](https://codecov.io/gh/NotNinja/routerify) +[![Dependencies](https://img.shields.io/david/NotNinja/routerify.svg?style=flat-square)](https://david-dm.org/NotNinja/routerify) +[![Dev Dependencies](https://img.shields.io/david/dev/NotNinja/routerify.svg?style=flat-square)](https://david-dm.org/NotNinja/routerify?type=dev) +[![License](https://img.shields.io/npm/l/routerify.svg?style=flat-square)](https://github.com/NotNinja/routerify/blob/master/LICENSE.md) [![Release](https://img.shields.io/npm/v/routerify.svg?style=flat-square)](https://www.npmjs.com/package/routerify) * [Install](#install) @@ -39,7 +39,7 @@ You'll need to have at least [Node.js](https://nodejs.org) 6 or newer. Routerify is opinionated. Routerify is also configurable and extensible via plugins. The two core plugin types that Routerify has are *Registrars* and *Mounters*. Through these, Routerify can be configured to load routes from modules in any pattern and mount them onto any server. - + ### Registrars Registrars are responsible for picking which source files within the directory should be loaded as modules and how the @@ -47,7 +47,7 @@ routes are extracted from the modules. These routes are then passed to the mount Routerify includes some opinionated registrars. If you don't like our opinion, you can either not use Routerify **or** you can simply [create your own](#create-your-own-registrar) and, optionally, -[create a pull request](https://github.com/Skelp/routerify/compare) to share it with everyone, provided our opinions +[create a pull request](https://github.com/NotNinja/routerify/compare) to share it with everyone, provided our opinions match :) If not, you can always release it as a plugin. #### `IndexRegistrar` @@ -126,7 +126,7 @@ It expects the following file structure under the target directory: Only files whose base name matches that of a supported verb will be loaded (e.g. `helper.js` in the above example would be ignored) and it expects each one of those modules to export either a single handler method or an array of handler -methods. +methods. In the example above, the following routes would be registered: @@ -150,7 +150,7 @@ class CustomRegistrar extends Registrar { getPluginName() { return 'custom' } - + register(file, options) { // Load the module, extract the routes, and mount them via this.mounter ... @@ -173,7 +173,8 @@ routerify({ ``` You probably want to take a look at the relevant -[source code](https://github.com/Skelp/routerify/tree/master/src/registrar) before trying to create your own registrar. +[source code](https://github.com/NotNinja/routerify/tree/master/src/registrar) before trying to create your own +registrar. ### Mounters @@ -183,7 +184,7 @@ option is specified, and they determine how parameter path variables are formatt Routerify includes some mounters for common server frameworks. If your favorite framework is not supported, you can [create your own](#create-your-own-mounter) and, optionally, -[create a pull request](https://github.com/Skelp/routerify/compare) to share it with everyone. +[create a pull request](https://github.com/NotNinja/routerify/compare) to share it with everyone. #### `ExpressMounter` @@ -205,7 +206,7 @@ benefits for Restify applications by allowing extra optional information (e.g. ` mounting routes. This can be done by simply adding an `options` property containing the additional information to one of the route -handlers and it will be passed in. +handlers and it will be passed in. #### Create your own Mounter @@ -216,7 +217,7 @@ const routerify = require('routerify') const Mounter = require('routerify/src/mounter') class CustomMounter extends Mounter { - + formatParamPath(param) { // Format param for insertion into the route URL return ... @@ -253,7 +254,7 @@ routerify({ ``` You probably want to take a look at the relevant -[source code](https://github.com/Skelp/routerify/tree/master/src/mounter) before trying to create your own mounter. +[source code](https://github.com/NotNinja/routerify/tree/master/src/mounter) before trying to create your own mounter. ## API @@ -332,26 +333,25 @@ The current version of Routerify. ``` javascript routerify.version -=> "0.2.0" +=> "0.3.0" ``` ## Bugs If you have any problems with Routerify or would like to see changes currently in development you can do so -[here](https://github.com/Skelp/routerify/issues). +[here](https://github.com/NotNinja/routerify/issues). ## Contributors If you want to contribute, you're a legend! Information on how you can do so can be found in -[CONTRIBUTING.md](https://github.com/Skelp/routerify/blob/master/CONTRIBUTING.md). We want your suggestions and pull +[CONTRIBUTING.md](https://github.com/NotNinja/routerify/blob/master/CONTRIBUTING.md). We want your suggestions and pull requests! A list of Routerify contributors can be found in -[AUTHORS.md](https://github.com/Skelp/routerify/blob/master/AUTHORS.md). +[AUTHORS.md](https://github.com/NotNinja/routerify/blob/master/AUTHORS.md). ## License -See [LICENSE.md](https://github.com/Skelp/routerify/raw/master/LICENSE.md) for more information on our MIT license. +See [LICENSE.md](https://github.com/NotNinja/routerify/raw/master/LICENSE.md) for more information on our MIT license. -© 2016 [Skelp](https://skelp.io) - +[![Copyright !ninja](https://cdn.rawgit.com/NotNinja/branding/master/assets/copyright/base/not-ninja-copyright-186x25.png)](https://not.ninja) diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..db24720 --- /dev/null +++ b/codecov.yml @@ -0,0 +1 @@ +comment: off diff --git a/package.json b/package.json index 62bdc48..89bf63d 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,15 @@ { "name": "routerify", - "version": "0.2.0", + "version": "0.3.0", "description": "Opinionated router loader for Express-like applications", - "homepage": "https://github.com/Skelp/routerify", + "homepage": "https://github.com/NotNinja/routerify", "bugs": { - "url": "https://github.com/Skelp/routerify/issues" + "url": "https://github.com/NotNinja/routerify/issues" }, "author": { "name": "Alasdair Mercer", - "email": "alasdair@skelp.io", - "url": "https://skelp.io" + "email": "mercer.alasdair@gmail.com", + "url": "https://not.ninja" }, "license": "MIT", "keywords": [ @@ -19,7 +19,7 @@ ], "repository": { "type": "git", - "url": "https://github.com/Skelp/routerify.git" + "url": "https://github.com/NotNinja/routerify.git" }, "dependencies": { "glob": "^7.1.1", @@ -27,20 +27,20 @@ }, "devDependencies": { "chai": "^3.5.0", - "coveralls": "^2.11.15", - "eslint": "^3.12.1", - "eslint-config-skelp": "^0.1.5", + "codecov": "^2.2.0", + "eslint": "^3.19.0", + "eslint-config-notninja": "^0.1.1", "istanbul": "^0.4.5", - "mocha": "^3.2.0", - "sinon": "^1.17.6" + "mocha": "^3.4.1", + "sinon": "^2.2.0" }, "main": "src/routerify.js", "scripts": { - "coveralls": "istanbul cover _mocha --report lcovonly -- -R spec \"test/**/*.spec.js\" && coveralls < coverage/lcov.info", - "test": "npm run test-lint && npm run test-suite && npm run test-coverage", - "test-coverage": "istanbul check-coverage", - "test-lint": "eslint \"src/**/*.js\" \"test/**/*.js\"", - "test-suite": "istanbul cover _mocha -- -R spec \"test/**/*.spec.js\"" + "ci": "npm run test", + "report-coverage": "istanbul cover _mocha --report lcovonly -- -R spec \"test/**/*.spec.js\" && codecov", + "pretest": "eslint \"src/**/*.js\" \"test/**/*.js\"", + "test": "istanbul cover _mocha -- -R list \"test/**/*.spec.js\"", + "posttest": "istanbul check-coverage" }, "engines": { "node": ">=6" diff --git a/src/mounter/express-mounter.js b/src/mounter/express-mounter.js index a7fed9d..1b5b528 100644 --- a/src/mounter/express-mounter.js +++ b/src/mounter/express-mounter.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,9 +20,9 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const Mounter = require('./index') +const Mounter = require('./index'); /** * An implementation of {@link Mounter} that is intended to be used for Express applications. @@ -37,7 +37,7 @@ class ExpressMounter extends Mounter { * @inheritDoc */ formatParamPath(param) { - return `:${param}` + return `:${param}`; } /** @@ -45,7 +45,7 @@ class ExpressMounter extends Mounter { * @inheritDoc */ getDefaultVerbs() { - return [ 'del', 'get', 'head', 'opts', 'patch', 'post', 'put' ] + return [ 'del', 'get', 'head', 'opts', 'patch', 'post', 'put' ]; } /** @@ -53,7 +53,7 @@ class ExpressMounter extends Mounter { * @inheritDoc */ getPluginName() { - return 'express' + return 'express'; } /** @@ -61,11 +61,11 @@ class ExpressMounter extends Mounter { * @inheritDoc */ mount(url, verb, handlers, options) { - handlers = Array.isArray(handlers) ? handlers : [ handlers ] + handlers = Array.isArray(handlers) ? handlers : [ handlers ]; - options.server[verb](url, ...handlers) + options.server[verb](url, ...handlers); } } -module.exports = ExpressMounter +module.exports = ExpressMounter; diff --git a/src/mounter/index.js b/src/mounter/index.js index 936bf68..9840be0 100644 --- a/src/mounter/index.js +++ b/src/mounter/index.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,10 +20,10 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const Plugin = require('../plugin') -const Utilities = require('../utilities') +const Plugin = require('../plugin'); +const Utilities = require('../utilities'); /** * Responsible for mounting a route, whose information is provided by a {@link Registrar}, onto the server. @@ -42,7 +42,7 @@ class Mounter extends Plugin { * @abstract */ formatParamPath(param) { - Utilities.abstracted(Mounter, 'formatParamPath') + Utilities.abstracted(Mounter, 'formatParamPath'); } /** @@ -53,7 +53,7 @@ class Mounter extends Plugin { * @abstract */ getDefaultVerbs() { - Utilities.abstracted(Mounter, 'getDefaultVerbs') + Utilities.abstracted(Mounter, 'getDefaultVerbs'); } /** @@ -68,9 +68,9 @@ class Mounter extends Plugin { * @abstract */ mount(url, verb, handlers, options) { - Utilities.abstracted(Mounter, 'mount') + Utilities.abstracted(Mounter, 'mount'); } } -module.exports = Mounter +module.exports = Mounter; diff --git a/src/mounter/restify-mounter.js b/src/mounter/restify-mounter.js index 9ecad8a..36bbdaa 100644 --- a/src/mounter/restify-mounter.js +++ b/src/mounter/restify-mounter.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,9 +20,9 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const ExpressMounter = require('./express-mounter') +const ExpressMounter = require('./express-mounter'); /** * An extension of {@link ExpressMounter} which provides further compatibility with Restify by reading @@ -42,7 +42,7 @@ class RestifyMounter extends ExpressMounter { * @inheritDoc */ getPluginName() { - return 'restify' + return 'restify'; } /** @@ -50,19 +50,19 @@ class RestifyMounter extends ExpressMounter { * @inheritDoc */ mount(url, verb, handlers, options) { - handlers = Array.isArray(handlers) ? handlers : [ handlers ] + handlers = Array.isArray(handlers) ? handlers : [ handlers ]; - const handlerWithOptions = handlers.find((handler) => handler.options != null) + const handlerWithOptions = handlers.find((handler) => handler.options != null); if (handlerWithOptions) { url = Object.assign({}, handlerWithOptions.options, { method: verb, path: url - }) + }); } - super.mount(url, verb, handlers, options) + super.mount(url, verb, handlers, options); } } -module.exports = RestifyMounter +module.exports = RestifyMounter; diff --git a/src/plugin.js b/src/plugin.js index 9d73dee..b3c9d52 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,9 +20,9 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const Utilities = require('./utilities') +const Utilities = require('./utilities'); /** * A plugin can be registered to be used and then looked up later based on the plugin name. @@ -41,9 +41,9 @@ class Plugin { * @abstract */ getPluginName() { - Utilities.abstracted(Plugin, 'getPluginName') + Utilities.abstracted(Plugin, 'getPluginName'); } } -module.exports = Plugin +module.exports = Plugin; diff --git a/src/registrar/index-registrar.js b/src/registrar/index-registrar.js index 13bd021..570d783 100644 --- a/src/registrar/index-registrar.js +++ b/src/registrar/index-registrar.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,11 +20,11 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const path = require('path') +const path = require('path'); -const Registrar = require('./index') +const Registrar = require('./index'); /** * An implementation of {@link Registrar} where the index files in each directory is loaded as a module and the result @@ -41,7 +41,7 @@ class IndexRegistrar extends Registrar { * @override */ getPluginName() { - return 'index' + return 'index'; } /** @@ -49,21 +49,21 @@ class IndexRegistrar extends Registrar { * @override */ register(file, options) { - const name = path.basename(file, options.ext) + const name = path.basename(file, options.ext); if (name !== 'index') { - return + return; } - const router = this.loadRouter(file, options) - const url = this.buildUrl(file, options) + const router = this.loadRouter(file, options); + const url = this.buildUrl(file, options); Object.keys(router) .filter(options.verbs.includes.bind(options.verbs)) .forEach((verb) => { - options.mounter.mount(url, verb, router[verb], options) - }) + options.mounter.mount(url, verb, router[verb], options); + }); } } -module.exports = IndexRegistrar +module.exports = IndexRegistrar; diff --git a/src/registrar/index.js b/src/registrar/index.js index 186fb0c..2f854e8 100644 --- a/src/registrar/index.js +++ b/src/registrar/index.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,12 +20,12 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const path = require('path') +const path = require('path'); -const Plugin = require('../plugin') -const Utilities = require('../utilities') +const Plugin = require('../plugin'); +const Utilities = require('../utilities'); /** * Responsible for loading routes from a specific structure of modules and mounting them onto the server using a @@ -54,13 +54,13 @@ class Registrar extends Plugin { return file.split(path.sep) .slice(0, -1) .reduce((memo, segment) => { - const match = segment.match(options.paramPattern) + const match = segment.match(options.paramPattern); if (match) { - segment = options.mounter.formatParamPath(match[1]) + segment = options.mounter.formatParamPath(match[1]); } - return `${memo}/${segment}` - }, '') + return `${memo}/${segment}`; + }, ''); } /** @@ -72,7 +72,7 @@ class Registrar extends Plugin { * @protected */ loadRouter(file, options) { - return require(path.resolve(options.dir, file)) + return require(path.resolve(options.dir, file)); } /** @@ -85,9 +85,9 @@ class Registrar extends Plugin { * @abstract */ register(file, options) { - Utilities.abstracted(Registrar, 'register') + Utilities.abstracted(Registrar, 'register'); } } -module.exports = Registrar +module.exports = Registrar; diff --git a/src/registrar/verb-registrar.js b/src/registrar/verb-registrar.js index 80dc305..fa5c3e0 100644 --- a/src/registrar/verb-registrar.js +++ b/src/registrar/verb-registrar.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,11 +20,11 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const path = require('path') +const path = require('path'); -const Registrar = require('./index') +const Registrar = require('./index'); /** * An implementation of {@link Registrar} where the name of the files in each directory is checked and, if it's a @@ -41,7 +41,7 @@ class VerbRegistrar extends Registrar { * @override */ getPluginName() { - return 'verb' + return 'verb'; } /** @@ -49,17 +49,17 @@ class VerbRegistrar extends Registrar { * @override */ register(file, options) { - const name = path.basename(file, options.ext) + const name = path.basename(file, options.ext); if (!options.verbs.includes(name)) { - return + return; } - const handlers = this.loadRouter(file, options) - const url = this.buildUrl(file, options) + const handlers = this.loadRouter(file, options); + const url = this.buildUrl(file, options); - options.mounter.mount(url, name, handlers, options) + options.mounter.mount(url, name, handlers, options); } } -module.exports = VerbRegistrar +module.exports = VerbRegistrar; diff --git a/src/routerify.js b/src/routerify.js index 502fac6..2e49a86 100644 --- a/src/routerify.js +++ b/src/routerify.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,18 +20,18 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const defaultsDeep = require('lodash.defaultsdeep') -const glob = require('glob') +const defaultsDeep = require('lodash.defaultsdeep'); +const glob = require('glob'); -const ExpressMounter = require('./mounter/express-mounter') -const IndexRegistrar = require('./registrar/index-registrar') -const Mounter = require('./mounter') -const { version } = require('../package.json') -const Registrar = require('./registrar') -const RestifyMounter = require('./mounter/restify-mounter') -const VerbRegistrar = require('./registrar/verb-registrar') +const ExpressMounter = require('./mounter/express-mounter'); +const IndexRegistrar = require('./registrar/index-registrar'); +const Mounter = require('./mounter'); +const { version } = require('../package.json'); +const Registrar = require('./registrar'); +const RestifyMounter = require('./mounter/restify-mounter'); +const VerbRegistrar = require('./registrar/verb-registrar'); /** * A set containing all registered {@link Plugin} instances. @@ -39,7 +39,7 @@ const VerbRegistrar = require('./registrar/verb-registrar') * @private * @type {Set.} */ -const plugins = new Set() +const plugins = new Set(); /** * Mounts routes onto a given server by loading modules within a specific directory. @@ -61,19 +61,19 @@ function routerify(options) { registrar: 'index', server: null, verbs: null - }) + }); - const mounter = options.mounter = routerify.lookup(Mounter, options.mounter) - const registrar = options.registrar = routerify.lookup(Registrar, options.registrar) + const mounter = options.mounter = routerify.lookup(Mounter, options.mounter); + const registrar = options.registrar = routerify.lookup(Registrar, options.registrar); if (!options.verbs) { - options.verbs = mounter.getDefaultVerbs() + options.verbs = mounter.getDefaultVerbs(); } - const globOptions = Object.assign({ cwd: options.dir }, options.glob) - const files = glob.sync(`**/*${options.ext}`, globOptions) + const globOptions = Object.assign({ cwd: options.dir }, options.glob); + const files = glob.sync(`**/*${options.ext}`, globOptions); - files.forEach((file) => registrar.register(file, options)) + files.forEach((file) => registrar.register(file, options)); } Object.assign(routerify, { @@ -97,16 +97,16 @@ Object.assign(routerify, { lookup(type, name) { if (typeof name === 'undefined') { return Array.from(plugins) - .filter((plugin) => plugin instanceof type) + .filter((plugin) => plugin instanceof type); } const match = Array.from(plugins) - .find((plugin) => plugin instanceof type && plugin.getPluginName() === name) + .find((plugin) => plugin instanceof type && plugin.getPluginName() === name); if (match == null) { - throw new Error(`Unable to lookup ${type.name}: ${name}`) + throw new Error(`Unable to lookup ${type.name}: ${name}`); } - return match + return match; }, /** @@ -121,10 +121,10 @@ Object.assign(routerify, { */ use(plugin) { if (plugin) { - plugins.add(plugin) + plugins.add(plugin); } - return plugin + return plugin; }, /** @@ -136,14 +136,14 @@ Object.assign(routerify, { */ version -}) +}); -routerify.use(new ExpressMounter()) -routerify.use(new RestifyMounter()) -routerify.use(new IndexRegistrar()) -routerify.use(new VerbRegistrar()) +routerify.use(new ExpressMounter()); +routerify.use(new RestifyMounter()); +routerify.use(new IndexRegistrar()); +routerify.use(new VerbRegistrar()); -module.exports = routerify +module.exports = routerify; /** * The options that can be passed to routerify. diff --git a/src/utilities.js b/src/utilities.js index 3cfb4f1..2e0a899 100644 --- a/src/utilities.js +++ b/src/utilities.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ * SOFTWARE. */ -'use strict' +'use strict'; /** * Contains utility methods. @@ -41,9 +41,9 @@ class Utilities { * @static */ static abstracted(type, methodName) { - throw new Error(`${type.name}#${methodName} has not been implemented`) + throw new Error(`${type.name}#${methodName} has not been implemented`); } } -module.exports = Utilities +module.exports = Utilities; diff --git a/test/fixtures/registrar/index/ignore.js b/test/fixtures/registrar/index/ignore.js index 09f57a9..283bede 100644 --- a/test/fixtures/registrar/index/ignore.js +++ b/test/fixtures/registrar/index/ignore.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ * SOFTWARE. */ -'use strict' +'use strict'; function ignorePost(req, res, next) {} -module.exports = { post: ignorePost } +module.exports = { post: ignorePost }; diff --git a/test/fixtures/registrar/index/index.js b/test/fixtures/registrar/index/index.js index 60ea5bc..c04f5cb 100644 --- a/test/fixtures/registrar/index/index.js +++ b/test/fixtures/registrar/index/index.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ * SOFTWARE. */ -'use strict' +'use strict'; function rootGet(req, res, next) {} function rootHead1(req, res, next) {} @@ -31,4 +31,4 @@ module.exports = { get: rootGet, head: [ rootHead1, rootHead2 ] -} +}; diff --git a/test/fixtures/registrar/index/level1/_id/index.js b/test/fixtures/registrar/index/level1/_id/index.js index 29796e1..3973da0 100644 --- a/test/fixtures/registrar/index/level1/_id/index.js +++ b/test/fixtures/registrar/index/level1/_id/index.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ * SOFTWARE. */ -'use strict' +'use strict'; function level1IdDel(req, res, next) {} function level1IdGet(req, res, next) {} @@ -32,4 +32,4 @@ module.exports = { get: level1IdGet, post: level1IdPost -} +}; diff --git a/test/fixtures/registrar/index/level1/_id/level2/index.js b/test/fixtures/registrar/index/level1/_id/level2/index.js index 26fbac2..ce20d87 100644 --- a/test/fixtures/registrar/index/level1/_id/level2/index.js +++ b/test/fixtures/registrar/index/level1/_id/level2/index.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ * SOFTWARE. */ -'use strict' +'use strict'; function level1IdLevel2Get(req, res, next) {} -module.exports = { get: level1IdLevel2Get } +module.exports = { get: level1IdLevel2Get }; diff --git a/test/fixtures/registrar/index/level1/index.js b/test/fixtures/registrar/index/level1/index.js index 9067f9e..4c3625c 100644 --- a/test/fixtures/registrar/index/level1/index.js +++ b/test/fixtures/registrar/index/level1/index.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,7 +20,7 @@ * SOFTWARE. */ -'use strict' +'use strict'; function level1Get(req, res, next) {} function level1Post(req, res, next) {} @@ -30,4 +30,4 @@ module.exports = { get: level1Get, post: level1Post -} +}; diff --git a/test/fixtures/registrar/verb/get.js b/test/fixtures/registrar/verb/get.js index 6c293fe..4a65038 100644 --- a/test/fixtures/registrar/verb/get.js +++ b/test/fixtures/registrar/verb/get.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ * SOFTWARE. */ -'use strict' +'use strict'; function rootGet(req, res, next) {} -module.exports = rootGet +module.exports = rootGet; diff --git a/test/fixtures/registrar/verb/head.js b/test/fixtures/registrar/verb/head.js index 25c8c6c..8e39091 100644 --- a/test/fixtures/registrar/verb/head.js +++ b/test/fixtures/registrar/verb/head.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,9 +20,9 @@ * SOFTWARE. */ -'use strict' +'use strict'; function rootHead1(req, res, next) {} function rootHead2(req, res, next) {} -module.exports = [ rootHead1, rootHead2 ] +module.exports = [ rootHead1, rootHead2 ]; diff --git a/test/fixtures/registrar/verb/ignore.js b/test/fixtures/registrar/verb/ignore.js index a09aa05..ab9bb4c 100644 --- a/test/fixtures/registrar/verb/ignore.js +++ b/test/fixtures/registrar/verb/ignore.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ * SOFTWARE. */ -'use strict' +'use strict'; function ignore(req, res, next) {} -module.exports = ignore +module.exports = ignore; diff --git a/test/fixtures/registrar/verb/level1/_id/del.js b/test/fixtures/registrar/verb/level1/_id/del.js index 4629a55..d0162b5 100644 --- a/test/fixtures/registrar/verb/level1/_id/del.js +++ b/test/fixtures/registrar/verb/level1/_id/del.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ * SOFTWARE. */ -'use strict' +'use strict'; function level1IdDel(req, res, next) {} -module.exports = level1IdDel +module.exports = level1IdDel; diff --git a/test/fixtures/registrar/verb/level1/_id/get.js b/test/fixtures/registrar/verb/level1/_id/get.js index 1c7ba44..f632bcb 100644 --- a/test/fixtures/registrar/verb/level1/_id/get.js +++ b/test/fixtures/registrar/verb/level1/_id/get.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ * SOFTWARE. */ -'use strict' +'use strict'; function level1IdGet(req, res, next) {} -module.exports = level1IdGet +module.exports = level1IdGet; diff --git a/test/fixtures/registrar/verb/level1/_id/level2/get.js b/test/fixtures/registrar/verb/level1/_id/level2/get.js index 9be6e3d..c96d06f 100644 --- a/test/fixtures/registrar/verb/level1/_id/level2/get.js +++ b/test/fixtures/registrar/verb/level1/_id/level2/get.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ * SOFTWARE. */ -'use strict' +'use strict'; function level1IdLevel2Get(req, res, next) {} -module.exports = level1IdLevel2Get +module.exports = level1IdLevel2Get; diff --git a/test/fixtures/registrar/verb/level1/_id/put.js b/test/fixtures/registrar/verb/level1/_id/put.js index f17da57..8792fed 100644 --- a/test/fixtures/registrar/verb/level1/_id/put.js +++ b/test/fixtures/registrar/verb/level1/_id/put.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ * SOFTWARE. */ -'use strict' +'use strict'; function level1IdPut(req, res, next) {} -module.exports = level1IdPut +module.exports = level1IdPut; diff --git a/test/fixtures/registrar/verb/level1/get.js b/test/fixtures/registrar/verb/level1/get.js index 5f4540c..bea4b56 100644 --- a/test/fixtures/registrar/verb/level1/get.js +++ b/test/fixtures/registrar/verb/level1/get.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ * SOFTWARE. */ -'use strict' +'use strict'; function level1Get(req, res, next) {} -module.exports = level1Get +module.exports = level1Get; diff --git a/test/fixtures/registrar/verb/level1/post.js b/test/fixtures/registrar/verb/level1/post.js index 01a0ee1..a3f9eba 100644 --- a/test/fixtures/registrar/verb/level1/post.js +++ b/test/fixtures/registrar/verb/level1/post.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,8 +20,8 @@ * SOFTWARE. */ -'use strict' +'use strict'; function level1Post(req, res, next) {} -module.exports = level1Post +module.exports = level1Post; diff --git a/test/mounter/express-mounter.spec.js b/test/mounter/express-mounter.spec.js index ab2347d..623a0ac 100644 --- a/test/mounter/express-mounter.spec.js +++ b/test/mounter/express-mounter.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,65 +20,65 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const { expect } = require('chai') -const sinon = require('sinon') +const { expect } = require('chai'); +const sinon = require('sinon'); -const ExpressMounter = require('../../src/mounter/express-mounter') +const ExpressMounter = require('../../src/mounter/express-mounter'); describe('mounter/express-mounter', () => { describe('ExpressMounter.prototype', () => { - let mounter + let mounter; beforeEach(() => { - mounter = new ExpressMounter() - }) + mounter = new ExpressMounter(); + }); describe('.formatParamPath', () => { it('should prefix the parameter with a colon', () => { - expect(mounter.formatParamPath('foo')).to.equal(':foo') - }) - }) + expect(mounter.formatParamPath('foo')).to.equal(':foo'); + }); + }); describe('.getDefaultVerbs', () => { it('should contain all verbs supported by Express', () => { - expect(mounter.getDefaultVerbs()).to.eql([ 'del', 'get', 'head', 'opts', 'patch', 'post', 'put' ]) - }) - }) + expect(mounter.getDefaultVerbs()).to.eql([ 'del', 'get', 'head', 'opts', 'patch', 'post', 'put' ]); + }); + }); describe('.getPluginName', () => { it('should return correct name', () => { - expect(mounter.getPluginName()).to.equal('express') - }) - }) + expect(mounter.getPluginName()).to.equal('express'); + }); + }); describe('.mount', () => { context('when a single handler is provided', () => { it('should mount the handler onto the server', () => { - const url = '/foo' - const handler = function a() {} - const server = sinon.stub({ get() {} }) + const url = '/foo'; + const handler = function handler() {}; + const server = sinon.stub({ get() {} }); - mounter.mount(url, 'get', handler, { server }) + mounter.mount(url, 'get', handler, { server }); - expect(server.get.calledOnce).to.be.true - expect(server.get.args[0]).to.eql([ url, handler ]) - }) - }) + expect(server.get.calledOnce).to.be.true; + expect(server.get.args[0]).to.eql([ url, handler ]); + }); + }); context('when multiple handlers are provided in an array', () => { it('should mount all handlers onto the server', () => { - const url = '/foo' - const handlers = [ function a() {}, function b() {} ] - const server = sinon.stub({ get() {} }) + const url = '/foo'; + const handlers = [ function a() {}, function b() {} ]; + const server = sinon.stub({ get() {} }); - mounter.mount(url, 'get', handlers, { server }) + mounter.mount(url, 'get', handlers, { server }); - expect(server.get.calledOnce).to.be.true - expect(server.get.args[0]).to.eql([ url ].concat(handlers)) - }) - }) - }) - }) -}) + expect(server.get.calledOnce).to.be.true; + expect(server.get.args[0]).to.eql([ url ].concat(handlers)); + }); + }); + }); + }); +}); diff --git a/test/mounter/index.spec.js b/test/mounter/index.spec.js index 9182002..c5d0c9b 100644 --- a/test/mounter/index.spec.js +++ b/test/mounter/index.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,36 +20,36 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const { expect } = require('chai') +const { expect } = require('chai'); -const Mounter = require('../../src/mounter') +const Mounter = require('../../src/mounter'); describe('mounter/index', () => { describe('Mounter.prototype', () => { - let mounter + let mounter; beforeEach(() => { - mounter = new Mounter() - }) + mounter = new Mounter(); + }); describe('.formatParamPath', () => { it('should be abstract', () => { - expect(mounter.formatParamPath.bind(mounter)).to.throw('Mounter#formatParamPath has not been implemented') - }) - }) + expect(mounter.formatParamPath.bind(mounter)).to.throw('Mounter#formatParamPath has not been implemented'); + }); + }); describe('.getDefaultVerbs', () => { it('should be abstract', () => { - expect(mounter.getDefaultVerbs.bind(mounter)).to.throw('Mounter#getDefaultVerbs has not been implemented') - }) - }) + expect(mounter.getDefaultVerbs.bind(mounter)).to.throw('Mounter#getDefaultVerbs has not been implemented'); + }); + }); describe('.mount', () => { it('should be abstract', () => { - expect(mounter.mount.bind(mounter)).to.throw('Mounter#mount has not been implemented') - }) - }) - }) -}) + expect(mounter.mount.bind(mounter)).to.throw('Mounter#mount has not been implemented'); + }); + }); + }); +}); diff --git a/test/mounter/restify-mounter.spec.js b/test/mounter/restify-mounter.spec.js index 6054145..619896f 100644 --- a/test/mounter/restify-mounter.spec.js +++ b/test/mounter/restify-mounter.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,86 +20,86 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const { expect } = require('chai') -const sinon = require('sinon') +const { expect } = require('chai'); +const sinon = require('sinon'); -const RestifyMounter = require('../../src/mounter/restify-mounter') +const RestifyMounter = require('../../src/mounter/restify-mounter'); describe('mounter/restify-mounter', () => { describe('RestifyMounter.prototype', () => { - let mounter + let mounter; beforeEach(() => { - mounter = new RestifyMounter() - }) + mounter = new RestifyMounter(); + }); describe('.formatParamPath', () => { it('should prefix the parameter with a colon', () => { - expect(mounter.formatParamPath('foo')).to.equal(':foo') - }) - }) + expect(mounter.formatParamPath('foo')).to.equal(':foo'); + }); + }); describe('.getDefaultVerbs', () => { it('should contain all verbs supported by Restify', () => { - expect(mounter.getDefaultVerbs()).to.eql([ 'del', 'get', 'head', 'opts', 'patch', 'post', 'put' ]) - }) - }) + expect(mounter.getDefaultVerbs()).to.eql([ 'del', 'get', 'head', 'opts', 'patch', 'post', 'put' ]); + }); + }); describe('.getPluginName', () => { it('should return correct name', () => { - expect(mounter.getPluginName()).to.equal('restify') - }) - }) + expect(mounter.getPluginName()).to.equal('restify'); + }); + }); describe('.mount', () => { context('when a single handler is provided', () => { it('should mount the handler onto the server', () => { - const url = '/foo' - const handler = function a() {} - const server = sinon.stub({ get() {} }) + const url = '/foo'; + const handler = function handler() {}; + const server = sinon.stub({ get() {} }); - mounter.mount(url, 'get', handler, { server }) + mounter.mount(url, 'get', handler, { server }); - expect(server.get.calledOnce).to.be.true - expect(server.get.args[0]).to.eql([ url, handler ]) - }) - }) + expect(server.get.calledOnce).to.be.true; + expect(server.get.args[0]).to.eql([ url, handler ]); + }); + }); context('when multiple handlers are provided in an array', () => { it('should mount all handlers onto the server', () => { - const url = '/foo' - const handlers = [ function a() {}, function b() {} ] - const server = sinon.stub({ get() {} }) + const url = '/foo'; + const handlers = [ function a() {}, function b() {} ]; + const server = sinon.stub({ get() {} }); - mounter.mount(url, 'get', handlers, { server }) + mounter.mount(url, 'get', handlers, { server }); - expect(server.get.calledOnce).to.be.true - expect(server.get.args[0]).to.eql([ url ].concat(handlers)) - }) - }) + expect(server.get.calledOnce).to.be.true; + expect(server.get.args[0]).to.eql([ url ].concat(handlers)); + }); + }); context('when any handler has a options attached', () => { it('should mount the handlers to the server with those options', () => { - const url = '/foo' - const verb = 'get' - const handlers = [ function a() {}, function b() {} ] - const server = sinon.stub({ get() {} }) - const version = '1.0.0' + const url = '/foo'; + const verb = 'get'; + const handlers = [ function a() {}, function b() {} ]; + const server = sinon.stub({ get() {} }); + const version = '1.0.0'; - handlers[0].options = { version } + handlers[0].options = { version }; - mounter.mount(url, verb, handlers, { server }) + mounter.mount(url, verb, handlers, { server }); - expect(server.get.calledOnce).to.be.true + expect(server.get.calledOnce).to.be.true; expect(server.get.args[0]).to.eql([ { method: verb, path: url, version - } ].concat(handlers)) - }) - }) - }) - }) -}) + } ].concat(handlers)); + }); + }); + }); + }); +}); diff --git a/test/plugin.spec.js b/test/plugin.spec.js index e64865a..07814fc 100644 --- a/test/plugin.spec.js +++ b/test/plugin.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,24 +20,24 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const { expect } = require('chai') +const { expect } = require('chai'); -const Plugin = require('../src/plugin') +const Plugin = require('../src/plugin'); describe('plugin', () => { describe('Plugin.prototype', () => { - let plugin + let plugin; beforeEach(() => { - plugin = new Plugin() - }) + plugin = new Plugin(); + }); describe('.getPluginName', () => { it('should be abstract', () => { - expect(plugin.getPluginName.bind(plugin)).to.throw('Plugin#getPluginName has not been implemented') - }) - }) - }) -}) + expect(plugin.getPluginName.bind(plugin)).to.throw('Plugin#getPluginName has not been implemented'); + }); + }); + }); +}); diff --git a/test/registrar/index-registrar.spec.js b/test/registrar/index-registrar.spec.js index 3000df1..cddcd3f 100644 --- a/test/registrar/index-registrar.spec.js +++ b/test/registrar/index-registrar.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,31 +20,31 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const IndexRegistrar = require('../../src/registrar/index-registrar') -const RegistrarTestCase = require('./registrar-test-case') +const IndexRegistrar = require('../../src/registrar/index-registrar'); +const RegistrarTestCase = require('./registrar-test-case'); describe('registrar/index-registrar', () => { describe('IndexRegistrar.prototype', () => { - let registrar - let testCase + let registrar; + let testCase; beforeEach(() => { - registrar = new IndexRegistrar() - testCase = new RegistrarTestCase(registrar, 'index') - }) + registrar = new IndexRegistrar(); + testCase = new RegistrarTestCase(registrar, 'index'); + }); describe('.getPluginName', () => { it('should return correct name', () => { - testCase.testGetPluginName() - }) - }) + testCase.testGetPluginName(); + }); + }); describe('.register', () => { it('should register index file-based routes via mounter', () => { - testCase.testRegister() - }) - }) - }) -}) + testCase.testRegister(); + }); + }); + }); +}); diff --git a/test/registrar/index.spec.js b/test/registrar/index.spec.js index 58a741f..1848071 100644 --- a/test/registrar/index.spec.js +++ b/test/registrar/index.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,50 +20,50 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const { expect } = require('chai') -const path = require('path') -const sinon = require('sinon') +const { expect } = require('chai'); +const path = require('path'); +const sinon = require('sinon'); -const Mounter = require('../../src/mounter') -const Registrar = require('../../src/registrar') -const routerify = require('../../src/routerify') +const Mounter = require('../../src/mounter'); +const Registrar = require('../../src/registrar'); +const routerify = require('../../src/routerify'); describe('registrar/index', () => { describe('Registrar.prototype', () => { - let mounter - let registrar + let mounter; + let registrar; beforeEach(() => { - mounter = sinon.createStubInstance(Mounter) - registrar = new Registrar() - }) + mounter = sinon.createStubInstance(Mounter); + registrar = new Registrar(); + }); describe('.buildUrl', () => { it('should build the URL correctly', () => { - mounter.formatParamPath.withArgs('id').returns('{id}') + mounter.formatParamPath.withArgs('id').returns('{id}'); - const file = path.join('test', 'fixtures', 'registrar', 'verb', 'level1', '_id', 'level2', 'get.js') + const file = path.join('test', 'fixtures', 'registrar', 'verb', 'level1', '_id', 'level2', 'get.js'); const url = registrar.buildUrl(file, { mounter, paramPattern: /^_(.+)/ - }) + }); - expect(url).to.equal('/test/fixtures/registrar/verb/level1/{id}/level2') - }) - }) + expect(url).to.equal('/test/fixtures/registrar/verb/level1/{id}/level2'); + }); + }); describe('.loadRouter', () => { it('should load file as module based on "dir" option', () => { - expect(registrar.loadRouter('routerify.js', { dir: 'src' })).to.equal(routerify) - }) - }) + expect(registrar.loadRouter('routerify.js', { dir: 'src' })).to.equal(routerify); + }); + }); describe('.register', () => { it('should be abstract', () => { - expect(registrar.register.bind(registrar)).to.throw('Registrar#register has not been implemented') - }) - }) - }) -}) + expect(registrar.register.bind(registrar)).to.throw('Registrar#register has not been implemented'); + }); + }); + }); +}); diff --git a/test/registrar/registrar-test-case.js b/test/registrar/registrar-test-case.js index 01925f5..583d9ad 100644 --- a/test/registrar/registrar-test-case.js +++ b/test/registrar/registrar-test-case.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,23 +20,23 @@ * SOFTWARE. */ -'use strict' +'use strict'; /* eslint "arrow-body-style": "off" */ -const { expect } = require('chai') -const glob = require('glob') -const path = require('path') -const sinon = require('sinon') +const { expect } = require('chai'); +const glob = require('glob'); +const path = require('path'); +const sinon = require('sinon'); -const Mounter = require('../../src/mounter/index') +const Mounter = require('../../src/mounter/index'); class Route { constructor(url, verb, handlers = 1) { - this.url = url - this.verb = verb - this.handlers = handlers + this.url = url; + this.verb = verb; + this.handlers = handlers; } } @@ -44,11 +44,11 @@ class Route { class RegistrarTestCase { constructor(registrar, name) { - this.registrar = registrar - this.name = name - this.directory = `test/fixtures/registrar/${name}` - this.mounter = sinon.createStubInstance(Mounter) - this.mounter.formatParamPath.withArgs('id').returns('{id}') + this.registrar = registrar; + this.name = name; + this.directory = `test/fixtures/registrar/${name}`; + this.mounter = sinon.createStubInstance(Mounter); + this.mounter.formatParamPath.withArgs('id').returns('{id}'); this.expected = [ new Route('/', 'get'), new Route('/', 'head', 2), @@ -58,16 +58,16 @@ class RegistrarTestCase { new Route('/level1/{id}', 'get'), new Route('/level1/{id}', 'put'), new Route('/level1/{id}/level2', 'get') - ] + ]; } testGetPluginName() { - expect(this.registrar.getPluginName()).to.equal(this.name) + expect(this.registrar.getPluginName()).to.equal(this.name); } testRegister() { - const directory = this.directory.replace(/\\|\//g, path.sep) - const fixtures = glob.sync('**/*.js', { cwd: directory }) + const directory = this.directory.replace(/\\|\//g, path.sep); + const fixtures = glob.sync('**/*.js', { cwd: directory }); const options = { dir: directory, ext: '.js', @@ -75,21 +75,21 @@ class RegistrarTestCase { paramPattern: /^_(.+)/, registrar: this.registrar, verbs: [ 'del', 'get', 'head', 'opts', 'patch', 'post', 'put' ] - } + }; fixtures.forEach((fixture) => { - this.registrar.register(fixture, options) - }) + this.registrar.register(fixture, options); + }); - expect(this.mounter.mount.callCount).to.equal(this.expected.length) + expect(this.mounter.mount.callCount).to.equal(this.expected.length); this.expected.forEach((route) => { this.mounter.mount.calledWith(route.url, route.verb, sinon.match((arg) => { - return route.handlers === 1 ? typeof arg === 'function' : Array.isArray(arg) && arg.length === route.handlers - }), options) - }) + return route.handlers === 1 ? typeof arg === 'function' : Array.isArray(arg) && arg.length === route.handlers; + }), options); + }); } } -module.exports = RegistrarTestCase +module.exports = RegistrarTestCase; diff --git a/test/registrar/verb-registrar.spec.js b/test/registrar/verb-registrar.spec.js index 7d2e59b..30e5759 100644 --- a/test/registrar/verb-registrar.spec.js +++ b/test/registrar/verb-registrar.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,31 +20,31 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const RegistrarTestCase = require('./registrar-test-case') -const VerbRegistrar = require('../../src/registrar/verb-registrar') +const RegistrarTestCase = require('./registrar-test-case'); +const VerbRegistrar = require('../../src/registrar/verb-registrar'); describe('registrar/verb-registrar', () => { describe('VerbRegistrar.prototype', () => { - let registrar - let testCase + let registrar; + let testCase; beforeEach(() => { - registrar = new VerbRegistrar() - testCase = new RegistrarTestCase(registrar, 'verb') - }) + registrar = new VerbRegistrar(); + testCase = new RegistrarTestCase(registrar, 'verb'); + }); describe('.getPluginName', () => { it('should return correct name', () => { - testCase.testGetPluginName() - }) - }) + testCase.testGetPluginName(); + }); + }); describe('.register', () => { it('should register verb file-based routes via mounter', () => { - testCase.testRegister() - }) - }) - }) -}) + testCase.testRegister(); + }); + }); + }); +}); diff --git a/test/routerify.spec.js b/test/routerify.spec.js index 3b04a26..426a22b 100644 --- a/test/routerify.spec.js +++ b/test/routerify.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,56 +20,56 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const { expect } = require('chai') -const glob = require('glob') -const sinon = require('sinon') +const { expect } = require('chai'); +const glob = require('glob'); +const sinon = require('sinon'); -const ExpressMounter = require('../src/mounter/express-mounter') -const IndexRegistrar = require('../src/registrar/index-registrar') -const Mounter = require('../src/mounter') -const { version } = require('../package.json') -const Plugin = require('../src/plugin') -const Registrar = require('../src/registrar') -const RestifyMounter = require('../src/mounter/restify-mounter') -const routerify = require('../src/routerify') -const VerbRegistrar = require('../src/registrar/verb-registrar') +const ExpressMounter = require('../src/mounter/express-mounter'); +const IndexRegistrar = require('../src/registrar/index-registrar'); +const Mounter = require('../src/mounter'); +const { version } = require('../package.json'); +const Plugin = require('../src/plugin'); +const Registrar = require('../src/registrar'); +const RestifyMounter = require('../src/mounter/restify-mounter'); +const routerify = require('../src/routerify'); +const VerbRegistrar = require('../src/registrar/verb-registrar'); describe('routerify', () => { describe('routerify', () => { - let mounter - const mounterName = 'routerify-test-mounter' - let registrar - const registrarName = 'routerify-test-registrar' + let mounter; + const mounterName = 'routerify-test-mounter'; + let registrar; + const registrarName = 'routerify-test-registrar'; before(() => { - mounter = sinon.createStubInstance(Mounter) - mounter.getPluginName.returns(mounterName) - registrar = sinon.createStubInstance(Registrar) - registrar.getPluginName.returns(registrarName) + mounter = sinon.createStubInstance(Mounter); + mounter.getPluginName.returns(mounterName); + registrar = sinon.createStubInstance(Registrar); + registrar.getPluginName.returns(registrarName); - routerify.use(mounter) - routerify.use(registrar) - }) + routerify.use(mounter); + routerify.use(registrar); + }); beforeEach(() => { - sinon.stub(glob, 'sync') - }) + sinon.stub(glob, 'sync'); + }); afterEach(() => { - mounter.getDefaultVerbs.reset() - registrar.register.reset() + mounter.getDefaultVerbs.reset(); + registrar.register.reset(); - glob.sync.restore() - }) + glob.sync.restore(); + }); it('should find and register all route modules based on options', () => { const files = [ 'file1.coffee', 'file2.coffee', 'file3.coffee' - ] + ]; const options = { dir: 'test', ext: '.coffee', @@ -79,42 +79,42 @@ describe('routerify', () => { registrar: registrarName, server: sinon.spy(), verbs: [ 'get', 'head' ] - } + }; - glob.sync.withArgs('**/*.coffee', { cwd: 'test', foo: 'bar' }).returns(files) + glob.sync.withArgs('**/*.coffee', { cwd: 'test', foo: 'bar' }).returns(files); - routerify(options) + routerify(options); - expect(registrar.register.callCount).to.equal(files.length) + expect(registrar.register.callCount).to.equal(files.length); files.forEach((file) => { - expect(registrar.register.calledWithExactly(file, options)) - }) - }) + expect(registrar.register.calledWithExactly(file, options)); + }); + }); context('when no options are specifed', () => { - let defaultMounter - let defaultRegistrar + let defaultMounter; + let defaultRegistrar; beforeEach(() => { - defaultMounter = routerify.lookup(Mounter, 'express') - sinon.stub(defaultMounter, 'getDefaultVerbs') - defaultRegistrar = routerify.lookup(Registrar, 'index') - sinon.stub(defaultRegistrar, 'register') - }) + defaultMounter = routerify.lookup(Mounter, 'express'); + sinon.stub(defaultMounter, 'getDefaultVerbs'); + defaultRegistrar = routerify.lookup(Registrar, 'index'); + sinon.stub(defaultRegistrar, 'register'); + }); afterEach(() => { - defaultMounter.getDefaultVerbs.restore() - defaultRegistrar.register.restore() - }) + defaultMounter.getDefaultVerbs.restore(); + defaultRegistrar.register.restore(); + }); it('should use correct default options', () => { const files = [ 'file1.js', 'file2.js', 'file3.js' - ] - const server = sinon.spy() - const verbs = [ 'get', 'head' ] + ]; + const server = sinon.spy(); + const verbs = [ 'get', 'head' ]; const options = { dir: process.cwd(), ext: '.js', @@ -124,99 +124,99 @@ describe('routerify', () => { registrar: 'index', server, verbs - } + }; - defaultMounter.getDefaultVerbs.returns(verbs) - glob.sync.withArgs('**/*.js', { cwd: options.dir }).returns(files) + defaultMounter.getDefaultVerbs.returns(verbs); + glob.sync.withArgs('**/*.js', { cwd: options.dir }).returns(files); - routerify({ server }) + routerify({ server }); - expect(defaultRegistrar.register.callCount).to.equal(files.length) + expect(defaultRegistrar.register.callCount).to.equal(files.length); files.forEach((file) => { - expect(defaultRegistrar.register.calledWithExactly(file, options)) - }) - }) - }) + expect(defaultRegistrar.register.calledWithExactly(file, options)); + }); + }); + }); describe('.lookup', () => { context('when only a type is provided', () => { it('should return all plugins when Plugin is passed', () => { - const plugins = routerify.lookup(Plugin) + const plugins = routerify.lookup(Plugin); - expect(plugins).to.have.length.of.at.least(4) - expect(plugins[0]).to.be.an.instanceOf(ExpressMounter) - expect(plugins[1]).to.be.an.instanceOf(RestifyMounter) - expect(plugins[2]).to.be.an.instanceOf(IndexRegistrar) - expect(plugins[3]).to.be.an.instanceOf(VerbRegistrar) - }) + expect(plugins).to.have.length.of.at.least(4); + expect(plugins[0]).to.be.an.instanceOf(ExpressMounter); + expect(plugins[1]).to.be.an.instanceOf(RestifyMounter); + expect(plugins[2]).to.be.an.instanceOf(IndexRegistrar); + expect(plugins[3]).to.be.an.instanceOf(VerbRegistrar); + }); it('should return only plugins of a given type when it is passed', () => { - const mounters = routerify.lookup(Mounter) + const mounters = routerify.lookup(Mounter); - expect(mounters).to.have.length.of.at.least(2) - expect(mounters[0]).to.be.an.instanceOf(ExpressMounter) - expect(mounters[1]).to.be.an.instanceOf(RestifyMounter) + expect(mounters).to.have.length.of.at.least(2); + expect(mounters[0]).to.be.an.instanceOf(ExpressMounter); + expect(mounters[1]).to.be.an.instanceOf(RestifyMounter); - const registrars = routerify.lookup(Registrar) + const registrars = routerify.lookup(Registrar); - expect(registrars[0]).to.be.an.instanceOf(IndexRegistrar) - expect(registrars[1]).to.be.an.instanceOf(VerbRegistrar) - }) - }) + expect(registrars[0]).to.be.an.instanceOf(IndexRegistrar); + expect(registrars[1]).to.be.an.instanceOf(VerbRegistrar); + }); + }); context('when an existing name is provided along with type', () => { it('should return the specific ', () => { class LookupTestPlugin extends Plugin { getPluginName() { - return 'lookup-test-plugin' + return 'lookup-test-plugin'; } } - const plugin = routerify.use(new LookupTestPlugin()) + const plugin = routerify.use(new LookupTestPlugin()); - expect(routerify.lookup(Plugin, 'lookup-test-plugin')).to.equal(plugin) - }) - }) + expect(routerify.lookup(Plugin, 'lookup-test-plugin')).to.equal(plugin); + }); + }); context('when an unknown name is provided along with type', () => { it('should throw an error', () => { - expect(routerify.lookup.bind(routerify, Plugin, 'foo')).to.throw(Error, 'Unable to lookup Plugin: foo') - }) - }) - }) + expect(routerify.lookup.bind(routerify, Plugin, 'foo')).to.throw(Error, 'Unable to lookup Plugin: foo'); + }); + }); + }); describe('.use', () => { it('should register the plugin', () => { class UseTestPlugin extends Plugin { getPluginName() { - return 'use-test-plugin' + return 'use-test-plugin'; } } - const plugin = new UseTestPlugin() + const plugin = new UseTestPlugin(); - expect(routerify.use(plugin)).to.equal(plugin) - expect(routerify.lookup(Plugin, 'use-test-plugin')).to.equal(plugin) - }) + expect(routerify.use(plugin)).to.equal(plugin); + expect(routerify.lookup(Plugin, 'use-test-plugin')).to.equal(plugin); + }); context('when plugin is null', () => { it('should not add a plugin', () => { - const plugins = routerify.lookup(Object) + const plugins = routerify.lookup(Object); - expect(routerify.use(null)).to.be.null - expect(routerify.lookup(Object)).to.eql(plugins) - }) - }) - }) + expect(routerify.use(null)).to.be.null; + expect(routerify.lookup(Object)).to.eql(plugins); + }); + }); + }); describe('.version', () => { it('should match package version', () => { - expect(routerify.version).to.equal(version) - }) - }) - }) -}) + expect(routerify.version).to.equal(version); + }); + }); + }); +}); diff --git a/test/utilities.spec.js b/test/utilities.spec.js index 08e1b86..5ec3b8a 100644 --- a/test/utilities.spec.js +++ b/test/utilities.spec.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 Alasdair Mercer, Skelp + * Copyright (C) 2017 Alasdair Mercer, !ninja * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -20,11 +20,11 @@ * SOFTWARE. */ -'use strict' +'use strict'; -const { expect } = require('chai') +const { expect } = require('chai'); -const Utilities = require('../src/utilities') +const Utilities = require('../src/utilities'); describe('utilities', () => { describe('Utilities', () => { @@ -33,13 +33,13 @@ describe('utilities', () => { class Foo { static bar() { - Utilities.abstracted(Foo, 'bar') + Utilities.abstracted(Foo, 'bar'); } } - expect(Foo.bar).to.throw(Error, 'Foo#bar has not been implemented') - }) - }) - }) -}) + expect(Foo.bar).to.throw(Error, 'Foo#bar has not been implemented'); + }); + }); + }); +});