In Next.js, you can define the possible extensions for the pages with the pageExtensions property of the next.config.js file. This was not taken into consideration for the nextjs-http-supertest package.
For instance, suppose a project has page.ts as one of the possible extensions. For any file in the pages directory like[route_name].page.ts, Next will create a route /[route_name], but we cannot use the route's name when testing. Instead, it would be necessary to do something like this:
Since the permitted page extensions may vary from project to project, and since it is more readable to test with the route's actual name, I changed the package's code to consider the pageExtensions property when parsing the file tree. With the changes, we can write tests without worrying about the file extensions, but only with the routes' names.
In Next.js, you can define the possible extensions for the pages with the
pageExtensions
property of thenext.config.js
file. This was not taken into consideration for thenextjs-http-supertest
package.For instance, suppose a project has
page.ts
as one of the possible extensions. For any file in thepages
directory like[route_name].page.ts
, Next will create a route/[route_name]
, but we cannot use the route's name when testing. Instead, it would be necessary to do something like this:const response = await supertest(server).get("/[route_name].page")
Since the permitted page extensions may vary from project to project, and since it is more readable to test with the route's actual name, I changed the package's code to consider the
pageExtensions
property when parsing the file tree. With the changes, we can write tests without worrying about the file extensions, but only with the routes' names.