Skip to content

Commit

Permalink
add test case to express.Router
Browse files Browse the repository at this point in the history
  • Loading branch information
KarineValenca committed Jul 27, 2020
1 parent 3c52f52 commit 0021758
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 8 additions & 0 deletions test/app_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ app.get('/', (req, res) => {
res.send('test')
})

const router = express.Router()

router.get('/testRouter', (req, res) => {
res.send("hello")
})

app.use('/router', router)



module.exports = app
22 changes: 21 additions & 1 deletion test/test_monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Collect metrics middleware', () => {
.get('/')
.set('Content-Type', 'application/json')
.send()
.end((err, res) => {
.end((err) => {
if(err) console.log(err)
})
chai.request(app)
Expand All @@ -32,4 +32,24 @@ describe('Collect metrics middleware', () => {
expect(res.text).to.include('response_size_bytes{type="http",status="200",method="GET",addr="/",isError="false",errorMessage=""}')
})
})

it('should collect metric from express.Router', () => {
chai.request(app)
.get('/router/testRouter')
.set('Content-Type', 'application/json')
.send()
.end((err) => {
if(err) console.log(err)
})
chai.request(app)
.get('/metrics')
.set('Content-Type', 'application/json')
.send()
.end((err, res) => {
expect(res.text).to.include('request_seconds_bucket{le="0.1",type="http",status="200",method="GET",addr="/router/testRouter",isError="false",errorMessage=""} 1')
expect(res.text).to.include('request_seconds_sum{type="http",status="200",method="GET",addr="/router/testRouter",isError="false",errorMessage=""}')
expect(res.text).to.include('request_seconds_count{type="http",status="200",method="GET",addr="/router/testRouter",isError="false",errorMessage=""} 1')
expect(res.text).to.include('response_size_bytes{type="http",status="200",method="GET",addr="/router/testRouter",isError="false",errorMessage=""}')
})
})
})

0 comments on commit 0021758

Please sign in to comment.