kylemh / next-ts-with-cypress-coverage

An example create-next-app project using TypeScript, Cypress, @testing-library/cypress, and instrumented coverage
14 stars 9 forks source link

Does code coverage get bundled into production builds? #8

Closed coltonehrman closed 1 year ago

coltonehrman commented 1 year ago

Will the istanbul code coverage instrumented code get bundled for production and be part of a production build?

kylemh commented 1 year ago

It will show up in the server bundle since it's require()'d inside pages/api; however, there's no client entry point for any of the test code so it won't show up in the client-side bundle.

You can test this yourself with https://github.com/vercel/next.js/tree/canary/packages/next-bundle-analyzer

coltonehrman commented 1 year ago

It will show up in the server bundle since it's require()'d inside pages/api; however, there's no client entry point for any of the test code so it won't show up in the client-side bundle.

Does that mean that the production code getting deployed would be instrumented with code coverage lines? That would be a performance hit and not ideal.

kylemh commented 1 year ago

It would show up in the server bundle overall; however, I believe API routes are code-split by default with Next.js so only this specific route would include the dependency. Additionally, the instrumentation is for the UI code only. So, I don't see that it's possible for instrumentation code to be included anywhere in your actual application code.

coltonehrman commented 1 year ago

It would show up in the server bundle overall; however, I believe API routes are code-split by default with Next.js so only this specific route would include the dependency. Additionally, the instrumentation is for the UI code only. So, I don't see that it's possible for instrumentation code to be included anywhere in your actual application code.

Ah, so this does not instrument server-side code? So this won't allow me to collect coverage on the server?

kylemh commented 1 year ago

Correct. That's an open issue here: https://github.com/kylemh/next-ts-with-cypress-coverage/issues/3

If you find a solution, definitely let me know! It seems to be a limitation of @cypress/code-coverage