Files
shields/services/gitlab/gitlab-coverage.tester.js
Hrishikesh Patil 1e6acc830b [GitlabCoverage] Add badge for code coverage (#5262)
* Add base for GitLab code coverage badge

* Change examples to repos which have implemented code coverage reporting
in GitLab UI

* Add tests for Gitlab Coverage badge

* Fix test data that was not changed

* Update code according to new branch detection

Signed-off-by: Hrishikesh Patil <hrishikeshpatil.754@gmail.com>

* Update docs and examples, make branch required option that was missed in
previous commit

Signed-off-by: Hrishikesh Patil <hrishikeshpatil.754@gmail.com>

* Apply suggestions from PR discussion

Signed-off-by: Hrishikesh Patil <hrishikeshpatil.754@gmail.com>

* Remove default value of branch param

Signed-off-by: Hrishikesh Patil <hrishikeshpatil.754@gmail.com>

* Apply further discussed changes to service

Signed-off-by: Hrishikesh Patil <hrishikeshpatil.754@gmail.com>

* Fix tests that were failing

Signed-off-by: Hrishikesh Patil <hrishikeshpatil.754@gmail.com>

* Add fetch and transform functions

Signed-off-by: Hrishikesh Patil <hrishikeshpatil.754@gmail.com>

* Add examples and tests for custom job name

Signed-off-by: Hrishikesh Patil <hrishikeshpatil.754@gmail.com>

* Add finishing touches

Signed-off-by: Hrishikesh Patil <hrishikeshpatil.754@gmail.com>

* Change to a working example

Signed-off-by: Hrishikesh Patil <hrishikeshpatil.754@gmail.com>

Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
2020-08-07 00:15:47 +00:00

65 lines
1.6 KiB
JavaScript

'use strict'
const { isIntegerPercentage } = require('../test-validators')
const t = (module.exports = require('../tester').createServiceTester())
t.create('Coverage (branch)')
.get('/gitlab-org/gitlab-runner/12-0-stable.json')
.expectBadge({
label: 'coverage',
message: isIntegerPercentage,
})
t.create('Coverage (existent branch but coverage not set up)')
.get('/gitlab-org/gitlab-git-http-server/master.json')
.expectBadge({
label: 'coverage',
message: 'not set up',
})
t.create('Coverage (nonexistent branch)')
.get('/gitlab-org/gitlab-runner/nope-not-a-branch.json')
.expectBadge({
label: 'coverage',
message: 'not set up',
})
t.create('Coverage (nonexistent repo)')
.get('/this-repo/does-not-exist/neither-branch.json')
.expectBadge({
label: 'coverage',
message: 'inaccessible',
})
t.create('Coverage (custom job)')
.get(
'/gitlab-org/gitlab-runner/12-0-stable.json?job_name=test coverage report'
)
.expectBadge({
label: 'coverage',
message: isIntegerPercentage,
})
t.create('Coverage (custom invalid job)')
.get('/gitlab-org/gitlab-runner/12-0-stable.json?job_name=i dont exist')
.expectBadge({
label: 'coverage',
message: 'not set up',
})
t.create('Coverage (custom gitlab URL)')
.get('/GNOME/libhandy/master.json?gitlab_url=https://gitlab.gnome.org')
.expectBadge({
label: 'coverage',
message: isIntegerPercentage,
})
t.create('Coverage (custom gitlab URL and job)')
.get(
'/GNOME/libhandy/master.json?gitlab_url=https://gitlab.gnome.org&job_name=unit-test'
)
.expectBadge({
label: 'coverage',
message: isIntegerPercentage,
})