@unito/integration-sdk
Version:
Integration SDK
24 lines (23 loc) • 1.01 kB
JavaScript
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import start from '../../src/middlewares/start.js';
import { RequestMetrics } from '../../src/resources/requestMetrics.js';
describe('start middleware', () => {
it('initializes request metrics on locals', () => {
const request = {};
const response = { locals: {} };
start(request, response, () => { });
assert.ok(response.locals.requestMetrics instanceof RequestMetrics);
assert.match(response.locals.requestId, /^[0-9a-f-]{36}$/);
});
it('records request start time in metrics', () => {
const request = {};
const response = { locals: {} };
const before = process.hrtime.bigint();
start(request, response, () => { });
const result = response.locals.requestMetrics.endRequest();
const after = process.hrtime.bigint();
assert.ok(result.durationNs >= 0n);
assert.ok(result.durationNs <= after - before);
});
});