Search code examples
gitlabcode-coveragegitlab-ciflowtype

Get Gitlab CI coverage with flow coverage report


I'm using flow-coverage-report to get the coverage rate of my code by Flow. I've added a job in my Gitlab CI pipeline to execute it and retrieve the coverage rate.

jobName:
  stage: stage
  script:
    - ./node_modules/.bin/flow-coverage-report
  coverage: /MyProject\s*│\s*([\d\.]+)/

The output of the script is a lot of lines and more particularly :

┌───────────┬─────────┬───────┬─────────┬───────────┐
│ project   │ percent │ total │ covered │ uncovered │
│ MyProject │    87 % │ 62525 │   54996 │      7529 │
└───────────┴─────────┴───────┴─────────┴───────────┘

They are not using the pipe character | for the table, but │

When I debug the regex with Rubular as explained in the GitLab Documentation, I get the right result in the matching group.

However, every time my job finishes, it does not have any coverage value. Am I missing something ? Are the characters displayed differently ?

Note : I have no problems with Jest coverage for example.


Solution

  • Alright, after digging in the code and other places, I've found the culprit => colors in the output.

    The first line of the table above was actually displayed in green !

    So to have the correct value interpreted by the GitLab regex, one can include the colors in the regex or just strip the colors like I did :

    ./node_modules/.bin/flow-coverage-report | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g"
    

    Thanks to this answer.

    Hope it helps.