4

I struggle to get the code coverage working for all tests in electron, that i wanne use for the gitlab coverage.

Situation
The tests are working and for each test-script I get a nice report.
Same on GitLab pipeline, when i push a commit.

Problem
I can't get a summary coverage report for all the test-scripts I execute.

I use Electron with a frontend which is in another repo.
electron-mocha, chai, sinon for the test and istanbul/nyc for the test-coverage.
Following this Setup TypeScript code coverage for Electron applications.

Test-Scripts
I have multiple test-scripts. One for the main- and two for the renderer process
and run them all with npm test

"coverage": "npm run test && nyc report",
"test": "npm run test-main && npm run test-renderer && npm run test-update-renderer",
"test-main": "electron-mocha --require ts-node/register,babel-register.js \"test/{main,hooks}/**/*.spec.ts\"",
"test-renderer": "electron-mocha --renderer --url src/html/shell.html --require ts-node/register,babel-register.js,src/scripts/preload/shell-preload.ts \"test/{renderer,hooks}/**/*.spec.ts\"",
"test-update-renderer": "electron-mocha --renderer --url src/html/update-dialog.html --require ts-node/register,babel-register.js \"test/{update-renderer,hooks}/**/*.spec.ts\"",

I also have more test-scripts for the pipeline.

.nycrc.json

{
    "all": true,
    "per-file": false,
    "check-coverage": true,
    "lines": 70,
    "skip-full": false,
    "extension": [".ts"],
    "include": "src/**/*.ts",
    "reporter": ["html", "text", "lcov", "cobertura"]
}

Output

---------------------|---------|----------|---------|---------|------------------------------------------------
File                 | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------------|---------|----------|---------|---------|------------------------------------------------
All files            |   69.94 |    21.28 |   44.68 |   69.94 |                                               
 src                 |   70.73 |     12.5 |   48.65 |   70.73 |                                               
  main.ts            |    54.9 |     3.57 |      40 |    54.9 | 40,51-56,62,75-81,90-91,98,103,112-113,124-127
  updater.ts         |   81.94 |       75 |   54.55 |   81.94 | 21,44,61-62,92,96,100,107-108,124-125,130-131 
 src/aws             |   29.41 |        0 |       0 |   29.41 |                                               
  signer.ts          |   29.41 |        0 |       0 |   29.41 | 8-44                                          
 src/environment     |     100 |      100 |     100 |     100 |                                               
  environment.ts     |     100 |      100 |     100 |     100 |                                               
 src/scripts/updater |    87.5 |    46.15 |      50 |    87.5 |                                               
  update-dialog.ts   |    87.5 |    46.15 |      50 |    87.5 | 14,20-28                                      
---------------------|---------|----------|---------|---------|------------------------------------------------

main.ts and updater.ts coverage comes from the tests of the electron main process and updater-dialog from the renderer process, which comes from the test scripts test-main and test-update-renderer

Unfortunately in script test-renderer there are two more test-files, which gets executed with green test results, but dont show up in the report.

I tried several things for over a week now but can't get it to work.
If you need more information, please do not hesitate to ask.

PxlCode
  • 51
  • 6

0 Answers0