{"id":51031793,"url":"https://github.com/fmguerreiro/vitest-coverage-per-test","last_synced_at":"2026-06-22T01:01:46.682Z","repository":{"id":356693097,"uuid":"1232799597","full_name":"fmguerreiro/vitest-coverage-per-test","owner":"fmguerreiro","description":"Vitest reporter that emits per-test runtime coverage attribution as JSON","archived":false,"fork":false,"pushed_at":"2026-05-25T02:09:03.000Z","size":70,"stargazers_count":0,"open_issues_count":5,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-25T02:23:28.318Z","etag":null,"topics":["code-coverage","coverage","javascript","reporter","test-coverage","testing","typescript","vitest","vitest-plugin"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/fmguerreiro.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-08T09:31:16.000Z","updated_at":"2026-05-25T00:25:55.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/fmguerreiro/vitest-coverage-per-test","commit_stats":null,"previous_names":["fmguerreiro/vitest-coverage-per-test"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fmguerreiro/vitest-coverage-per-test","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmguerreiro%2Fvitest-coverage-per-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmguerreiro%2Fvitest-coverage-per-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmguerreiro%2Fvitest-coverage-per-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmguerreiro%2Fvitest-coverage-per-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fmguerreiro","download_url":"https://codeload.github.com/fmguerreiro/vitest-coverage-per-test/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fmguerreiro%2Fvitest-coverage-per-test/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34630753,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-21T02:00:05.568Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["code-coverage","coverage","javascript","reporter","test-coverage","testing","typescript","vitest","vitest-plugin"],"created_at":"2026-06-22T01:01:45.755Z","updated_at":"2026-06-22T01:01:46.676Z","avatar_url":"https://github.com/fmguerreiro.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vitest-coverage-per-test\n\nVitest reporter that emits per-test runtime coverage attribution as JSON. Each test file gets mapped to the set of source files it actually exercised at runtime.\n\nVitest's built-in v8 reporter merges per-test coverage into a single aggregate `coverage-final.json` before any reporter sees it. This package snapshots V8 coverage between tests via `node:v8`'s `takeCoverage()` and writes a per-test breakdown.\n\n## Why\n\nStatic analyzers like [tdad-ts](https://github.com/fmguerreiro/tdad-ts) and similar test-impact tools need per-test coverage to flag tests at risk when a source file changes through dynamic dispatch, registry lookups, or routing — paths that static `import` traversal misses. Aggregate coverage doesn't tell you *which* test exercised the source.\n\n## Output shape\n\n```json\n{\n  \"version\": 1,\n  \"tests\": {\n    \"tests/foo.spec.ts\": [\"src/used.ts\", \"src/other.ts\"],\n    \"tests/bar.spec.ts\": [\"src/lib/helper.ts\"]\n  }\n}\n```\n\nPaths are project-relative, forward-slash. Each value is the deduped set of source files covered while that test file ran.\n\n## Status\n\nPre-release. Single reporter, V8 provider only (`@vitest/coverage-v8`). Istanbul provider not supported.\n\n## Install (github pin)\n\n```bash\nnpm install --save-dev \"github:fmguerreiro/vitest-coverage-per-test#\u003csha\u003e\"\n```\n\nThe package builds its `dist/` on install via the `prepare` script.\n\n## Usage\n\n```ts\n// vitest.config.ts\nimport { defineConfig } from \"vitest/config\";\nimport { perTestCoverageReporter } from \"vitest-coverage-per-test\";\n\nexport default defineConfig({\n  test: {\n    pool: \"forks\",\n    isolate: true,\n    coverage: {\n      enabled: true,\n      provider: \"v8\",\n      include: [\"src/**/*.ts\"],\n      exclude: [\"**/*.spec.ts\", \"**/*.test.ts\", \"**/test-utils/**\"],\n    },\n    reporters: [\n      \"default\",\n      perTestCoverageReporter({ outFile: \".coverage-per-test.json\" }),\n    ],\n  },\n});\n```\n\nRun `vitest run --coverage` and the reporter writes `outFile` at the end. Coverage data is keyed by the spec file path, project-relative.\n\n## How it works\n\n1. Vitest sets `NODE_V8_COVERAGE` automatically when coverage is on.\n2. A worker-side `afterEach` hook calls `node:v8`'s `takeCoverage()` to flush per-test coverage events. The delta is the set of source URLs touched while that test ran.\n3. The hook writes the delta to `task.meta`, which vitest carries from worker to main process.\n4. The reporter's `onTestCaseResult` hook reads `task.meta`, remaps V8's transpiled URLs back to original `.ts` source paths via `@ampproject/remapping`, deduplicates per spec file, and accumulates.\n5. `onTestRunEnd` writes the JSON.\n\n## Limitations\n\n- V8 provider only. Istanbul instrumentation produces a different shape and is out of scope.\n- Requires `isolate: true` and `pool: \"forks\"` (vitest defaults). With `isolate: false` per-test V8 coverage is unreliable; the reporter throws on detection.\n- Dynamic imports are captured if they execute before the test ends. Lazy imports loaded asynchronously after `afterEach` are not.\n- Excluded files (per `coverage.exclude`) never appear in the output even if loaded.\n\n## License\n\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffmguerreiro%2Fvitest-coverage-per-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffmguerreiro%2Fvitest-coverage-per-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffmguerreiro%2Fvitest-coverage-per-test/lists"}