Skip to content

Commit

Permalink
Merge bfea662 into 90dd6f9
Browse files Browse the repository at this point in the history
  • Loading branch information
ardiadrianadri committed Jan 19, 2019
2 parents 90dd6f9 + bfea662 commit 64a35fb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
4 changes: 3 additions & 1 deletion index.js
Expand Up @@ -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
}

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -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/"
},
Expand Down
48 changes: 46 additions & 2 deletions 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) {
Expand All @@ -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])
}
})
})

0 comments on commit 64a35fb

Please sign in to comment.