From b59aa5707da359b863c770cb728e12bf5fe411f9 Mon Sep 17 00:00:00 2001 From: Kevin Hira Date: Wed, 9 Mar 2022 00:17:17 +1300 Subject: [PATCH] Add integration test for wildcard path scenario Issue: #59 --- test/integration-tests/koa/middleware-test.js | 17 +++++++++++++++++ test/integration-tests/koa/server/koa-server.js | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/test/integration-tests/koa/middleware-test.js b/test/integration-tests/koa/middleware-test.js index 07f22ca..978fa0f 100644 --- a/test/integration-tests/koa/middleware-test.js +++ b/test/integration-tests/koa/middleware-test.js @@ -679,6 +679,23 @@ describe('when using koa framework', () => { }); }); }); + describe('when calling wildcard endpoint', function () { + before(() => { + const wildcardPath = '/wild-path/' + Math.floor(Math.random() * 10); + return supertest(app) + .get(wildcardPath) + .expect(200) + .then((res) => {}); + }); + it('should add it to the histogram', () => { + return supertest(app) + .get('/metrics') + .expect(200) + .then((res) => { + expect(res.text).to.contain('method="GET",route="N/A",code="200"'); + }); + }); + }); it('should get metrics as json', () => { return supertest(app) .get('/metrics.json') diff --git a/test/integration-tests/koa/server/koa-server.js b/test/integration-tests/koa/server/koa-server.js index fd5a04b..fa28c39 100644 --- a/test/integration-tests/koa/server/koa-server.js +++ b/test/integration-tests/koa/server/koa-server.js @@ -78,4 +78,10 @@ router.post('/test', async (ctx, next) => { return next(); }); +router.get('/wild-path/(.*)', (ctx, next) => { + ctx.status = 200; + ctx.body = { message: 'Wildcard route reached!' }; + return next(); +}); + module.exports = app;