-
Notifications
You must be signed in to change notification settings - Fork 5
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
[Question]: does it support server side code coverage? #1
Comments
For current version, the coverage data is collected by Chromium Coverage API, so it works on chromium based browser. |
I followed the cypress approach for istanbul: 1) create an middleware endpoint in the backend; 2) when client side send request like 'GET localhost:3000/coverage, then return the json data, so far it works, maybe you can implement the similar solution for v8 as well. |
I've only gotten coverage on my client components for now (i.e. not RSC or Next.js route handlers). I was going to recommend the same thing -- the Cypress full stack code coverage approach is probably a good place to start. |
Thanks for the cypress example.
One thing that is different from the browser Chromium Coverage API is that you need to read the source code manually. |
Hey @cenfun, thanks for this! I updated my Next.js example project with the The client-side coverage is still working well: But it looks like the server-side coverage is erroneously reporting 100% coverage: I'm out of time today, but I'll try to keep exploring this over the next couple of weeks. |
@michaelhays Seems that |
Ooh okay got it. Thanks for the PR, I've tested it out and got the same results. I'll keep playing around with it to see if I can find anything else there! |
@michaelhays there is a playwright issue which causes Node.js can NOT generate coverage data with env I found a new option to collect the v8 coverage data, check the repo: https://github.com/cenfun/nextjs-with-playwright |
@michaelhays There have been some recent updates about the coverage report. |
Wow, great work @cenfun! I'm still having some trouble getting the server coverage to appear at all in my example project, not sure why. I'll continue playing around with it in the coming days. |
After made some changes, it seems like the coverage is finally being correctly obtained. 1, First, please update to new version [email protected], there is a bug has been fixed. - NODE_V8_COVERAGE=.coverage NODE_OPTIONS=--inspect npm run start
+ NODE_V8_COVERAGE=.coverage NODE_OPTIONS=--inspect npm run dev I don't know why
Note, please take coverage with - const res = await fetch("http://127.0.0.1:9229/json");
+ const res = await fetch("http://127.0.0.1:9230/json"); BTW, there is mistake in |
Incredible, that all worked 😭🙌 Yep, I'd previously changed the inspector port from 9230 to 9229 since You are an absolute machine, I seriously cannot thank you enough |
@michaelhays There is an optimization that connecting CDP, you can simply use the tool chrome-remote-interface. import CDP from 'chrome-remote-interface';
const client = await CDP({
port: 9230
});
await client.Runtime.enable();
const data = await client.Runtime.evaluate({
expression: 'new Promise(resolve=>{ require("v8").takeCoverage(); resolve(process.env.NODE_V8_COVERAGE); })',
includeCommandLineAPI: true,
returnByValue: true,
awaitPromise: true
});
await client.Runtime.disable();
await client.close();
const dir = data.result.value; example: https://github.com/cenfun/nextjs-with-playwright/blob/main/global-teardown.js |
Nice! That's working for me :) |
Nice job! @cenfun, I want to confirm that do you support istanbul for the server side coverage? Right now we still need the istanbul solution, thanks! |
@stevez It supports all Istanbul built-in reports.
|
@cenfun, thanks for your reply, my question is specifically for the Istanbul support on server side code coverage. Since I saw the above discussions and examples are all based on v8, I need some examples for the server side coverage using Istanbul. Thanks |
@stevez I create a example repo for istanbul: https://github.com/cenfun/nextjs-with-playwright-istanbul |
@cenfun, thanks for your example repo, I can run it in my local, thanks.
I wonder is this normal? Or I should use a different port, like 9229? Thanks |
By the way my node version is 18.17.1 |
By default the debugging port is
And for nextjs, We will get the prompt in the console:
This tell us we should use 9230 (9229+1) as the debugging port. It seems that nextjs has started two services. In fact you can use any port like
And also please update the port to
I believe Node 18 is working, but you could try upgrading to Node 20. |
@stevez I've made some further optimizations for the next.config: https://github.com/cenfun/nextjs-with-playwright-istanbul
That is, it enables the Babel compiler only during testing. |
@michaelhays I found my repo has the similar issues, the coverage is almost 100% just for a single playwright test, I wonder how did you fix it? we use custom sever side rendering using express, front end is react |
I wonder if this library supports server side code coverage.
Currently we have nextJS applications (including both client and server code), use playwright + nyc to capture the code coverage.
My question is if we use your library, does it support server side coverage as well? For both V8 and istanbul?
The text was updated successfully, but these errors were encountered: