diff --git a/index.js b/index.js index 616a8ca..0a01122 100644 --- a/index.js +++ b/index.js @@ -27,9 +27,11 @@ module.exports = getCurrentNodeMethods() || getBasicNodeMethods() */ function getCurrentNodeMethods () { - return http.METHODS && http.METHODS.map(function lowerCaseMethod (method) { + var methods = http.METHODS && http.METHODS.map(function lowerCaseMethod (method) { return method.toLowerCase() }) + + return (methods && methods.length > 0) ? methods : false } /** diff --git a/package.json b/package.json index ac28d1b..d4aba5d 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "scripts": { "lint": "eslint .", "test": "mocha --reporter spec --bail --check-leaks test/", + "test-debug": "mocha --inspect-brk test/", "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/", "test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/" }, diff --git a/test/methods.js b/test/methods.js index 98899d5..0c4a540 100644 --- a/test/methods.js +++ b/test/methods.js @@ -1,8 +1,8 @@ -var http = require('http') var assert = require('assert') -var methods = require('..') describe('methods', function () { + var http = require('http') + var methods = require('..') if (http.METHODS) { it('is a lowercased http.METHODS', function () { var lowercased = http.METHODS.map(function (method) { @@ -25,3 +25,47 @@ describe('methods', function () { }) } }) + +describe('empty methods', function () { + it('should get the default methods if http.METHODS === []', function () { + delete require.cache[require.resolve('http')] + delete require.cache[require.resolve('..')] + var http = require('http') + http.METHODS = [] + var defaultMethods = require('..') + var defaultValues = [ + 'get', + 'post', + 'put', + 'head', + 'delete', + 'options', + 'trace', + 'copy', + 'lock', + 'mkcol', + 'move', + 'purge', + 'propfind', + 'proppatch', + 'unlock', + 'report', + 'mkactivity', + 'checkout', + 'merge', + 'm-search', + 'notify', + 'subscribe', + 'unsubscribe', + 'patch', + 'search', + 'connect' + ] + var leng = defaultMethods.length + assert.equal(defaultMethods.length, defaultValues.length) + + for (var i = 0; i < leng; i++) { + assert.equal(defaultMethods[i], defaultValues[i]) + } + }) +})