PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 26, 2022

[FIXED] How to start a gitlab pipeline job that fails when test coverage goes below a threshold

 September 26, 2022     continuous-deployment, continuous-integration, gitlab, gitlab-ci, jestjs     No comments   

Issue

We have jest unit testing for our react app and need to set a threshold value of 80% test case coverage. I know that we can get the coverage report in npm test -- --coverage --watchAll=false but I am now tasked with failing the pipeline if the coverage goes below 80%. I saw that there is a test pipeline stage which is commented right now. I have the following script, I need to somehow get the coverage, and compare if it is 80 or more else fail the pipleline, what should I do

test:
  stage: test
  image: node:16.13.1
  before_script:
    - npm i
    - npx node -v
    - npx npm -v
  script:
    - echo "running test coverage"
    - npm test -- --coverage --watchAll=false
  coverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'

Solution

Within your script section you should be able to use a Regex expression to retrieve the coverage value from the report.

Then you can use some bash scripting to remove the % sign from the output and compare the value with your required minimum. If the value is below, simply return false which I think gitlab should interpret as a failure.

If it’s above your minimum value return true and it should pass the job.



Answered By - quizguy
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing