Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Next.js - API handlers not covered in coverage report #27

Open
KATT opened this issue Jun 5, 2021 · 5 comments
Open

Next.js - API handlers not covered in coverage report #27

KATT opened this issue Jun 5, 2021 · 5 comments

Comments

@KATT
Copy link

KATT commented Jun 5, 2021

See/try PR #26 for more details

@KATT
Copy link
Author

KATT commented Jul 14, 2021

cc @ocavue @mxschmitt

Got any ideas for a workaround?

@mxschmitt
Copy link
Collaborator

As far as I know, these API handlers are executed on the server side of Next.js. The coverage example in this repository does only collect the frontend coverage via the istanbul plugin. But unsure, I'm not using Next.js that often.

@KATT
Copy link
Author

KATT commented Jul 14, 2021

I was thinking that the transpilation of the api fns would've gone through babel and hence istanbul as well, but maybe they have another transpilation model on the server.

@ocavue
Copy link
Contributor

ocavue commented Jul 14, 2021

If I'm not wrong, Next.js in fact use their own Babel plugin to separate browser-side code and server-side code from one JS file. I guess their Babel plugin is just not compatible with istanbul plugin. Since the server-side code is running on the NodeJS environment, maybe you can test it with separate jest test cases and use jest to collect the coverage information.

@KATT
Copy link
Author

KATT commented Jul 15, 2021

Yeah, it's of course possible to spin up the API and do integration tests against it, but it'd be better if I could just combine it into the same test suite.

I avoid unit tests as far as possible, having e2e tests collect coverage % would be a real eureka moment, then I could just focus on writing tests that are representing real-user behavior and use the cov to see weak spots in my tests / make unit/integration tests for extra hairy bits.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants