Skip to content

Use istanbul for code coverage

Phyks requested to merge phyks/kresus:istanbul into master

I just came across Istanbul which seems to integrate seemlessly with mocha to produce code coverage statistics.

It outputs stuff like

------------------------------|----------|----------|----------|----------|----------------|
File                          |  % Stmts | % Branch |  % Funcs |  % Lines |Uncovered Lines |
------------------------------|----------|----------|----------|----------|----------------|
All files                     |    45.33 |    28.67 |    17.92 |    44.24 |                |
 client/components/duplicates |    49.71 |    14.81 |    25.93 |    45.64 |                |
  default-params-modal.js     |       32 |        0 |        0 |       32 |... 113,117,119 |
  index.js                    |    60.98 |    23.53 |    38.89 |     54.9 |... 124,127,130 |
  item.js                     |    14.81 |        0 |        0 |    18.18 |... 44,45,46,54 |
 client/store                 |    25.14 |    12.24 |     7.46 |    24.07 |                |
  categories.js               |    16.88 |        0 |        0 |    16.22 |... 207,208,209 |
  helpers.js                  |    53.33 |       75 |       40 |    59.09 |... 29,30,36,42 |
  operation-types.js          |       40 |      100 |        0 |    44.44 | 10,11,12,14,18 |
  ui.js                       |    18.97 |        0 |     4.17 |    17.54 |... 210,214,218 |
 server                       |       30 |    10.53 |    28.57 |    30.43 |                |
  index.js                    |       30 |    10.53 |    28.57 |    30.43 |... 100,104,111 |
 server/lib                   |     83.7 |    80.56 |      100 |    87.21 |                |
  diff-accounts.js            |      100 |      100 |      100 |      100 |                |
  logger.js                   |    54.55 |    41.67 |      100 |    60.71 |... 67,68,72,73 |
------------------------------|----------|----------|----------|----------|----------------|

after running the tests, see for instance in the output of the CI.

This is just really basic use of istanbul to decide whether it is worth it or not. In particular, it does not compute 0 coverage for files which are not used at the moment.

Gitlab can then use a regex to parse code coverage from the CI logs and output it. Not sure how useful it can be, but might be a new interesting metrics to have, to have more incentive to write tests.

Merge request reports

Loading