{"id":22423404,"url":"https://github.com/prantlf/c8-ethernal-100","last_synced_at":"2025-03-27T05:40:56.302Z","repository":{"id":150431618,"uuid":"622506607","full_name":"prantlf/c8-ethernal-100","owner":"prantlf","description":"Demonstrates how all coverage stats computed by c8 remain 100 if excludeAfterRemap is set to true.","archived":false,"fork":false,"pushed_at":"2023-04-02T10:24:43.000Z","size":1118,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T10:43:01.978Z","etag":null,"topics":["bug","c8","coverage"],"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/prantlf.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-04-02T10:20:48.000Z","updated_at":"2023-04-02T10:23:07.000Z","dependencies_parsed_at":"2023-05-18T00:45:37.986Z","dependency_job_id":null,"html_url":"https://github.com/prantlf/c8-ethernal-100","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fc8-ethernal-100","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fc8-ethernal-100/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fc8-ethernal-100/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prantlf%2Fc8-ethernal-100/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prantlf","download_url":"https://codeload.github.com/prantlf/c8-ethernal-100/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245791899,"owners_count":20672668,"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":["bug","c8","coverage"],"created_at":"2024-12-05T18:11:16.985Z","updated_at":"2025-03-27T05:40:56.284Z","avatar_url":"https://github.com/prantlf.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# C8 - Ethernal 100 Coverage\n\nDemonstrates how all coverage stats computed by [c8] remain 100 if excludeAfterRemap is set to true. Contains files from the [original project], which need only [c8] to test.\n\nHow to test it:\n\n    # install dependencies and prepare coverage/tmp/out.json\n    npm ci\n    # run report with no exclusions\n    npx c8 report\n    # run report excluding src/codejar and src/prism\n    npm c8 report -a\n\n`npx c8 report` reveals an incomplete coverage in `script-editor.js`, among other files:\n\n    File                | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s\n    --------------------|---------|----------|---------|---------|-------------------\n      script-editor.js  |   96.84 |      100 |     100 |   96.84 | 71-76\n      ...\n\n`npm c8 report -a` excludes other files with missing coverage, but the remaining `script-editor.js` is reported with the complete coverage:\n\n    File                | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s\n    --------------------|---------|----------|---------|---------|-------------------\n      script-editor.js  |     100 |      100 |     100 |     100 |\n      ...\n\n## Project Description\n\nThis project demonstrates computing the test code coverage only for a part of sources. The source files are located in the `src` directory:\n\n    src\n    ├── bundled-engine.js\n    ├── codejar\n    │   └── codejar.js\n    ├── graph.js\n    ├── index.js\n    ├── prism\n    │   ├── prism-core.js\n    │   ├── prism-graphviz.js\n    │   ├── prism-line-highlight.js\n    │   ├── prism-line-numbers.js\n    │   └── prism-match-braces.js\n    ├── renderer.js\n    ├── script-editor.js\n    └── separate-engine.js\n\nThe minified bundles with source maps are located in the `dist` directory:\n\n    dist\n    ├── index-bundled.min.js\n    ├── index-bundled.min.js.map\n    ├── index.min.js\n    ├── index.min.js.map\n    ├── renderer.min.js\n    └── renderer.min.js.map\n\nThe minified bundles refer to their source maps on their last line, for example, from `index.min.js`:\n\n    //# sourceMappingURL=index.min.js.map\n\nThe source map files include relative source file paths from `dist` to `src`, for example: `../src/graph.js`.\n\nThe text code coverage produced using [Puppeteer Coverage API] is saved in `data/out.json`, where the absolute paths to the project root are replaced with `$$$CWD$$$`. The script `data/prepare.js`, which is executed during the `prepare` phase of `npm ci`, reads the JSON file, replaces the `$$$CWD$$$` strings with the absolute path to the current project root and writes the result to `converage/tmp/out.json`. This simulates the state after collecting the test coverage in the original project.\n\nThe [original project] can be used to demonstrate the problem too:\n\n    git clone https://github.com/prantlf/graphviz-webcomponent.git\n    cd graphviz-webcomponent\n    git checkout c8-ethernal-100-coverage\n    npm i -g pnpm\n    pnpm i\n    npm test\n    npx c8 report -a\n\n## Test with No Exclusions\n\nThe exclusions from package.json do not apply, because they do not match the paths to the bundles loaded by the test pages:\n\n    \"c8\": {\n      \"exclude\": [\n        \"src/codejar\",\n        \"src/prism\"\n      ],\n      ...\n    }\n\nThe report includes all files, as expected:\n\n    ❯ npx c8 report\n    -------------------------------------------------|---------|----------|---------|---------|-------------------\n    File                                             | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s\n    -------------------------------------------------|---------|----------|---------|---------|-------------------\n    All files                                        |   90.74 |    67.85 |   47.46 |   90.74 |\n     ...s+wasm@2.8.0/node_modules/@hpcc-js/wasm/dist |     100 |    59.16 |   40.68 |     100 |\n      graphviz.js                                    |     100 |    59.16 |   40.68 |     100 | 1\n     src                                             |    98.4 |      100 |     100 |    98.4 |\n      bundled-engine.js                              |     100 |      100 |     100 |     100 |\n      graph.js                                       |     100 |      100 |     100 |     100 |\n      renderer.js                                    |     100 |      100 |     100 |     100 |\n      script-editor.js                               |   96.84 |      100 |     100 |   96.84 | 71-76\n      separate-engine.js                             |     100 |      100 |     100 |     100 |\n     src/codejar                                     |     100 |       70 |      30 |     100 |\n      codejar.js                                     |     100 |       70 |      30 |     100 | 4-17\n     src/prism                                       |   83.56 |    78.72 |   59.25 |   83.56 |\n      prism-core.js                                  |   78.75 |    73.13 |   68.42 |   78.75 | ...48-252,322-325\n      prism-graphviz.js                              |     100 |      100 |     100 |     100 |\n      prism-line-numbers.js                          |   98.19 |    86.66 |      75 |   98.19 | 147-149\n      prism-match-braces.js                          |   82.58 |      100 |       0 |   82.58 | ...53,57-61,65-75\n    -------------------------------------------------|---------|----------|---------|---------|-------------------\n    ERROR: Coverage for lines (90.74%) does not meet global threshold (100%)\n    ERROR: Coverage for functions (47.46%) does not meet global threshold (100%)\n    ERROR: Coverage for branches (67.85%) does not meet global threshold (100%)\n    ERROR: Coverage for statements (90.74%) does not meet global threshold (100%)\n\nNote the following line:\n\n      script-editor.js                               |   96.84 |      100 |     100 |   96.84 | 71-76\n\n\n## Test with Exclusions\n\nThe exclusions from package.json do apply, because the `-a` command-line argument makes `c8` match the excluded paths to sources from the source maps, as if `excludeAfterRemap` was set to `true` in `package.json`:\n\n    \"c8\": {\n      \"excludeAfterRemap\": true,\n      \"exclude\": [\n        \"src/codejar\",\n        \"src/prism\"\n      ],\n      ...\n    }\n\nThe report doesn't include excluded files, as expected, but the code coverage of the remaining files is always 100, also for files, have obviously less code coverages, as tested by disabling the exclusions:\n\n    ❯ npx c8 report -a\n    --------------------|---------|----------|---------|---------|-------------------\n    File                | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s\n    --------------------|---------|----------|---------|---------|-------------------\n    All files           |     100 |      100 |     100 |     100 |\n     bundled-engine.js  |     100 |      100 |     100 |     100 |\n     graph.js           |     100 |      100 |     100 |     100 |\n     renderer.js        |     100 |      100 |     100 |     100 |\n     script-editor.js   |     100 |      100 |     100 |     100 |\n     separate-engine.js |     100 |      100 |     100 |     100 |\n    --------------------|---------|----------|---------|---------|-------------------\n\nNote the following line:\n\n     script-editor.js   |     100 |      100 |     100 |     100 |\n\n## License\n\nCopyright (c) 2023 Ferdinand Prantl\n\nLicensed under the MIT license.\n\n[original project]: https://github.com/prantlf/graphviz-webcomponent\n[c8]: https://github.com/bcoe/c8\n[Puppeteer Coverage API]: https://pptr.dev/api/puppeteer.coverage\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fc8-ethernal-100","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprantlf%2Fc8-ethernal-100","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprantlf%2Fc8-ethernal-100/lists"}