nyc icon indicating copy to clipboard operation
nyc copied to clipboard

How to instrument code for Electron app?

Open MMcKester opened this issue 3 years ago • 3 comments

Hi,

I am very sorry if this is actually not a bug, but I don't know any support channel and I am lost on this at the moment.

I wrote an Electron app, and setup a few tests with ava which start my app, trigger a few functions and terminate the application. nyc put on top only covers the executions from the Main Process.

As far as I understand, this is caused because nyc doesn't reach down to the browser context. Is there any way to build my entire Electron application with instrumented code, so I can still create a coverage report?

Here are a few snippets from my package.json:

"scripts": {
    "build": "npm run electron:serve-tsc && ng build --base-href ./",
    "ava-ts": "env NODE_ENV=ava ava-ts --serial",
},

  "ava-ts": {
    "cache": false,
    "serial": true,
    "verbose": true,
    "timeout": 10000,
    "instrument": true
  },

Any help is highly appreciated! Thank you!

MMcKester avatar Oct 29 '20 01:10 MMcKester

Hi, is there any chance for support on this? Any help is appreciated! Thank you!

MMcKester avatar Nov 07 '20 06:11 MMcKester

You likely need to use babel-plugin-istanbul, though I don't have any specific instructions for doing this in electron or under ava-ts. This is a somewhat advanced topic which I don't have the knowledge to support.

coreyfarrell avatar Nov 20 '20 15:11 coreyfarrell

@MMcKester, I wrote an article on how to setup TypeScript code coverage for Electron applications. Hope it helps you! 🍀

bennycode avatar Oct 17 '21 17:10 bennycode