question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to generate report for active node server?

See original GitHub issue
  • Version: 16.18.0
  • Platform: Ubuntu 20.04 x86_64 GNU/Linux

Hi, I want to use c8 for checking code coverage for my typescript based node server. My use case is:

  1. Frontend will have test scripts which will try to cover maximum APIs.
  2. We want to start server in usual way along with c8, with command similar to c8 node --loader ts-node/esm app.ts.
  3. Now when the frontend tests gets completed, I want to somehow generate the code coverage reports for the server.

Issue: Right now from what I have read till now, I need to gracefully exit the server using process.exit(0) post which c8 generates the report. But for doing this, it would require to exposing an API which calls process.exit(). This temporary solution works but it doesn’t seem to be ideal way. I tried using kill {PID} commands and usual CTRL + C to end the server but none of them works. Am I missing something or is there any better way to generate report?

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
cion-yatindracommented, Dec 22, 2022

Hi @olivierodo , For my node server, i created an api as

import v8 from 'v8';

.... server setup ...
 const app = express(); 
app.post('/coverage', async (req, res)=>{
        ... some authentication here or in middleware ....
        v8.takeCoverage();
        v8.stopCoverage();
        res.sendStatus(200);
} );

Run server as c8 node app.js. Then start testing from frontend (my use case). Call this /coverage api at end of testing directly from frontend. In server terminal, run c8 report.

After calling this API, the v8 code coverage JSON is generated at directories mentioned in c8 config.

Let me know if you need more details.

1reaction
olivierodocommented, Dec 17, 2022

@cion-yatindra There is multiple issue related to the same topic, actually the issue is not coming from c8, its coming from how nodejs manage the flag NODE_V8_COVERAGE , you can refer to this issue: https://github.com/nodejs/node/issues/29896

Now related to your use case what i would suggest is to use c8 programmatically and build a test launcher that will spin up your server through a child process. Then when your tests are finished you can send a kill signal to your app running in the child process that would then close your server gracefully. I’ll be happy to share in detail how to do if you want to 😁.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GENERATE A REPORT WHICH TELLS YOU NODE AND ...
Report Lab GENERATE A REPORT WHICH TELLS YOU NODE AND ALERT(NAME AND MESSAGE) CONFIGURED FOR ALL NODE : NOTE REPORT SHOULD NOT INCLUDE...
Read more >
Using Node.js for Reporting - SparkPost
In this post I'll demonstrate how we use SparkPost to build an email report. We're going to build what we refer to as...
Read more >
JavaScript Report Designer | ActiveReportsJS - YouTube
Build scalable reporting applications with ActiveReportsJS. The ActiveReportsJS Designer is a desktop app for creating and modifying reports ...
Read more >
Debugging NodeJS in Production with Diagnostic Reports
Diagnostic Reports are a recent addition to Node. js core. This feature enables insight into Node. js processes running in production—without ...
Read more >
report-toolkit for Node.js – report-toolkit Quick Start
Install · Generate a Diagnostic Report · Redact Secrets From a Report · Compare Two Reports · Detect Problems within a Report ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found