0

I have written a number of addon functions, and I make sure they are available. Now I want to test these functions by unit test, written by google-test, therefore I need to manually call these functions in c++. Therefore, I need to pass the Napi::CallbackInfo parameter when calling the functions. But I don't know how to construct Napi::CallbackInfo object.

The signature of the function I wrote is as follows: Napi::Value MyFunction(const Napi::CallbackInfo& info);

Botje
  • 26,269
  • 3
  • 31
  • 41
Robert
  • 31
  • 2
  • All of the test cases inside the node-addon-api repository are driven from node.js ([example](https://github.com/nodejs/node-addon-examples/tree/HEAD/2_function_arguments/node-addon-api)), is there a reason you cannot do the same? – Botje Aug 03 '21 at 12:47
  • Because I want to count the coverage of my c++ source code, so I can't call it from JS. Is there a method for counting the c++ coverage when the JS invokes addon. – Robert Aug 09 '21 at 08:55
  • I would think coverage is implemented by code instrumentation, so I think you can just run `node test.js` under whatever code coverage tool you want and it will generate the appropriate output? – Botje Aug 09 '21 at 09:48
  • I don't know how to coverage if I just run node test.js. Currently I use gtest to write some c++ unit test cases, and use OpenCppCoverage to generate code coverage reports. The OpenCppCoverage needs to run an executable file to analyze the code coverage. – Robert Aug 09 '21 at 15:38
  • So .. `OpenCppCoverage -- node test.js`, presumably with the `--sources` argument? – Botje Aug 09 '21 at 15:43
  • Thanks very much for providing me with another idea and it works. – Robert Aug 10 '21 at 02:22

0 Answers0