{"id":26684569,"url":"https://github.com/bacebu4/cobertura","last_synced_at":"2025-04-12T15:05:42.544Z","repository":{"id":208106343,"uuid":"720805985","full_name":"bacebu4/cobertura","owner":"bacebu4","description":"A Cobertura reporter for `node:test`","archived":false,"fork":false,"pushed_at":"2024-12-27T06:03:34.000Z","size":39,"stargazers_count":9,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T15:04:36.755Z","etag":null,"topics":["cobertura","node-test","reporter"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bacebu4.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-19T16:54:47.000Z","updated_at":"2025-03-21T10:40:34.000Z","dependencies_parsed_at":"2023-11-19T19:27:30.230Z","dependency_job_id":"7f2da1d9-c522-45d2-82fa-5b4a0516e0ad","html_url":"https://github.com/bacebu4/cobertura","commit_stats":null,"previous_names":["bacebu4/cobertura"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bacebu4%2Fcobertura","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bacebu4%2Fcobertura/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bacebu4%2Fcobertura/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bacebu4%2Fcobertura/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bacebu4","download_url":"https://codeload.github.com/bacebu4/cobertura/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586237,"owners_count":21128997,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cobertura","node-test","reporter"],"created_at":"2025-03-26T09:32:09.905Z","updated_at":"2025-04-12T15:05:42.521Z","avatar_url":"https://github.com/bacebu4.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://img.shields.io/npm/v/cobertura)](https://www.npmjs.com/package/cobertura)\n![tests](https://github.com/bacebu4/cobertura/actions/workflows/test.yaml/badge.svg?branch=master)\n[![codecov](https://codecov.io/gh/bacebu4/cobertura/graph/badge.svg?token=JW6GTZWBSY)](https://codecov.io/gh/bacebu4/cobertura)\n\n# Cobertura Reporter\n\nA Cobertura reporter for `node:test`. Primarily was created in order to support GitLab's [Test coverage visualization](https://docs.gitlab.com/ee/ci/testing/test_coverage_visualization.html).\n\nAlso you can see the reporter in action in [this GitLab repo](https://gitlab.com/bacebu4/cobertura-test/-/merge_requests/1/diffs).\n\n## Installation\n\n```bash\nnpm install --save-dev cobertura\n```\n\nor\n\n```bash\nyarn add --dev cobertura\n```\n\n## Usage\n\nDefine your `test` script:\n\n```bash\nnode --test \\\n  --experimental-test-coverage \\\n  --test-reporter=cobertura --test-reporter-destination=cobertura.xml \\\n  --test-reporter=spec --test-reporter-destination=stdout\n```\n\nYour `.gitlab-ci.yml` can look something like this:\n\n```yml\nstages:\n  - test\n\ntest:\n  stage: test\n  image: node:22-alpine\n  artifacts:\n    when: always\n    reports:\n      coverage_report:\n        coverage_format: cobertura\n        path: ./cobertura.xml\n  script:\n    - node -v\n    - npm run test\n  coverage: '/all files[^|]*\\|[^|]*\\s+([\\d\\.]+)/'\n```\n\n## Supported Versions\n\nThe reporter can be used with **node v20 and later**, detailed explanation is [here](https://github.com/bacebu4/cobertura/issues/3#issuecomment-2370444363)\n\n## Acknowledgements\n\nThis test reporter is heavily inspired by test reporters of [this GitHub repo](https://github.com/MoLow/reporters) and some code parts might be directly copied from there.\n\n## Example\n\nSource file:\n\n```js\nexport function fooOne(x) {\n  if (x === 1) {\n    return x + 1;\n  }\n\n  if (x === 2) {\n    return x + 1;\n  }\n\n  const result = x + 1;\n\n  return result + 1;\n}\n```\n\nTest file:\n\n```js\nimport { describe, it } from 'node:test';\nimport assert from 'node:assert';\nimport { fooOne } from './foo.js';\n\ndescribe('fooTest', () =\u003e {\n  it('returns result', () =\u003e {\n    const result = fooOne(12);\n\n    assert.strictEqual(result, 14);\n  });\n\n  it('handles when x equals to 2', () =\u003e {\n    const result = fooOne(2);\n\n    assert.strictEqual(result, 3);\n  });\n});\n```\n\nOutput:\n\n```xml\n\u003c?xml version=\"1.0\" ?\u003e\n\u003c!DOCTYPE coverage SYSTEM \"http://cobertura.sourceforge.net/xml/coverage-04.dtd\"\u003e\n\u003ccoverage lines-valid=\"30\" lines-covered=\"28\" line-rate=\"0.9333\" branches-valid=\"8\" branches-covered=\"7\" branch-rate=\"0.8750\" timestamp=\"1700416562185\" complexity=\"0\" version=\"0.1\"\u003e\n\t\u003csources \u003e\n\t\t\u003csource \u003e\n/Users/bacebu4/dev/cobertura-test\n\t\t\u003c/source\u003e\n\t\u003c/sources\u003e\n\t\u003cpackages \u003e\n\t\t\u003cpackage name=\"cobertura-test.src\" line-rate=\"0.9333\" branch-rate=\"0.8750\"\u003e\n\t\t\t\u003cclass name=\"foo.js\" filename=\"src/foo.js\" line-rate=\"0.8462\" branch-rate=\"0.7500\"\u003e\n\t\t\t\t\u003cmethods \u003e\n\t\t\t\t\t\u003cmethod name=\"fooOne\" hits=\"2\" signature=\"()V\"\u003e\n\t\t\t\t\t\t\u003clines \u003e\n\t\t\t\t\t\t\t\u003cline number=\"1\" hits=\"2\"/\u003e\n\t\t\t\t\t\t\u003c/lines\u003e\n\t\t\t\t\t\u003c/method\u003e\n\t\t\t\t\u003c/methods\u003e\n\t\t\t\t\u003clines \u003e\n\t\t\t\t\t\u003cline number=\"1\" hits=\"1\" branch=\"true\" condition-coverage=\"100% (2/2)\"/\u003e\n\t\t\t\t\t\u003cline number=\"2\" hits=\"2\" branch=\"true\" condition-coverage=\"0% (0/1)\"/\u003e\n\t\t\t\t\t\u003cline number=\"3\" hits=\"0\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"4\" hits=\"0\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"5\" hits=\"2\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"6\" hits=\"2\" branch=\"true\" condition-coverage=\"100% (1/1)\"/\u003e\n\t\t\t\t\t\u003cline number=\"7\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"8\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"9\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"10\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"11\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"12\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"13\" hits=\"2\" branch=\"false\"/\u003e\n\t\t\t\t\u003c/lines\u003e\n\t\t\t\u003c/class\u003e\n\t\t\t\u003cclass name=\"foo.test.js\" filename=\"src/foo.test.js\" line-rate=\"1.0000\" branch-rate=\"1.0000\"\u003e\n\t\t\t\t\u003cmethods \u003e\n\t\t\t\t\t\u003cmethod name=\"(anonymous_0)\" hits=\"1\" signature=\"()V\"\u003e\n\t\t\t\t\t\t\u003clines \u003e\n\t\t\t\t\t\t\t\u003cline number=\"5\" hits=\"1\"/\u003e\n\t\t\t\t\t\t\u003c/lines\u003e\n\t\t\t\t\t\u003c/method\u003e\n\t\t\t\t\t\u003cmethod name=\"(anonymous_1)\" hits=\"1\" signature=\"()V\"\u003e\n\t\t\t\t\t\t\u003clines \u003e\n\t\t\t\t\t\t\t\u003cline number=\"6\" hits=\"1\"/\u003e\n\t\t\t\t\t\t\u003c/lines\u003e\n\t\t\t\t\t\u003c/method\u003e\n\t\t\t\t\t\u003cmethod name=\"(anonymous_2)\" hits=\"1\" signature=\"()V\"\u003e\n\t\t\t\t\t\t\u003clines \u003e\n\t\t\t\t\t\t\t\u003cline number=\"12\" hits=\"1\"/\u003e\n\t\t\t\t\t\t\u003c/lines\u003e\n\t\t\t\t\t\u003c/method\u003e\n\t\t\t\t\u003c/methods\u003e\n\t\t\t\t\u003clines \u003e\n\t\t\t\t\t\u003cline number=\"1\" hits=\"1\" branch=\"true\" condition-coverage=\"100% (1/1)\"/\u003e\n\t\t\t\t\t\u003cline number=\"2\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"3\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"4\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"5\" hits=\"1\" branch=\"true\" condition-coverage=\"100% (1/1)\"/\u003e\n\t\t\t\t\t\u003cline number=\"6\" hits=\"1\" branch=\"true\" condition-coverage=\"100% (1/1)\"/\u003e\n\t\t\t\t\t\u003cline number=\"7\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"8\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"9\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"10\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"11\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"12\" hits=\"1\" branch=\"true\" condition-coverage=\"100% (1/1)\"/\u003e\n\t\t\t\t\t\u003cline number=\"13\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"14\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"15\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"16\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\t\u003cline number=\"17\" hits=\"1\" branch=\"false\"/\u003e\n\t\t\t\t\u003c/lines\u003e\n\t\t\t\u003c/class\u003e\n\t\t\u003c/package\u003e\n\t\u003c/packages\u003e\n\u003c/coverage\u003e\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbacebu4%2Fcobertura","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbacebu4%2Fcobertura","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbacebu4%2Fcobertura/lists"}