-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specmatic Coverage reporting invalid routes when running on Latest version of Express. #1287
Comments
Hi, @barath121 thanks for sharing this. |
@pranavgawri Any update on this? |
Hi @barath121 , Thanks for your patience. We upgraded one of our sample projects to use express server 4.21.0, here is the package.json FYR and we are not able to see any additional routes in our API coverage report. Here is the link to our CI log. Can you please take a look and let us know if we are missing anything? |
@pranavgawri I checked the CI log and after further debugging seems like the the coverage is skipping parts of URL. I cloned your order-bff and added a small code snippet to Product router code. const testRouter = express.Router();
testRouter.get(
"/findAvailableProducts",
validate({ query: productTypeSchema }),
asyncErrorHandler(async (req, res) => {
const pageSize = req.get("pageSize");
if (!pageSize) {
throw ApiError.BadRequest("pageSize is required in Headers");
}
if (Number.isNaN(Number.parseInt(pageSize))) {
throw ApiError.BadRequest("pageSize must be a number");
}
if (req.query.type === "other" || pageSize > 20) {
throw ApiError.TimeoutError("Product type was other");
}
const products = await ProductService.searchProducts(req.query.type);
return res.status(200).json(products);
})
);
testRouter.post(
"/products",
validate({ body: productSchema }),
asyncErrorHandler(async (req, res) => {
const newProduct = await ProductService.createProduct(req.body);
return res.status(201).json(newProduct);
})
);
router.use("/v1.0/test/:param1/test/:param2/test",testRouter); This should ideally add 2 routes to the coverage
But this is the coverage table: |-------------------------------------------------------------------------------------------|
| SPECMATIC API COVERAGE SUMMARY |
|-------------------------------------------------------------------------------------------|
| coverage | path | method | response | #exercised | result |
|----------|-----------------------------|--------|----------|------------|-----------------|
| 100% | /findAvailableProducts | GET | 200 | 2 | covered |
| | | | 400 | 2 | covered |
| | | | 503 | 1 | covered |
| 80% | /orders | GET | 200 | 2 | WIP |
| | | | 400 | 2 | WIP |
| | | POST | 201 | 1 | covered |
| | | | 400 | 6 | covered |
| | | | 503 | 0 | not covered |
| 67% | /products | POST | 201 | 12 | covered |
| | | | 400 | 65 | covered |
| | | | 503 | 0 | not covered |
| 0% | /v1.0/findAvailableProducts | GET | 0 | 0 | missing in spec |
| 0% | /v1.0/products | POST | 0 | 0 | missing in spec |
|-------------------------------------------------------------------------------------------|
| 69% API Coverage reported from 5 Paths |
|-------------------------------------------------------------------------------------------| Here as you can see the routes are
Can you please check once again. |
Thanks @barath121 for the details. We have been able to narrow down the issue to library which we were using to enumerate routes which has not been kept up to date with Express 4.20.0 and later approach for compiling route pattern into regular expressions. We have tried following up with the library. However since we have not heard back, we will fix this ourselves and rollout a release of Specmatic also with the update version to fix this. We will keep you posted on the same. |
Description
When running specmatic on express v4.20.0 random routes which are not present in app are shown in coverage with remarks as missing in spec it works for v4.19.2.
Steps to reproduce
Expected behavior
The extra routes should not be displayed
System Information:
The text was updated successfully, but these errors were encountered: