简体   繁体   English

NestJS 返回 404 页面以进行提供者契约验证测试

[英]NestJS returns 404 page for provider pact verification test

I have a NestJS v8.4.0 application.我有一个 NestJS v8.4.0 应用程序。 When I run provider verification test my application returns 404 “Cannot PUT url…”.当我运行提供商验证测试时,我的应用程序返回 404“Cannot PUT url...”。 If I copy-paste the URL into Postman and run the request myself it works as expected.如果我将 URL 复制粘贴到 Postman 并自己运行请求,它会按预期工作。

The questions are:问题是:

  1. Why does it return 404 error for pact initiated request but doesn't do so for the hand-made request with the same URL, headers, body?为什么它对协议发起的请求返回 404 错误,但对于具有相同 URL、标头、正文的手工请求却不返回 404 错误?
  2. How can I debug for NestJS/Express routes matching to see why it cannot match the route?我如何调试 NestJS/Express 路由匹配以查看它无法匹配路由的原因?

To do the hand-made request I remove server.close() so that I can make a request against the same environment.为了执行手动请求,我删除了server.close()以便我可以针对同一环境发出请求。 Environment is the same both for pact made requests and hand-mage.契约请求和手工法师的环境是相同的。 Compared to Jest tests pact tests doen't have any teardown.与 Jest 测试相比,pact 测试没有任何拆解。 Hence, all mocks I've made for pact tests are used for hand-made request as well.因此,我为契约测试制作的所有模拟也用于手工制作的请求。

Somehow the problem is in running pact verification tests with ts-node only and in this project only.不知何故,问题出在仅使用 ts-node 且仅在该项目中运行契约验证测试。 If used pure JS for pacts verification - it works.如果使用纯 JS 进行契约验证 - 它可以工作。 Can't explain it, but using JS fixed the issue无法解释,但是使用 JS 解决了这个问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM