From 351de8ed499252d403dbc4d35c1043e0a74cf921 Mon Sep 17 00:00:00 2001 From: Davide Bianchi <10374360+davidebianchi@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:41:09 +0200 Subject: [PATCH] fix: getResponseTime deprecation warning (#383) * fix: getResponseTime deprecation warning * expose coverage lcov * fix * fix github action --- .github/workflows/node.js.yml | 3 ++- .gitignore | 1 + CHANGELOG.md | 4 ++++ lib/custom-logger.js | 2 +- package.json | 21 +++++++++---------- .../tests/custom-logger.test.js.test.cjs | 6 +++--- .../documentation-routes.test.js.test.cjs | 6 +++--- 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index 0d5cd66..3bd610d 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -33,9 +33,10 @@ jobs: - run: npm test - name: Coveralls - uses: coverallsapp/github-action@master + uses: coverallsapp/github-action@v2 with: github-token: ${{ secrets.GITHUB_TOKEN }} + file: ./.tap/report/lcov.info publish: runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 9a22b53..77dc5df 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ coverage # nyc test coverage .nyc_output +.tap # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) .grunt diff --git a/CHANGELOG.md b/CHANGELOG.md index 8caad1b..763d5bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- use `reply.elapsedTime` instead of the deprecated `reply.getResponseTime()` to get the elapsed time of the request + ## v8.0.1 - 2024-08-06 ### Fixed diff --git a/lib/custom-logger.js b/lib/custom-logger.js index f7a474a..927d1bf 100644 --- a/lib/custom-logger.js +++ b/lib/custom-logger.js @@ -109,7 +109,7 @@ function logRequestCompleted(req, reply, next) { forwardedHost: headers['x-forwarded-host'], ip: headers['x-forwarded-for'], }, - responseTime: reply.getResponseTime(), + responseTime: reply.elapsedTime, }, 'request completed') next() } diff --git a/package.json b/package.json index e1c1fc0..26dda1a 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,7 @@ }, "scripts": { "checkonly": "! grep -R '\\.only' tests/", - "coverage": "npm run unit -- --coverage-report=text-summary", - "postcoverage": "tap --coverage-report=html --no-browser", + "coverage": "npm run unit -- --coverage-report=text-summary --coverage-report=lcov --no-browser", "lint": "eslint . --ignore-path .gitignore", "test": "npm run lint && npm run coverage && npm run test:types && npm run checkonly", "unit": "tap -b -o tap.log tests/*.test.js", @@ -44,13 +43,13 @@ "@fastify/sensible": "^5.5.0", "@fastify/swagger": "^8.12.0", "@fastify/swagger-ui": "^1.10.1", - "@opentelemetry/auto-instrumentations-node": "^0.48.0", - "@opentelemetry/sdk-node": "^0.49.1", - "@opentelemetry/sdk-trace-base": "^1.18.1", + "@opentelemetry/auto-instrumentations-node": "^0.49.1", + "@opentelemetry/sdk-node": "^0.52.1", + "@opentelemetry/sdk-trace-base": "^1.25.1", "commander": "^11.1.0", "dotenv": "^16.3.1", "dotenv-expand": "^11.0.3", - "fastify": "^4.24.3", + "fastify": "^4.28.1", "fastify-metrics": "^10.3.3", "fastify-plugin": "^4.5.1", "lodash.get": "^4.4.2", @@ -58,13 +57,13 @@ }, "devDependencies": { "@mia-platform/eslint-config-mia": "^3.0.0", - "ajv": "^8.12.0", + "ajv": "^8.17.1", "eslint": "^8.53.0", - "semver": "^7.5.4", + "semver": "^7.6.3", "split2": "^4.2.0", "swagger-parser": "^10.0.3", - "tap": "^16.3.7", - "tsd": "^0.30.4" + "tap": "^21.0.1", + "tsd": "^0.31.1" }, "engines": { "node": ">=14" @@ -73,6 +72,6 @@ "extends": "@mia-platform/eslint-config-mia" }, "tap": { - "check-coverage": false + "allow-incomplete-coverage": true } } diff --git a/tap-snapshots/tests/custom-logger.test.js.test.cjs b/tap-snapshots/tests/custom-logger.test.js.test.cjs index e1b2539..de228db 100644 --- a/tap-snapshots/tests/custom-logger.test.js.test.cjs +++ b/tap-snapshots/tests/custom-logger.test.js.test.cjs @@ -5,7 +5,7 @@ * Make sure to inspect the output below. Do not ignore changes! */ 'use strict' -exports[`tests/custom-logger.test.js TAP Test log serialize error both for error and err fields > must match snapshot 1`] = ` +exports[`tests/custom-logger.test.js > TAP > Test log serialize error both for error and err fields > must match snapshot 1`] = ` Array [ Object { "err": Object { @@ -22,7 +22,7 @@ Array [ ] ` -exports[`tests/custom-logger.test.js TAP Test redacted values - uppercase headers > must match snapshot 1`] = ` +exports[`tests/custom-logger.test.js > TAP > Test redacted values - uppercase headers > must match snapshot 1`] = ` Array [ Object { "headersToSend": Object { @@ -33,7 +33,7 @@ Array [ ] ` -exports[`tests/custom-logger.test.js TAP Test redacted values > must match snapshot 1`] = ` +exports[`tests/custom-logger.test.js > TAP > Test redacted values > must match snapshot 1`] = ` Array [ Object { "headers": Object { diff --git a/tap-snapshots/tests/documentation-routes.test.js.test.cjs b/tap-snapshots/tests/documentation-routes.test.js.test.cjs index ae2ea11..9184544 100644 --- a/tap-snapshots/tests/documentation-routes.test.js.test.cjs +++ b/tap-snapshots/tests/documentation-routes.test.js.test.cjs @@ -5,7 +5,7 @@ * Make sure to inspect the output below. Do not ignore changes! */ 'use strict' -exports[`tests/documentation-routes.test.js TAP Test Fastify creation with custom prefix > must match snapshot 1`] = ` +exports[`tests/documentation-routes.test.js > TAP > Test Fastify creation with custom prefix > must match snapshot 1`] = ` Object { "components": Object { "schemas": Object { @@ -204,7 +204,7 @@ Object { } ` -exports[`tests/documentation-routes.test.js TAP Test Fastify creation with custom prefix without trailing slash > must match snapshot 1`] = ` +exports[`tests/documentation-routes.test.js > TAP > Test Fastify creation with custom prefix without trailing slash > must match snapshot 1`] = ` Object { "components": Object { "schemas": Object { @@ -410,7 +410,7 @@ Object { } ` -exports[`tests/documentation-routes.test.js TAP Test Fastify creation with no prefix > must match snapshot 1`] = ` +exports[`tests/documentation-routes.test.js > TAP > Test Fastify creation with no prefix > must match snapshot 1`] = ` Object { "components": Object { "schemas": Object {