swagger-stats icon indicating copy to clipboard operation
swagger-stats copied to clipboard

Process does not finish when running jest tests

Open sepulvedablanco opened this issue 7 years ago • 1 comments
trafficstars

Hi everyone, First of all, thanks for your help and support in monitoring API´s performance. I find it really useful. I have an issue once the middleware swagger-stat is imported. When I run test with JEST, I have noticed that it does not come back to the shell, so the process does not finish successfully. However, if I do not use the middleware, the process regarding the aforementioned test I am running, ends successfully. Could you give any advice regarding this issue?

sepulvedablanco avatar Mar 04 '18 22:03 sepulvedablanco

@sepulvedablanco You'll need to close your server in an afterAll hook like so:

import request from 'supertest'
import swaggerDef from '../../../src/swagger'
import { server } from '../../../src/app'

 describe('Swagger Routes', () => {
   afterAll(() => {
    server.close()  // Close the process
  })
  
  describe('when called', () => {
    it('should return updated swagger object', async () => {
      await request(server)
        .get(`${swaggerDef.basePath}/swagger-stats`)
        .expect(200)
        .expect(result => {
          expect(result.body).toEqual(swaggerDef)
        })
    })
  })
})

dmwelch avatar Jan 17 '19 15:01 dmwelch