server-timing
Advanced tools
Comparing version 3.2.2 to 3.3.1
declare module "server-timing" { | ||
import * as e from "express"; | ||
type Options = { | ||
name?: string, | ||
description?: string, | ||
total?: boolean; | ||
@@ -5,0 +7,0 @@ enabled?: boolean | IsEnabledCheck; |
@@ -8,2 +8,4 @@ 'use strict' | ||
const opts = Object.assign({ | ||
name: 'total', | ||
description: 'Total Response Time', | ||
total: true, | ||
@@ -38,3 +40,3 @@ enabled: true, | ||
const timeSec = (diff[0] * 1E3) + (diff[1] * 1e-6) | ||
res.setMetric('total', timeSec, 'Total Response Time') | ||
res.setMetric(opts.name, timeSec, opts.description) | ||
} | ||
@@ -41,0 +43,0 @@ timer.clear() |
{ | ||
"name": "server-timing", | ||
"version": "3.2.2", | ||
"version": "3.3.1", | ||
"description": "This module can add `ServerTiming` Header to http response, and be able to use express middleware", | ||
@@ -38,3 +38,3 @@ "main": "index.js", | ||
"coveralls": "3.1.0", | ||
"eater": "4.0.3", | ||
"eater": "4.0.4", | ||
"espower-loader": "1.2.2", | ||
@@ -45,4 +45,4 @@ "express": "4.17.1", | ||
"power-assert": "1.6.1", | ||
"standard": "14.3.4" | ||
"standard": "16.0.1" | ||
} | ||
} |
@@ -67,2 +67,4 @@ # server-timing | ||
- options.name: string, default `total`, name for the timing item | ||
- options.description: string, default `Total Response Time`, explanation for the timing item | ||
- options.total: boolean, default `true`, add total response time | ||
@@ -69,0 +71,0 @@ - options.enabled: boolean | function, default `true`, enable server timing header. If a function is passed, it will be called with two arguments, `request` and `response`, and should return a boolean. |
@@ -28,2 +28,22 @@ 'use strict' | ||
test('custom timing name and description', () => { | ||
const app = express() | ||
app.use(serverTiming({ | ||
name: 'app', | ||
description: 'Service Layer Response Time' | ||
})) | ||
app.use((req, res, next) => { | ||
res.send('hello') | ||
}) | ||
const server = app.listen(0, () => { | ||
http.get(`http://localhost:${server.address().port}/`, mustCall((res) => { | ||
const assertStream = new AssertStream() | ||
assertStream.expect('hello') | ||
res.pipe(assertStream) | ||
assert(/app; dur=.*; desc="Service Layer Response Time"/.test(res.headers['server-timing'])) | ||
server.close() | ||
})) | ||
}) | ||
}) | ||
test('express add some custom server timing header', () => { | ||
@@ -30,0 +50,0 @@ const app = express() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25815
668
77