Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Neriuzz committed Nov 28, 2023
1 parent b7cc922 commit 0057ce7
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/__tests__/route-metrics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,66 @@ describe('route metrics', () => {
});
});

describe('{ enabled = {} }', () => {
let app = fastify();

afterEach(async () => {
await app.close();
});

beforeEach(async () => {
app = fastify();

await app.register(fastifyPlugin, {
endpoint: '/metrics',
routeMetrics: {
enabled: {},
},
});
app.get('/test', async () => {
return 'get test';
});
app.post('/test', async () => {
return 'post test';
});
await app.ready();
});

test('metrics exposed', async () => {
await expect(
app.inject({
method: 'GET',
url: '/test',
})
).resolves.toBeDefined();

await expect(
app.inject({
method: 'POST',
url: '/test',
})
).resolves.toBeDefined();

const metrics = await app.inject({
method: 'GET',
url: '/metrics',
});

expect(typeof metrics.payload).toBe('string');

const lines = metrics.payload.split('\n');

expect(lines).toEqual(
expect.arrayContaining([
'http_request_duration_seconds_count{method="GET",route="/test",status_code="200"} 1',
'http_request_duration_seconds_count{method="POST",route="/test",status_code="200"} 1',
'http_request_summary_seconds_count{method="GET",route="/test",status_code="200"} 1',
'http_request_summary_seconds_count{method="POST",route="/test",status_code="200"} 1',
])
);
});
});

describe('{ registeredRoutesOnly = false }', () => {
let app = fastify();

Expand Down

0 comments on commit 0057ce7

Please sign in to comment.