Skip to content

Commit

Permalink
fix: replace methods imports everywhere (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkoops authored Oct 29, 2024
1 parent 878b0e0 commit 0fe592e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

const isPromise = require('is-promise')
const Layer = require('./lib/layer')
const methods = require('methods')
const { METHODS } = require('node:http')
const mixin = require('utils-merge')
const parseUrl = require('parseurl')
const Route = require('./lib/route')
Expand All @@ -26,6 +26,7 @@ const Route = require('./lib/route')

const slice = Array.prototype.slice
const flatten = Array.prototype.flat
const methods = METHODS.map((method) => method.toLowerCase())

/**
* Expose `Router`.
Expand Down
4 changes: 1 addition & 3 deletions lib/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const { METHODS } = require('node:http')

const slice = Array.prototype.slice
const flatten = Array.prototype.flat
const methods = METHODS.map((method) => method.toLowerCase())

/* istanbul ignore next */
const defer = typeof setImmediate === 'function'
Expand Down Expand Up @@ -215,9 +216,6 @@ Route.prototype.all = function all (handler) {
return this
}


const methods = METHODS.map((method) => method.toLowerCase())

methods.forEach(function (method) {
Route.prototype[method] = function (handler) {
const callbacks = flatten.call(slice.call(arguments), Infinity)
Expand Down
2 changes: 1 addition & 1 deletion test/route.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const { it, describe } = require('mocha')
const Buffer = require('safe-buffer').Buffer
const methods = require('methods')
const series = require('run-series')
const Router = require('..')
const utils = require('./support/utils')
Expand All @@ -13,6 +12,7 @@ const shouldHaveBody = utils.shouldHaveBody
const shouldHitHandle = utils.shouldHitHandle
const shouldNotHaveBody = utils.shouldNotHaveBody
const shouldNotHitHandle = utils.shouldNotHitHandle
const methods = utils.methods

const describePromises = global.Promise ? describe : describe.skip

Expand Down
2 changes: 1 addition & 1 deletion test/router.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { it, describe } = require('mocha')
const series = require('run-series')
const Buffer = require('safe-buffer').Buffer
const methods = require('methods')
const Router = require('..')
const utils = require('./support/utils')

Expand All @@ -14,6 +13,7 @@ const shouldHaveBody = utils.shouldHaveBody
const shouldHitHandle = utils.shouldHitHandle
const shouldNotHaveBody = utils.shouldNotHaveBody
const shouldNotHitHandle = utils.shouldNotHitHandle
const methods = utils.methods

const describePromises = global.Promise ? describe : describe.skip

Expand Down
5 changes: 4 additions & 1 deletion test/support/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ const assert = require('assert')
const Buffer = require('safe-buffer').Buffer
const finalhandler = require('finalhandler')
const http = require('http')
const methods = require('methods')
const { METHODS } = require('node:http')
const request = require('supertest')

const methods = METHODS.map((method) => method.toLowerCase())

exports.assert = assert
exports.createHitHandle = createHitHandle
exports.createServer = createServer
Expand All @@ -14,6 +16,7 @@ exports.shouldHaveBody = shouldHaveBody
exports.shouldNotHaveBody = shouldNotHaveBody
exports.shouldHitHandle = shouldHitHandle
exports.shouldNotHitHandle = shouldNotHitHandle
exports.methods = methods

function createHitHandle (num) {
const name = 'x-fn-' + String(num)
Expand Down

0 comments on commit 0fe592e

Please sign in to comment.