Skip to content

Commit

Permalink
pinpoint-apm#86 express version check
Browse files Browse the repository at this point in the history
  • Loading branch information
feelform committed Sep 12, 2023
1 parent 04088b3 commit 68339b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/instrumentation/module/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ const ExpressMethodDescriptorBuilder = require('../../context/express-method-des
const semver = require('semver')

module.exports = function (agent, version, express) {
try {
if (!semver.satisfies(version, '^4.0.0')) {
log.warn(`express version ${version} not supported.`)
return express
}
} catch (error) {
log.error('Invalid Version error')
return express
}

const MODULE_NAME = 'express'
const methodNames = ['GET', 'POST', 'PUT', 'HEAD', 'DELETE', 'OPTIONS', 'PATCH', 'ALL']
Expand Down
11 changes: 11 additions & 0 deletions test/instrumentation/module/express.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,15 @@ test(`${testName6} Should record each http method`, function (t) {
test('semver test', (t) => {
t.false(semver.satisfies('5.0.0', '^4.0.0'), 'express version')
t.end()
})

test('express version check', (t) => {
const hook = require('../../../lib/instrumentation/module/express')
const expected = { name: 'module' }
let actual = hook(null, '5.0', expected)
t.equal(actual.name, 'module', 'express version 5.0 test')

actual = hook(null, '5.0.0', expected)
t.equal(actual.name, 'module', 'express version 5.0.0 test')
t.end()
})

0 comments on commit 68339b2

Please sign in to comment.