I am trying to set up coverage for unit tests that run in a docker container. However, the coverage reports fail generating as expected inside the container. But, they succeed generating when the command is run outside the container (on Mac OSX and CentOS).
I mount my codebase to a pre-existing path in the image.
The image is based on node:8.11.4
karma v3.1.4
karma-coverage v1.1.2
karma-coverage-istanbul-reporter v2.0.4
karma-webpack v4.0.0-rc.5
istanbul-instrumenter-loader v.3.0.1 .
Attempts to tease out the issue:
__dirname in karma.conf.jspath.join in karma.conf.js and entry points used by webpack.coverage and istanbul-coverage reporters.-u $(id -u):$(id -g) doesn't make a differenceWhat code would you like to see?
docker run --privileged \
-u $(id -u):$(id -g) \
--mount type=bind,source=$(pwd),dst=/home/node/test/ \
-it $DOCKER_IMAGE \
/bin/bash -c "npm test"
Expected:
=============================== Coverage summary ===============================
Statements : 22.71% ( 7684/33837 )
Branches : 15.17% ( 2887/19027 )
Functions : 21.85% ( 1384/6334 )
Lines : 21.45% ( 6719/31327 )
================================================================================
Actual:
17:40:18 =============================== Coverage summary ===============================
17:40:18 Statements : Unknown% ( 0/0 )
17:40:18 Branches : Unknown% ( 0/0 )
17:40:18 Functions : Unknown% ( 0/0 )
17:40:18 Lines : Unknown% ( 0/0 )
17:40:18 ================================================================================
what worked for me in Angular app - you run in your CLI ng test --code-coverage it magically shows the coverage