From cdf169320401fe6786875e4568574afcbac98808 Mon Sep 17 00:00:00 2001 From: Adrian Ferreres Esteller Date: Wed, 16 Jan 2019 15:18:58 +0100 Subject: [PATCH 1/8] If Http does not has methods declared the default ones are returned --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 616a8ca..7f730d5 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) { + const methods = http.METHODS && http.METHODS.map(function lowerCaseMethod (method) { return method.toLowerCase() - }) + }); + + return methods; } /** From 748c799a5ba1e460f01d8b6a20c47af7a7c2c098 Mon Sep 17 00:00:00 2001 From: Adrian Ferreres Esteller Date: Thu, 17 Jan 2019 07:37:54 +0100 Subject: [PATCH 2/8] Check if http.METHODS exists and if it is an array with values --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7f730d5..05b331f 100644 --- a/index.js +++ b/index.js @@ -31,7 +31,7 @@ function getCurrentNodeMethods () { return method.toLowerCase() }); - return methods; + return (methods && methods.length > 0) ? methods : false; } /** From bf999d7095dbaf169f4f190390df58ee89347169 Mon Sep 17 00:00:00 2001 From: Adrian Ferreres Esteller Date: Thu, 17 Jan 2019 08:26:56 +0100 Subject: [PATCH 3/8] Change const by var for backward compatibility --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 05b331f..429b5d4 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,7 @@ module.exports = getCurrentNodeMethods() || getBasicNodeMethods() */ function getCurrentNodeMethods () { - const methods = http.METHODS && http.METHODS.map(function lowerCaseMethod (method) { + var methods = http.METHODS && http.METHODS.map(function lowerCaseMethod (method) { return method.toLowerCase() }); From 92d35923f6f3514fe9f2da6c38cb3975aaa1b4b3 Mon Sep 17 00:00:00 2001 From: Adrian Ferreres Esteller Date: Thu, 17 Jan 2019 08:35:12 +0100 Subject: [PATCH 4/8] Remove extra semicolon at the end of the lines --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 429b5d4..0a01122 100644 --- a/index.js +++ b/index.js @@ -29,9 +29,9 @@ module.exports = getCurrentNodeMethods() || getBasicNodeMethods() function getCurrentNodeMethods () { var methods = http.METHODS && http.METHODS.map(function lowerCaseMethod (method) { return method.toLowerCase() - }); + }) - return (methods && methods.length > 0) ? methods : false; + return (methods && methods.length > 0) ? methods : false } /** From 130f0fa85c648e00e777667bceeb136b9ded1dec Mon Sep 17 00:00:00 2001 From: Adrian Ferreres Esteller Date: Sat, 19 Jan 2019 20:01:51 +0100 Subject: [PATCH 5/8] Add unit test --- package.json | 3 +++ test/methods.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index ac28d1b..c9fc09b 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,8 @@ "license": "MIT", "repository": "jshttp/methods", "devDependencies": { + "chai": "^4.2.0", + "chai-spies": "^1.0.0", "eslint": "4.19.1", "eslint-config-standard": "11.0.0", "eslint-plugin-import": "2.13.0", @@ -30,6 +32,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..8bb9d96 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,48 @@ 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]) + } + + }) +}) From 07afd630b4d2e07da0365243f2ca047b3b61539f Mon Sep 17 00:00:00 2001 From: Adrian Ferreres Esteller Date: Sat, 19 Jan 2019 20:04:47 +0100 Subject: [PATCH 6/8] Remove chai dependencies --- package.json | 2 -- 1 file changed, 2 deletions(-) diff --git a/package.json b/package.json index c9fc09b..d4aba5d 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,6 @@ "license": "MIT", "repository": "jshttp/methods", "devDependencies": { - "chai": "^4.2.0", - "chai-spies": "^1.0.0", "eslint": "4.19.1", "eslint-config-standard": "11.0.0", "eslint-plugin-import": "2.13.0", From bfea6628935a6866363764f9a2d01ec8d660fa59 Mon Sep 17 00:00:00 2001 From: Adrian Ferreres Esteller Date: Sat, 19 Jan 2019 20:11:13 +0100 Subject: [PATCH 7/8] Fix code styles --- test/methods.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/methods.js b/test/methods.js index 8bb9d96..680fb1c 100644 --- a/test/methods.js +++ b/test/methods.js @@ -27,7 +27,7 @@ describe('methods', function () { }) describe('empty methods', function () { - it('should get the default methods if http.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') @@ -67,6 +67,5 @@ describe('empty methods', function () { for (var i = 0; i < leng; i++) { assert.equal(defaultMethods[i], defaultValues[i]) } - }) -}) +}) \ No newline at end of file From 0b9479ff9a5b671c80681f5858f9548ca46885a4 Mon Sep 17 00:00:00 2001 From: Adrian Ferreres Esteller Date: Sat, 19 Jan 2019 20:15:28 +0100 Subject: [PATCH 8/8] Add extra line at the end of the test --- test/methods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/methods.js b/test/methods.js index 680fb1c..0c4a540 100644 --- a/test/methods.js +++ b/test/methods.js @@ -68,4 +68,4 @@ describe('empty methods', function () { assert.equal(defaultMethods[i], defaultValues[i]) } }) -}) \ No newline at end of file +})