javascript - 如何将调试器附加到在 INestApplication.getHttpServer() 返回的服务器上运行的代码
问题描述
我正在运行一个用 NestJS 构建的应用程序。我有使用 supertest 库编写的集成测试。我使用 Jest 作为我的测试框架/测试运行器。我的集成测试看起来像这样。
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)
});
});
在 Visual Studio 代码中工作,我可以运行调试器并在测试中设置断点并逐行执行。但是,我需要能够单步执行在端点运行的代码。有什么办法可以将调试器附加到服务器上运行的代码上,该代码由app.getHttpServer()
.
在我没有使用超级测试通过请求到达端点之前。我正在创建实际控制器的实例并调用该函数。但是,这绕过了中间件。
解决方案
推荐阅读
- android - 浮动操作按钮背景模糊
- mysql - MySQL GROUP 基于其他列的列,但也排除基于第二列的重复项
- mysql - 我在 MySQL 中的查询没有得到预期的结果
- arrays - 将其内容向后复制到另一个数组的数组无法正常工作
- c - LZW序列实现
- sumo - 如何从 Webots 中的 Highway_overtake.py 访问 SUMO 车辆?
- java - 如何定义一个构造函数来为每个数组调用它?
- c# - AcquireTokenAsync 为图形客户端库中的用户凭据返回 401(未授权)
- amazon-web-services - AWS boto3 - 如何运行现货实例?
- sql - 我需要根据SSMS中相同条件的相同数据位置的19列返回行