diff --git a/src/metrics.ts b/src/metrics.ts index e12dfd6..9916cb5 100644 --- a/src/metrics.ts +++ b/src/metrics.ts @@ -91,7 +91,7 @@ export default class VerdaccioMiddlewarePlugin implements IPluginMiddleware { + res.once('close', () => { const { statusCode } = res; const metricLabels: MetricsLabels = { username, userAgentName, statusCode }; if (packageGroup) { diff --git a/tests/testUtils.ts b/tests/testUtils.ts index 12b1d1e..26ff77d 100644 --- a/tests/testUtils.ts +++ b/tests/testUtils.ts @@ -95,7 +95,7 @@ export function generateMockResponse() { status: jest.fn(), send: jest.fn(), once: jest.fn().mockImplementation(function (eventName, handler: any) { - if (eventName === 'finish') { + if (eventName === 'close') { mockResponse.statusCode = 200; mockResponse.finish.mockImplementation(handler); }