-
Notifications
You must be signed in to change notification settings - Fork 109
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
Server-side coverage not reported when using next.js #557
Comments
Were running into this issue as well with a project which uses SSG and CSR. Any code that is run as part of the build to generate the pages is not producing coverage information. This is also true when using the dev server as illustrated in the example by @romandecker which directly impacts our ability to gather coverage for our project through our current build pipeline. Thinking this through, server side code runs at build time with SSG or at runtime with SSR would need to generate coverage data and either make it available in a separate file output or it would need to be tacked into the client side coverage data as soon as the page loads. Has there been any thoughts on which of these approaches would be appropriate or even feasible? Getting this to work for the dev server would be useful too and happens to be the way that we are collecting coverage data currently in our build pipeline through CypressJS. My only workaround that I can think of for now is to disable coverage for all code that runs through SSG or SSR but identifying all of this code is not as simple as looking at a simple file name pattern or location of the code because of how code organized in a Next.js project with server side and client side code comingled and somewhat dynamically determined depending on the specific runtime scenario (ex. dev server vs. production build using export). We're currently generated coverage using the swc-plugin-coverage-instrument plugin instead of babel in order to keep our test builds closer to our production builds. |
Is this perhaps a nextjs limitation? I opened a feature request for a integration between nyc and nextjs here: vercel/next.js#70713 |
Proof of concept repository: https://github.com/romandecker/next-ts-with-cypress-coverage
Steps to reproduce:
npm install
npm run dev
DEBUG=code-coverage npm run cypress run
npm run see-cy-coverage
and verify thatgetServerSideProps()
inpages/index.tsx
was called and coverage was tracked successfully, but the function it calls, inno-coverage-here/some-file.ts
still shows up as having 0% coverage, even though it was clearly executed.Logs and screenshots
Versions
window.__coverage__
object? yes.nyc_output
folder? Is there.nyc_output/out.json
file. Is it empty? Can you paste at least part of it so we can see the keys and file paths? yes, it just doesn't cover certainly included filesDescribe the bug
Coverage is being measured correctly, but ONLY for the
pages
folder. Anything outside the pages folder (e.g.no-coverage-here
) always remains uncovered, despite being called.Link to the repo
https://github.com/romandecker/next-ts-with-cypress-coverage
Originally found this issue here: kylemh/next-ts-with-cypress-coverage#3
The text was updated successfully, but these errors were encountered: