fix(merge-coverage): eliminate Windows path-separator duplication#203
Conversation
- Add normalizeCoverageKeys() to convert backslash path keys and `path` properties to forward slashes in coverage JSON blobs before merging. This prevents nyc (backslash) vs karma-typescript (forward-slash) key duplication on Windows. - Normalize globby paths to forward slashes before the exclusion filter so that `coverage/coverage-final.json` is correctly excluded even when globby returns backslash-separated paths on Windows. - Add tests for normalizeCoverageKeys in merge-coverage.test.ts Agent-Logs-Url: https://github.com/nevware21/ts-build-tools/sessions/fe9562c3-39c4-4338-9207-223a423590cb Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
Address code review feedback: use string type annotations instead of any in lambda parameters, and use const instead of var for jsonBlobs. Agent-Logs-Url: https://github.com/nevware21/ts-build-tools/sessions/fe9562c3-39c4-4338-9207-223a423590cb Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses Windows-specific coverage merging issues in merge-coverage by normalizing path separators so that Istanbul treats coverage entries for the same file as identical, and by ensuring the tool doesn’t re-merge its own previously generated output.
Changes:
- Added
normalizeCoverageKeys()to rewrite coverage JSON keys (andpathfields) to forward slashes before creating Istanbul coverage maps. - Normalized
globbyresults to forward slashes prior to filtering socoverage/coverage-final.jsonis reliably excluded on Windows. - Added unit tests covering key/path normalization behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/coverage-tools/src/merge-coverage.ts | Adds coverage key/path normalization and normalizes globbed file paths before filtering. |
| lib/coverage-tools/test/src/merge-coverage.test.ts | Adds tests for normalizeCoverageKeys() behavior across empty, forward-slash, backslash, and missing-path cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…erage-path-duplication
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
@copilot review your changes as the tests are failing |
… in normalizeCoverageKeys The istanbul FileCoverage.merge() call requires complete statementMap location data (start/end), which may not be present. Use simple last-write-wins overwrite instead — cross-blob merging is handled by istanbul in the main mergeCoverage loop. All 23 tests pass. Agent-Logs-Url: https://github.com/nevware21/ts-build-tools/sessions/148514cb-94a7-4094-a057-e3cb05720107 Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
Fixed in b9afbfd. The test failure was caused by the istanbul |
|
@copilot node 18 is still failing with this fix |
… issue merge-coverage.ts imports globby v13 (ESM-only). On Node 18, loading any test that imports from merge-coverage.ts triggers the ESM loader, which can't handle .ts file extensions (ERR_UNKNOWN_FILE_EXTENSION). Moving normalizeCoverageKeys to utils.ts (only CJS deps: fs, path, @nevware21/ts-utils) and updating the test to import from utils.ts avoids this ESM cascade. merge-coverage.ts re-exports the function for API compatibility. utils.ts also gets stronger types (Record<string, any> instead of any). Agent-Logs-Url: https://github.com/nevware21/ts-build-tools/sessions/4303ce38-8fd4-4261-a66a-f982cd20395a Co-authored-by: nev21 <82737406+nev21@users.noreply.github.com>
Fixed in 4919ceb. The Node 18 failure was caused by |
nevware21-bot
left a comment
There was a problem hiding this comment.
Approved by nevware21-bot
merge-coverage.ts: normalize glob paths to forward slashesnormalizeCoverageKeys()helpernormalizeCoverageKeysinmerge-coverage.test.tsnormalizeCoverageKeystoutils.tsto avoid ESM loader issue —merge-coverage.tsimports globby v13 (ESM-only), which caused Node 18 to switch to ESM loader mode and fail to load.tstest files