mtbrault / nextjs-http-supertest

npm package to get an http server parsing your nextJS app to link endpoint with handler
14 stars 5 forks source link

fix: consider pageExtesions when running the package #18

Closed heldaolima closed 2 months ago

heldaolima commented 3 months ago

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:

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.

mtbrault commented 2 months ago

Thanks for your contribution @heldaolima. Your changes are available in the version 1.0.14 of the npm package