How can I attach the debugger to my code running on the server returned by INestApplication.getHttpServer()

  javascript, jestjs, nestjs, node.js, supertest

I’m running an app built with NestJS. I have integration tests written with the supertest library. I’m using Jest as my testing framework / test runner. My integration tests look like this.

describe('Item controller', () => {

    beforeAll(async () => {
    const moduleRef = await Test.createTestingModule({
      imports: [AppModule],
    }).compile();

    app = moduleRef.createNestApplication();
    await app.init();

    test('/Delete endpoint returns 404 if item does not exist', async () => {
        const nonExistentId = '081512e0-3d32-45cb-926c-f5140b99ca85'
        req(app.getHttpServer())
        .delete(`/items/${nonExistentId}`)
        .set('X-Company-Id', company.id)
        .expect(404)
      });
});

Working in Visual Studio code I can run the debugger and set a break point in the test and step through line by line. However, I need to be able to step through the code that runs at the endpoint. Is there any way I can attach a debugger to the code running on the server that gets returned by app.getHttpServer()?

Before I wasn’t using super test to hit the endpoint with a request. I was creating an instance of the actual controller and just calling the function. However, this bypasses middle-ware.

Source: Ask Javascript Questions

LEAVE A COMMENT