Test coverage regex does not work when output has color
I'm using jest
for testing javascript stuff and my .gitlab-ci.yml
roughly looks like this:
image: node:7
qa:
stage: qa
cache:
paths:
- node_modules
script:
- npm install
- npm run test
coverage: /All files\s*\|\s*([\d\.]+)/
When my test script does not have any color (cross-env NODE_ENV=test jest --coverage
), the coverage report is picked up correctly.
GitLab UI says: Test coverage 3.4%
.
However, when I introduce color in the output (cross-env NODE_ENV=test jest --color --coverage
), the regexp is no longer matched.
No text related to coverage appears in GitLab UI.
Seems like the color control characters do not let the regexp to work correctly. Would it be possible to remove them from the raw output before attempting to match?
I know that it is possible to do this manually too, but this is far more difficult. In particular, for Jest one would have to consider three cases when the search text is red, yellow and green plus one case when there is no color at all. This feels counter-intuitive and very hard to test locally.