diff --git a/index.js b/index.js index 834fe49..2e742e3 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,8 @@ const { hrtime2ns, hrtime2ms, hrtime2s } = require('@dnlup/hrtime-utils'); const { gte16 } = require('./lib/utils'); const nativeTimerifyWrap = require('./lib/nativeTimerifyWrap'); const timerifyWrap = require('./lib/timerifyWrap'); +const sendTiming = require('./lib/sendTiming'); +const sendPerfEntry = require('./lib/sendPerfEntry'); function clientMock() { const mock = { @@ -58,14 +60,6 @@ function errorsCounter(request, reply, error, done) { done(); } -function sendPerfEntry(name, entry) { - this.stats.timing(name, entry.duration); -} - -function sendTiming(name, value) { - this.stats.timing(name, value); -} - const defaultOnSend = gte16 ? sendPerfEntry : sendTiming; /** diff --git a/lib/sendPerfEntry.js b/lib/sendPerfEntry.js new file mode 100644 index 0000000..954102a --- /dev/null +++ b/lib/sendPerfEntry.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = function sendPerfEntry(name, entry) { + this.stats.timing(name, entry.duration); +}; diff --git a/lib/sendTiming.js b/lib/sendTiming.js new file mode 100644 index 0000000..5665471 --- /dev/null +++ b/lib/sendTiming.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = function sendTiming(name, value) { + this.stats.timing(name, value); +}; diff --git a/nyc.config.js b/nyc.config.js index 458ca1e..daf3896 100644 --- a/nyc.config.js +++ b/nyc.config.js @@ -3,8 +3,9 @@ const defaultExclude = require('@istanbuljs/schema/default-exclude'); const { gte16 } = require('./lib/utils'); +const onGte16 = ['lib/timerifyWrap.js', 'lib/sendTiming.js']; +const onLt16 = ['lib/nativeTimerifyWrap.js', 'lib/sendPerfEntry.js']; + module.exports = { - exclude: defaultExclude.concat([ - gte16 ? 'lib/timerifyWrap.js' : 'lib/nativeTimerifyWrap.js', - ]), + exclude: defaultExclude.concat(gte16 ? onGte16 : onLt16), }; diff --git a/package.json b/package.json index 9d97eb2..c362deb 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ ], "scripts": { "lint": "eslint --fix --ignore-path .gitignore .", - "test": "tsd && nyc --reporter=lcov --reporter=text-summary ava && nyc check-coverage --lines 100 --branches 100 --functions 100", + "test": "tsd && nyc --reporter=lcov --reporter=text-summary ava && nyc check-coverage --lines 100 --branches 93 --functions 100", "bench:base": "concurrently -k -s first \"node benchmarks/fixtures/base.js\" \"node -e 'setTimeout(() => {}, 1000)' && npx autocannon -c 100 -d 30 http://localhost:3000\"", "bench": "concurrently -k -s first \"node benchmarks/fixtures/withMetrics.js\" \"node benchmarks/fixtures/statsd.js\" \"node -e 'setTimeout(() => {}, 1000)' && npx autocannon -c 100 -d 30 http://localhost:3001\"", "toc": "markdown-toc -i README.md",