From 4611535b7d92516a3de7990e3af36af1a31d5400 Mon Sep 17 00:00:00 2001 From: yashwanth195 <59129034+yashwanth195@users.noreply.github.com> Date: Fri, 13 Nov 2026 14:49:02 -0800 Subject: [PATCH 1/2] Add portable coverage maps --- ...e-map-portability_2026-11-13-22-44-19.json | 11 + .../rush/nonbrowser-approved-packages.json | 8 + .../build-tests-subspace/pnpm-lock.yaml | 22 +- .../build-tests-subspace/repo-state.json | 4 +- .../config/subspaces/default/pnpm-lock.yaml | 102 ++++--- .../config/subspaces/default/repo-state.json | 2 +- heft-plugins/heft-jest-plugin/README.md | 3 + heft-plugins/heft-jest-plugin/package.json | 4 + .../heft-jest-plugin/src/JestCoverageMap.ts | 134 +++++++++ .../src/test/JestCoverageMap.test.ts | 278 ++++++++++++++++++ 10 files changed, 517 insertions(+), 51 deletions(-) create mode 100644 common/changes/@rushstack/heft-jest-plugin/user-yverupaka-jest-coverage-map-portability_2026-11-13-22-44-19.json create mode 100644 heft-plugins/heft-jest-plugin/src/JestCoverageMap.ts create mode 100644 heft-plugins/heft-jest-plugin/src/test/JestCoverageMap.test.ts diff --git a/common/changes/@rushstack/heft-jest-plugin/user-yverupaka-jest-coverage-map-portability_2026-11-13-22-44-19.json b/common/changes/@rushstack/heft-jest-plugin/user-yverupaka-jest-coverage-map-portability_2026-11-13-22-44-19.json new file mode 100644 index 00000000000..d5778130967 --- /dev/null +++ b/common/changes/@rushstack/heft-jest-plugin/user-yverupaka-jest-coverage-map-portability_2026-11-13-22-44-19.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "Add portable Istanbul coverage maps as a foundation for Jest shard coverage aggregation.", + "type": "minor", + "packageName": "@rushstack/heft-jest-plugin" + } + ], + "packageName": "@rushstack/heft-jest-plugin", + "email": "59129034+yashwanth195@users.noreply.github.com" +} \ No newline at end of file diff --git a/common/config/rush/nonbrowser-approved-packages.json b/common/config/rush/nonbrowser-approved-packages.json index 853d3fdc370..fe85072d720 100644 --- a/common/config/rush/nonbrowser-approved-packages.json +++ b/common/config/rush/nonbrowser-approved-packages.json @@ -798,6 +798,14 @@ "name": "import-lazy", "allowedCategories": [ "libraries" ] }, + { + "name": "istanbul-lib-coverage", + "allowedCategories": [ "libraries" ] + }, + { + "name": "istanbul-lib-instrument", + "allowedCategories": [ "libraries" ] + }, { "name": "jest", "allowedCategories": [ "libraries", "tests" ] diff --git a/common/config/subspaces/build-tests-subspace/pnpm-lock.yaml b/common/config/subspaces/build-tests-subspace/pnpm-lock.yaml index 08f760e7c08..0f40915461e 100644 --- a/common/config/subspaces/build-tests-subspace/pnpm-lock.yaml +++ b/common/config/subspaces/build-tests-subspace/pnpm-lock.yaml @@ -852,11 +852,11 @@ packages: engines: {node: '>=18.12'} '@pnpm/types@6.4.0': - resolution: {integrity: sha1-MSw78LQ7ADUIyyG9OBVAbqDztmk=, tarball: https://ms-feed-12.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/@pnpm/types/-/types-6.4.0.tgz} + resolution: {integrity: sha1-MSw78LQ7ADUIyyG9OBVAbqDztmk=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/@pnpm/types/-/types-6.4.0.tgz} engines: {node: '>=10.16'} '@pnpm/types@8.9.0': - resolution: {integrity: sha1-ljbV8GQnk0MvcmCbeUWMqb4EmwI=, tarball: https://ms-feed-12.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/@pnpm/types/-/types-8.9.0.tgz} + resolution: {integrity: sha1-ljbV8GQnk0MvcmCbeUWMqb4EmwI=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/@pnpm/types/-/types-8.9.0.tgz} engines: {node: '>=14.6'} '@pnpm/types@9.4.2': @@ -919,7 +919,7 @@ packages: resolution: {directory: ../../../heft-plugins/heft-api-extractor-plugin, type: directory} engines: {node: '>=20.9.0'} peerDependencies: - '@rushstack/heft': 1.3.4 + '@rushstack/heft': 1.3.5 '@rushstack/heft-config-file@file:../../../libraries/heft-config-file': resolution: {directory: ../../../libraries/heft-config-file, type: directory} @@ -929,7 +929,7 @@ packages: resolution: {directory: ../../../heft-plugins/heft-jest-plugin, type: directory} engines: {node: '>=20.9.0'} peerDependencies: - '@rushstack/heft': ^1.3.4 + '@rushstack/heft': ^1.3.5 '@types/jest': ^30.0.0 jest-environment-jsdom: ^30.3.0 jest-environment-node: ^30.3.0 @@ -945,18 +945,18 @@ packages: resolution: {directory: ../../../heft-plugins/heft-lint-plugin, type: directory} engines: {node: '>=20.9.0'} peerDependencies: - '@rushstack/heft': 1.3.4 + '@rushstack/heft': 1.3.5 '@rushstack/heft-node-rig@file:../../../rigs/heft-node-rig': resolution: {directory: ../../../rigs/heft-node-rig, type: directory} peerDependencies: - '@rushstack/heft': ^1.3.4 + '@rushstack/heft': ^1.3.5 '@rushstack/heft-typescript-plugin@file:../../../heft-plugins/heft-typescript-plugin': resolution: {directory: ../../../heft-plugins/heft-typescript-plugin, type: directory} engines: {node: '>=20.9.0'} peerDependencies: - '@rushstack/heft': 1.3.4 + '@rushstack/heft': 1.3.5 '@rushstack/heft@file:../../../apps/heft': resolution: {directory: ../../../apps/heft, type: directory} @@ -1100,10 +1100,10 @@ packages: resolution: {integrity: sha512-oh/6byDPnL1zeNXFrDXFLyZjkr1MsBG667IM792caf1L2UPOOMf65NFzjUH/ltyfwjAGfs1rsX1eftK0jC/KIg==} '@types/istanbul-lib-coverage@2.0.4': - resolution: {integrity: sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==} + resolution: {integrity: sha1-hGfUs8CHgF1jWASAiQeRJ3zjXEQ=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz} '@types/istanbul-lib-coverage@2.0.6': - resolution: {integrity: sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==} + resolution: {integrity: sha1-dznCMqH+6bTTzomF8xTAxtM1Sdc=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz} '@types/istanbul-lib-report@3.0.3': resolution: {integrity: sha512-NQn7AHQnk/RSLOxrBbGyJM/aVQ+pjj5HCgasFxc0K/KhoATfQ/47AyUl15I2yBUpihjmas+a+VJBOqecrFH+uA==} @@ -2488,7 +2488,7 @@ packages: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} istanbul-lib-coverage@3.2.2: - resolution: {integrity: sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==} + resolution: {integrity: sha1-LRZsSwZE1Do58Ev2wu3R5YXzF1Y=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz} engines: {node: '>=8'} istanbul-lib-instrument@6.0.3: @@ -4834,6 +4834,8 @@ snapshots: '@rushstack/heft-config-file': file:../../../libraries/heft-config-file(@types/node@20.17.19) '@rushstack/node-core-library': file:../../../libraries/node-core-library(@types/node@20.17.19) '@rushstack/terminal': file:../../../libraries/terminal(@types/node@20.17.19) + '@types/istanbul-lib-coverage': 2.0.6 + istanbul-lib-coverage: 3.2.2 jest-config: 30.3.0(@types/node@20.17.19) jest-resolve: 30.3.0 jest-snapshot: 30.3.0 diff --git a/common/config/subspaces/build-tests-subspace/repo-state.json b/common/config/subspaces/build-tests-subspace/repo-state.json index 1449961bcde..6c53f188ca2 100644 --- a/common/config/subspaces/build-tests-subspace/repo-state.json +++ b/common/config/subspaces/build-tests-subspace/repo-state.json @@ -1,6 +1,6 @@ // DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush. { - "pnpmShrinkwrapHash": "18a657d83020df41f6602b7c9087b7253cfee8e0", + "pnpmShrinkwrapHash": "2d809488ba633b49642efa77255a19455f1026a5", "preferredVersionsHash": "550b4cee0bef4e97db6c6aad726df5149d20e7d9", - "packageJsonInjectedDependenciesHash": "293debc6ed16567f5567a7748229a73be6647cc6" + "packageJsonInjectedDependenciesHash": "d5f6c2f6e850c173db1fe7980b08a67a66e994f2" } diff --git a/common/config/subspaces/default/pnpm-lock.yaml b/common/config/subspaces/default/pnpm-lock.yaml index 13b7ce39782..46d18ced016 100644 --- a/common/config/subspaces/default/pnpm-lock.yaml +++ b/common/config/subspaces/default/pnpm-lock.yaml @@ -3300,7 +3300,7 @@ importers: dependencies: '@jest/core': specifier: ~30.3.0 - version: 30.3.0(babel-plugin-macros@3.1.0)(esbuild-register@3.6.0(esbuild@0.28.0)) + version: 30.3.0 '@jest/reporters': specifier: ~30.3.0 version: 30.3.0 @@ -3316,9 +3316,15 @@ importers: '@rushstack/terminal': specifier: workspace:* version: link:../../libraries/terminal + '@types/istanbul-lib-coverage': + specifier: 2.0.6 + version: 2.0.6 + istanbul-lib-coverage: + specifier: 3.2.2 + version: 3.2.2 jest-config: specifier: ~30.3.0 - version: 30.3.0(@types/node@20.17.19)(babel-plugin-macros@3.1.0)(esbuild-register@3.6.0(esbuild@0.28.0)) + version: 30.3.0(@types/node@20.17.19) jest-resolve: specifier: ~30.3.0 version: 30.3.0 @@ -3332,6 +3338,9 @@ importers: '@rushstack/heft': specifier: workspace:* version: link:../../apps/heft + '@types/istanbul-lib-instrument': + specifier: 1.7.8 + version: 1.7.8 '@types/node': specifier: 20.17.19 version: 20.17.19 @@ -3341,6 +3350,9 @@ importers: eslint: specifier: ~9.37.0 version: 9.37.0 + istanbul-lib-instrument: + specifier: 6.0.3 + version: 6.0.3 jest-environment-jsdom: specifier: ~30.3.0 version: 30.3.0 @@ -4838,7 +4850,7 @@ importers: version: 1.3.4(@types/node@20.17.19) '@rushstack/heft-node-rig': specifier: 2.11.55 - version: 2.11.55(@rushstack/heft@1.3.4(@types/node@20.17.19))(@types/node@20.17.19)(babel-plugin-macros@3.1.0)(esbuild-register@3.6.0(esbuild@0.28.0))(jest-environment-jsdom@30.3.0) + version: 2.11.55(@rushstack/heft@1.3.4(@types/node@20.17.19))(@types/node@20.17.19)(jest-environment-jsdom@30.3.0) '@types/jest': specifier: 30.0.0 version: 30.0.0 @@ -6446,7 +6458,7 @@ packages: engines: {node: '>=6.9.0'} '@babel/parser@7.29.2': - resolution: {integrity: sha512-4GgRzy/+fsBa72/RZVJmGKPmZu9Byn8o4MoLpmNe1m8ZfYnz5emHLQz3U4gLud6Zwl0RZIcgiLD7Uq7ySFuDLA==} + resolution: {integrity: sha1-WL1QuaeVHRNJiKGuF3o175pwO6E=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/@babel/parser/-/parser-7.29.2.tgz} engines: {node: '>=6.0.0'} hasBin: true @@ -8356,7 +8368,7 @@ packages: engines: {node: '>=8'} '@istanbuljs/schema@0.1.3': - resolution: {integrity: sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==} + resolution: {integrity: sha1-5F44TkuOwWvOL9kDr3hFD2v37Jg=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/@istanbuljs/schema/-/schema-0.1.3.tgz} engines: {node: '>=8'} '@jest/console@29.7.0': @@ -10375,6 +10387,12 @@ packages: '@types/aws-lambda@8.10.93': resolution: {integrity: sha512-Vsyi9ogDAY3REZDjYnXMRJJa62SDvxHXxJI5nGDQdZW058dDE+av/anynN2rLKbCKXDRNw3D/sQmqxVflZFi4A==} + '@types/babel-generator@6.25.8': + resolution: {integrity: sha1-RLN7y81LHiTE5Zdfpte3K4yaRWs=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/@types/babel-generator/-/babel-generator-6.25.8.tgz} + + '@types/babel-types@7.0.16': + resolution: {integrity: sha1-dJFsG3pr1T3D0/QFO2USa8xejm8=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/@types/babel-types/-/babel-types-7.0.16.tgz} + '@types/babel__core@7.20.5': resolution: {integrity: sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==} @@ -10491,10 +10509,13 @@ packages: resolution: {integrity: sha512-/CLhCW79JUeLKznI6mbVieGbl4QU5Hfn+6udw1YHZoofASjbQ5zaP5LzAUZYDpRYEjS4/P+DhEgyJ/PQmGGTWw==} '@types/istanbul-lib-coverage@2.0.4': - resolution: {integrity: sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==} + resolution: {integrity: sha1-hGfUs8CHgF1jWASAiQeRJ3zjXEQ=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz} '@types/istanbul-lib-coverage@2.0.6': - resolution: {integrity: sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==} + resolution: {integrity: sha1-dznCMqH+6bTTzomF8xTAxtM1Sdc=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz} + + '@types/istanbul-lib-instrument@1.7.8': + resolution: {integrity: sha1-Tl9hQ1id/j5arv3sEDdyi2CZ23o=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/@types/istanbul-lib-instrument/-/istanbul-lib-instrument-1.7.8.tgz} '@types/istanbul-lib-report@3.0.3': resolution: {integrity: sha512-NQn7AHQnk/RSLOxrBbGyJM/aVQ+pjj5HCgasFxc0K/KhoATfQ/47AyUl15I2yBUpihjmas+a+VJBOqecrFH+uA==} @@ -12974,7 +12995,7 @@ packages: resolution: {integrity: sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==} emoji-regex@8.0.0: - resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} + resolution: {integrity: sha1-6Bj9ac5cz8tARZT4QpY79TFkzDc=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/emoji-regex/-/emoji-regex-8.0.0.tgz} emoji-regex@9.2.2: resolution: {integrity: sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==} @@ -14681,7 +14702,7 @@ packages: engines: {node: '>=4'} is-fullwidth-code-point@3.0.0: - resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==} + resolution: {integrity: sha1-8Rb4Bk/pCz94RKOJl8C3UFEmnx0=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz} engines: {node: '>=8'} is-function@1.0.2: @@ -14884,7 +14905,7 @@ packages: engines: {node: '>=0.10.0'} istanbul-lib-coverage@3.2.2: - resolution: {integrity: sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==} + resolution: {integrity: sha1-LRZsSwZE1Do58Ev2wu3R5YXzF1Y=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz} engines: {node: '>=8'} istanbul-lib-instrument@5.2.1: @@ -14892,7 +14913,7 @@ packages: engines: {node: '>=8'} istanbul-lib-instrument@6.0.3: - resolution: {integrity: sha512-Vtgk7L/R2JHyyGW07spoFlB8/lpjiOLTjMdms6AFMraYt3BaJauod/NGrfnVG/y4Ix1JEuMRPDPEj2ua+zz1/Q==} + resolution: {integrity: sha1-+hVAHfbBWHS8shBfdzMl14xmZ2U=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/istanbul-lib-instrument/-/istanbul-lib-instrument-6.0.3.tgz} engines: {node: '>=10'} istanbul-lib-report@3.0.1: @@ -18129,7 +18150,7 @@ packages: engines: {node: '>=6'} string-width@4.2.3: - resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==} + resolution: {integrity: sha1-JpxxF9J7Ba0uU2gwqOyJXvnG0BA=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/string-width/-/string-width-4.2.3.tgz} engines: {node: '>=8'} string-width@5.1.2: @@ -18569,7 +18590,7 @@ packages: resolution: {integrity: sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==} tslib@2.8.1: - resolution: {integrity: sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==} + resolution: {integrity: sha1-YS7+TtI11Wfoq6Xypfq3AoCt6D8=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/tslib/-/tslib-2.8.1.tgz} tslint@5.20.1: resolution: {integrity: sha512-EcMxhzCFt8k+/UP5r8waCf/lzmeSyVlqxqMEDQE7rWYiQky8KpIBz1JAoYXfROHrPZ1XXd43q8yQnULOLiBRQg==} @@ -19207,7 +19228,7 @@ packages: engines: {node: '>=8'} wrap-ansi@7.0.0: - resolution: {integrity: sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==} + resolution: {integrity: sha1-Z+FFz/UQpqaYS98RUpEdadLrnkM=, tarball: https://ms-feed-25.pkgs.visualstudio.com/1es-public/_packaging/npm-public/npm/registry/wrap-ansi/-/wrap-ansi-7.0.0.tgz} engines: {node: '>=10'} wrap-ansi@8.1.0: @@ -23213,7 +23234,7 @@ snapshots: - supports-color - ts-node - '@jest/core@30.3.0(babel-plugin-macros@3.1.0)(esbuild-register@3.6.0(esbuild@0.28.0))': + '@jest/core@30.3.0': dependencies: '@jest/console': 30.3.0 '@jest/pattern': 30.0.1 @@ -23228,7 +23249,7 @@ snapshots: exit-x: 0.2.2 graceful-fs: 4.2.11 jest-changed-files: 30.3.0 - jest-config: 30.3.0(@types/node@22.9.3)(babel-plugin-macros@3.1.0)(esbuild-register@3.6.0(esbuild@0.28.0)) + jest-config: 30.3.0(@types/node@22.9.3) jest-haste-map: 30.3.0 jest-message-util: 30.3.0 jest-regex-util: 30.0.1 @@ -24963,16 +24984,16 @@ snapshots: transitivePeerDependencies: - '@types/node' - '@rushstack/heft-jest-plugin@2.0.21(@rushstack/heft@1.3.4(@types/node@20.17.19))(@types/jest@30.0.0)(@types/node@20.17.19)(babel-plugin-macros@3.1.0)(esbuild-register@3.6.0(esbuild@0.28.0))(jest-environment-jsdom@30.3.0)(jest-environment-node@30.3.0)': + '@rushstack/heft-jest-plugin@2.0.21(@rushstack/heft@1.3.4(@types/node@20.17.19))(@types/jest@30.0.0)(@types/node@20.17.19)(jest-environment-jsdom@30.3.0)(jest-environment-node@30.3.0)': dependencies: - '@jest/core': 30.3.0(babel-plugin-macros@3.1.0)(esbuild-register@3.6.0(esbuild@0.28.0)) + '@jest/core': 30.3.0 '@jest/reporters': 30.3.0 '@jest/transform': 30.3.0 '@rushstack/heft': 1.3.4(@types/node@20.17.19) '@rushstack/heft-config-file': 0.20.17(@types/node@20.17.19) '@rushstack/node-core-library': 5.25.1(@types/node@20.17.19) '@rushstack/terminal': 0.24.7(@types/node@20.17.19) - jest-config: 30.3.0(@types/node@20.17.19)(babel-plugin-macros@3.1.0)(esbuild-register@3.6.0(esbuild@0.28.0)) + jest-config: 30.3.0(@types/node@20.17.19) jest-resolve: 30.3.0 jest-snapshot: 30.3.0 optionalDependencies: @@ -24996,13 +25017,13 @@ snapshots: transitivePeerDependencies: - '@types/node' - '@rushstack/heft-node-rig@2.11.55(@rushstack/heft@1.3.4(@types/node@20.17.19))(@types/node@20.17.19)(babel-plugin-macros@3.1.0)(esbuild-register@3.6.0(esbuild@0.28.0))(jest-environment-jsdom@30.3.0)': + '@rushstack/heft-node-rig@2.11.55(@rushstack/heft@1.3.4(@types/node@20.17.19))(@types/node@20.17.19)(jest-environment-jsdom@30.3.0)': dependencies: '@microsoft/api-extractor': 7.60.0(@types/node@20.17.19) '@rushstack/eslint-config': 4.9.0(eslint@9.37.0)(typescript@5.8.2) '@rushstack/heft': 1.3.4(@types/node@20.17.19) '@rushstack/heft-api-extractor-plugin': 1.3.31(@rushstack/heft@1.3.4(@types/node@20.17.19))(@types/node@20.17.19) - '@rushstack/heft-jest-plugin': 2.0.21(@rushstack/heft@1.3.4(@types/node@20.17.19))(@types/jest@30.0.0)(@types/node@20.17.19)(babel-plugin-macros@3.1.0)(esbuild-register@3.6.0(esbuild@0.28.0))(jest-environment-jsdom@30.3.0)(jest-environment-node@30.3.0) + '@rushstack/heft-jest-plugin': 2.0.21(@rushstack/heft@1.3.4(@types/node@20.17.19))(@types/jest@30.0.0)(@types/node@20.17.19)(jest-environment-jsdom@30.3.0)(jest-environment-node@30.3.0) '@rushstack/heft-lint-plugin': 1.4.1(@rushstack/heft@1.3.4(@types/node@20.17.19))(@types/node@20.17.19) '@rushstack/heft-typescript-plugin': 1.3.26(@rushstack/heft@1.3.4(@types/node@20.17.19))(@types/node@20.17.19) '@types/jest': 30.0.0 @@ -26893,6 +26914,12 @@ snapshots: '@types/aws-lambda@8.10.93': {} + '@types/babel-generator@6.25.8': + dependencies: + '@types/babel-types': 7.0.16 + + '@types/babel-types@7.0.16': {} + '@types/babel__core@7.20.5': dependencies: '@babel/parser': 7.29.2 @@ -27054,6 +27081,13 @@ snapshots: '@types/istanbul-lib-coverage@2.0.6': {} + '@types/istanbul-lib-instrument@1.7.8': + dependencies: + '@types/babel-generator': 6.25.8 + '@types/babel-types': 7.0.16 + '@types/istanbul-lib-coverage': 2.0.6 + source-map: 0.6.1 + '@types/istanbul-lib-report@3.0.3': dependencies: '@types/istanbul-lib-coverage': 2.0.6 @@ -30013,6 +30047,8 @@ snapshots: dedent@0.7.0: {} + dedent@1.7.2: {} + dedent@1.7.2(babel-plugin-macros@3.1.0): optionalDependencies: babel-plugin-macros: 3.1.0 @@ -30564,14 +30600,6 @@ snapshots: transitivePeerDependencies: - supports-color - esbuild-register@3.6.0(esbuild@0.28.0): - dependencies: - debug: 4.4.3(supports-color@8.1.1) - esbuild: 0.28.0 - transitivePeerDependencies: - - supports-color - optional: true - esbuild-runner@2.2.2(esbuild@0.14.54): dependencies: esbuild: 0.14.54 @@ -31145,7 +31173,7 @@ snapshots: eslint@8.57.1: dependencies: - '@eslint-community/eslint-utils': 4.9.1(eslint@8.57.1) + '@eslint-community/eslint-utils': 4.9.1(eslint@9.37.0) '@eslint-community/regexpp': 4.12.2 '@eslint/eslintrc': 2.1.4 '@eslint/js': 8.57.1 @@ -33129,7 +33157,7 @@ snapshots: - babel-plugin-macros - supports-color - jest-circus@30.3.0(babel-plugin-macros@3.1.0): + jest-circus@30.3.0: dependencies: '@jest/environment': 30.3.0 '@jest/expect': 30.3.0 @@ -33138,7 +33166,7 @@ snapshots: '@types/node': 22.9.3 chalk: 4.1.2 co: 4.6.0 - dedent: 1.7.2(babel-plugin-macros@3.1.0) + dedent: 1.7.2 is-generator-fn: 2.1.0 jest-each: 30.3.0 jest-matcher-utils: 30.3.0 @@ -33234,7 +33262,7 @@ snapshots: - babel-plugin-macros - supports-color - jest-config@30.3.0(@types/node@20.17.19)(babel-plugin-macros@3.1.0)(esbuild-register@3.6.0(esbuild@0.28.0)): + jest-config@30.3.0(@types/node@20.17.19): dependencies: '@babel/core': 7.29.0 '@jest/get-type': 30.1.0 @@ -33247,7 +33275,7 @@ snapshots: deepmerge: 4.3.1 glob: 10.5.0 graceful-fs: 4.2.11 - jest-circus: 30.3.0(babel-plugin-macros@3.1.0) + jest-circus: 30.3.0 jest-docblock: 30.2.0 jest-environment-node: 30.3.0 jest-regex-util: 30.0.1 @@ -33261,12 +33289,11 @@ snapshots: strip-json-comments: 3.1.1 optionalDependencies: '@types/node': 20.17.19 - esbuild-register: 3.6.0(esbuild@0.28.0) transitivePeerDependencies: - babel-plugin-macros - supports-color - jest-config@30.3.0(@types/node@22.9.3)(babel-plugin-macros@3.1.0)(esbuild-register@3.6.0(esbuild@0.28.0)): + jest-config@30.3.0(@types/node@22.9.3): dependencies: '@babel/core': 7.29.0 '@jest/get-type': 30.1.0 @@ -33279,7 +33306,7 @@ snapshots: deepmerge: 4.3.1 glob: 10.5.0 graceful-fs: 4.2.11 - jest-circus: 30.3.0(babel-plugin-macros@3.1.0) + jest-circus: 30.3.0 jest-docblock: 30.2.0 jest-environment-node: 30.3.0 jest-regex-util: 30.0.1 @@ -33293,7 +33320,6 @@ snapshots: strip-json-comments: 3.1.1 optionalDependencies: '@types/node': 22.9.3 - esbuild-register: 3.6.0(esbuild@0.28.0) transitivePeerDependencies: - babel-plugin-macros - supports-color diff --git a/common/config/subspaces/default/repo-state.json b/common/config/subspaces/default/repo-state.json index 3d09725be2d..55e56a9c559 100644 --- a/common/config/subspaces/default/repo-state.json +++ b/common/config/subspaces/default/repo-state.json @@ -1,5 +1,5 @@ // DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush. { - "pnpmShrinkwrapHash": "a21e9138c38033203ce379c3ec1a9aa12562d3c6", + "pnpmShrinkwrapHash": "29047d1b8fb535d70b569f4054013dc120218b4d", "preferredVersionsHash": "029c99bd6e65c5e1f25e2848340509811ff9753c" } diff --git a/heft-plugins/heft-jest-plugin/README.md b/heft-plugins/heft-jest-plugin/README.md index 25f82e5ef62..1ee091b308f 100644 --- a/heft-plugins/heft-jest-plugin/README.md +++ b/heft-plugins/heft-jest-plugin/README.md @@ -2,6 +2,9 @@ This is a Heft plugin for running Jest. +Portable Istanbul coverage maps provide a foundation for coverage aggregation across Jest shards. +This helper does not enable sharding or change Jest execution. + ## Links - [CHANGELOG.md]( diff --git a/heft-plugins/heft-jest-plugin/package.json b/heft-plugins/heft-jest-plugin/package.json index 53c493bc2ac..ee81b05d0ec 100644 --- a/heft-plugins/heft-jest-plugin/package.json +++ b/heft-plugins/heft-jest-plugin/package.json @@ -43,6 +43,8 @@ "@rushstack/heft-config-file": "workspace:*", "@rushstack/node-core-library": "workspace:*", "@rushstack/terminal": "workspace:*", + "@types/istanbul-lib-coverage": "2.0.6", + "istanbul-lib-coverage": "3.2.2", "jest-config": "~30.3.0", "jest-resolve": "~30.3.0", "jest-snapshot": "~30.3.0" @@ -50,9 +52,11 @@ "devDependencies": { "@jest/types": "30.3.0", "@rushstack/heft": "workspace:*", + "@types/istanbul-lib-instrument": "1.7.8", "@types/node": "20.17.19", "decoupled-local-node-rig": "workspace:*", "eslint": "~9.37.0", + "istanbul-lib-instrument": "6.0.3", "jest-environment-jsdom": "~30.3.0", "jest-environment-node": "~30.3.0", "jest-watch-select-projects": "2.0.0" diff --git a/heft-plugins/heft-jest-plugin/src/JestCoverageMap.ts b/heft-plugins/heft-jest-plugin/src/JestCoverageMap.ts new file mode 100644 index 00000000000..9e7127d4623 --- /dev/null +++ b/heft-plugins/heft-jest-plugin/src/JestCoverageMap.ts @@ -0,0 +1,134 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +import * as path from 'node:path'; + +import type { CoverageMap, FileCoverageData } from 'istanbul-lib-coverage'; + +export interface IJestFileCoverageData extends FileCoverageData { + /** Istanbul discards this untested-file baseline when real coverage exists. */ + all?: boolean; + /** Truthy branch counts produced by Istanbul's reportLogic option. */ + bT?: Record; +} + +export interface ICoverageSource { + hash: string; + text: string; +} + +export function validateCoverageIdentity(identity: string): void { + if ( + !identity || + path.posix.isAbsolute(identity) || + path.win32.isAbsolute(identity) || + identity.includes('\\') || + identity.includes(':') || + identity.includes('\0') || + identity.split('/').some((part) => !part || part === '.' || part === '..') + ) { + throw new Error(`Invalid build-root-relative coverage identity: "${identity}".`); + } +} + +/** Convert a native absolute filename inside the build root to a portable identity. */ +export function coverageIdentity(buildFolderPath: string, filename: string): string { + if (!path.isAbsolute(buildFolderPath) || !path.isAbsolute(filename)) { + throw new Error('Coverage paths must be absolute.'); + } + const identity: string = path.relative(buildFolderPath, filename).split(path.sep).join('/'); + validateCoverageIdentity(identity); + return identity; +} + +/** + * Detach remapped Istanbul coverage from class instances and source-map caches for JSON serialization. + * Sources are keyed by build-root-relative identity; their hashes are not read or verified here. + */ +export function portableCoverageMap( + map: CoverageMap, + buildFolderPath: string, + sources: ReadonlyMap +): Record { + const portable: Record = Object.create(null); + for (const filename of map.files().sort()) { + const identity: string = coverageIdentity(buildFolderPath, filename); + if (Object.hasOwn(portable, identity)) { + throw new Error(`Duplicate coverage identity "${identity}".`); + } + const coverage: IJestFileCoverageData = map.fileCoverageFor(filename).data; + if (coverage.path !== filename) { + throw new Error(`Coverage path does not match map entry "${filename}".`); + } + const { statementMap, fnMap, branchMap, s, f, b, bT, all } = coverage; + const data: IJestFileCoverageData = structuredClone({ + path: identity, + statementMap, + fnMap, + branchMap, + s, + f, + b, + ...(bT === undefined ? {} : { bT }), + ...(all === undefined ? {} : { all }) + }); + const source: ICoverageSource | undefined = sources.get(identity); + if (!source) { + throw new Error(`Missing original coverage source "${identity}".`); + } + const validateCount = (count: number): void => { + if (!Number.isSafeInteger(count) || count < 0) { + throw new Error(`Invalid coverage count for "${identity}".`); + } + }; + for (const counts of [data.s, data.f]) { + for (const count of Object.values(counts)) { + validateCount(count); + } + } + for (const counts of [data.b, data.bT]) { + if (counts) { + for (const branchCounts of Object.values(counts)) { + for (const count of branchCounts) { + validateCount(count); + } + } + } + } + const lines: string[] = source.text.split(/\r\n|\r|\n/); + const normalizeEnd = (location: FileCoverageData['statementMap'][string]): void => { + // Remapping uses Infinity for an end-of-line without an exact column mapping. + // Only this sentinel may be replaced; JSON would silently turn other non-finite numbers into null. + if (location.end.column === Number.POSITIVE_INFINITY) { + const line: string | undefined = lines[location.end.line - 1]; + if (line === undefined) { + throw new Error(`Invalid coverage source-map line for "${identity}".`); + } + location.end.column = line.length; + } + }; + for (const location of Object.values(data.statementMap)) { + normalizeEnd(location); + } + for (const fn of Object.values(data.fnMap)) { + normalizeEnd(fn.loc); + normalizeEnd(fn.decl); + } + for (const branch of Object.values(data.branchMap)) { + normalizeEnd(branch.loc); + for (const location of branch.locations) { + normalizeEnd(location); + } + } + portable[identity] = data; + } + // Implicit else arms contain undefined positions, which must become empty JSON objects. + return JSON.parse( + JSON.stringify(portable, (key: string, value: unknown) => { + if (typeof value === 'number' && !Number.isFinite(value)) { + throw new Error(`Non-finite coverage value for "${key}".`); + } + return value; + }) + ); +} diff --git a/heft-plugins/heft-jest-plugin/src/test/JestCoverageMap.test.ts b/heft-plugins/heft-jest-plugin/src/test/JestCoverageMap.test.ts new file mode 100644 index 00000000000..a34962b3ea8 --- /dev/null +++ b/heft-plugins/heft-jest-plugin/src/test/JestCoverageMap.test.ts @@ -0,0 +1,278 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +import * as path from 'node:path'; +import { Script } from 'node:vm'; +import { createCoverageMap, createFileCoverage, type CoverageMap } from 'istanbul-lib-coverage'; +import { createInstrumenter, type InstrumenterOptions } from 'istanbul-lib-instrument'; + +import { + coverageIdentity, + portableCoverageMap, + validateCoverageIdentity, + type ICoverageSource, + type IJestFileCoverageData +} from '../JestCoverageMap'; + +const ROOT: string = path.resolve(__dirname, 'coverage-root'); +const IDENTITY: string = 'src/choose.js'; +const SOURCE: string = [ + 'function choose(value) {', + ' if (value) {', + " return value && 'yes';", + ' }', + " return 'no';", + '}', + '' +].join('\n'); + +function createMap(root: string = ROOT): CoverageMap { + // Istanbul 6 supports reportLogic, but its community typings do not include the option. + const options: Partial & { reportLogic: boolean } = { reportLogic: true }; + const instrumenter = createInstrumenter(options); + const context: { __coverage__?: Record } = {}; + const instrumented: string = instrumenter.instrumentSync(SOURCE, path.join(root, IDENTITY)); + new Script(`${instrumented}\nchoose(true); choose(false);`).runInNewContext(context); + if (!context.__coverage__) { + throw new Error('The instrumented fixture did not produce coverage.'); + } + return createCoverageMap(context.__coverage__); +} + +function createSources(text: string = SOURCE): Map { + return new Map([[IDENTITY, { text, hash: 'opaque-source-hash' }]]); +} + +describe('coverage identities', () => { + it('uses build-root-relative forward-slash identities', () => { + expect(coverageIdentity(ROOT, path.join(ROOT, 'src', 'choose.js'))).toBe(IDENTITY); + expect(coverageIdentity(ROOT, path.join(ROOT, '..inside', 'choose.js'))).toBe('..inside/choose.js'); + }); + + it.each([ + '', + '.', + '..', + '../outside.js', + 'src/../choose.js', + './choose.js', + 'src//choose.js', + 'src/', + '/choose.js', + 'C:/choose.js', + 'C:choose.js', + '\\\\server\\share\\choose.js', + 'src\\choose.js', + 'choose.js:stream', + 'choose\0.js' + ])('rejects a nonportable identity %j', (identity) => { + expect(() => validateCoverageIdentity(identity)).toThrow('Invalid build-root-relative coverage identity'); + }); + + it('rejects outside-root, root-only and relative paths', () => { + for (const filename of [ROOT, path.join(ROOT, '..', 'outside.js'), 'src/choose.js']) { + expect(() => coverageIdentity(ROOT, filename)).toThrow(); + } + expect(() => coverageIdentity('relative-root', path.join(ROOT, IDENTITY))).toThrow('absolute'); + }); +}); + +describe('portableCoverageMap', () => { + it('round trips real Istanbul data without caches, class instances, lost counters or input mutations', () => { + const map: CoverageMap = createMap(); + const original: IJestFileCoverageData = map.fileCoverageFor(path.join(ROOT, IDENTITY)).data; + const before: IJestFileCoverageData = structuredClone(original); + const sources: Map = createSources(); + const sourcesBefore: [string, ICoverageSource][] = structuredClone([...sources]); + const cache = { inputSourceMap: new Map([['filename', ROOT]]), sourceMapCache: () => ROOT }; + Object.assign(original, cache); + + const portable: Record = portableCoverageMap(map, ROOT, sources); + expect(Object.keys(portable)).toEqual([IDENTITY]); + expect(portable).toEqual(JSON.parse(JSON.stringify(portable))); + expect(Object.getPrototypeOf(portable[IDENTITY])).toBe(Object.prototype); + expect(portable[IDENTITY]).toEqual({ + path: IDENTITY, + statementMap: before.statementMap, + fnMap: before.fnMap, + branchMap: JSON.parse(JSON.stringify(before.branchMap)), + s: before.s, + f: before.f, + b: before.b, + bT: before.bT + }); + expect(Object.values(portable[IDENTITY].s).some((count) => count > 0)).toBe(true); + expect(Object.values(portable[IDENTITY].b).some((counts) => counts.length === 2)).toBe(true); + expect(Object.values(portable[IDENTITY].bT!).some((counts) => counts.some((count) => count > 0))).toBe( + true + ); + const implicitElse = Object.values(portable[IDENTITY].branchMap).find((branch) => branch.type === 'if')!; + expect(implicitElse.locations[1]).toEqual({ start: {}, end: {} }); + expect(createCoverageMap(portable).getCoverageSummary().toJSON()).toEqual( + map.getCoverageSummary().toJSON() + ); + expect(original).toEqual({ ...before, ...cache }); + portable[IDENTITY].s[0] += 10; + portable[IDENTITY].statementMap[0].start.column += 1; + expect(original).toEqual({ ...before, ...cache }); + expect([...sources]).toEqual(sourcesBefore); + }); + + it.each([true, false])('preserves the all=%s baseline marker', (all) => { + const filename: string = path.join(ROOT, IDENTITY); + const data: IJestFileCoverageData = { ...createFileCoverage(filename).data, all }; + const portable: Record = portableCoverageMap( + createCoverageMap({ [filename]: data }), + ROOT, + createSources() + ); + expect(portable[IDENTITY].all).toBe(all); + expect(createFileCoverage(portable[IDENTITY]).toJSON()).toEqual(portable[IDENTITY]); + }); + + it('produces the same map in different build roots and orders files deterministically', () => { + const otherRoot: string = path.resolve(ROOT, '..', 'other-root'); + expect(portableCoverageMap(createMap(otherRoot), otherRoot, createSources())).toEqual( + portableCoverageMap(createMap(), ROOT, createSources()) + ); + const map: CoverageMap = createMap(); + map.addFileCoverage(createFileCoverage(path.join(ROOT, 'a.js'))); + const sources: Map = createSources(); + sources.set('a.js', { text: '', hash: '' }); + expect(Object.keys(portableCoverageMap(map, ROOT, sources))).toEqual(['a.js', IDENTITY]); + }); + + it.each(['\n', '\r\n', '\r'])( + 'resolves only positive-Infinity end columns using %j source lines', + (newline) => { + const map: CoverageMap = createMap(); + const original = map.fileCoverageFor(path.join(ROOT, IDENTITY)).data; + const locations = [ + original.statementMap[0], + original.fnMap[0].loc, + original.fnMap[0].decl, + original.branchMap[0].loc, + original.branchMap[0].locations[0] + ]; + for (const location of locations) { + location.end = { line: 2, column: Number.POSITIVE_INFINITY }; + } + // V8-derived coverage can legitimately contain negative, finite columns. + original.fnMap[0].decl.start.column = -2; + const before = structuredClone(original); + const portable = portableCoverageMap(map, ROOT, createSources(`first${newline}second${newline}`))[ + IDENTITY + ]; + for (const location of [ + portable.statementMap[0], + portable.fnMap[0].loc, + portable.fnMap[0].decl, + portable.branchMap[0].loc, + portable.branchMap[0].locations[0] + ]) { + expect(location.end).toEqual({ line: 2, column: 6 }); + } + expect(portable.fnMap[0].decl.start.column).toBe(-2); + expect(original).toEqual(before); + } + ); + + it.each([0, -1, 1.5, 99, NaN, Infinity])( + 'rejects invalid sentinel line %s without mutating input', + (line) => { + const map: CoverageMap = createMap(); + const original = map.fileCoverageFor(path.join(ROOT, IDENTITY)).data; + original.statementMap[0].end = { line, column: Number.POSITIVE_INFINITY }; + const before = structuredClone(original); + expect(() => portableCoverageMap(map, ROOT, createSources())).toThrow( + 'Invalid coverage source-map line' + ); + expect(original).toEqual(before); + } + ); + + it.each([ + { text: '', line: 1, column: 0 }, + { text: 'first\n', line: 2, column: 0 }, + { text: '\t\uD83D\uDE00', line: 1, column: 3 } + ])('uses original UTF-16 line length including empty lines (%j)', ({ text, line, column }) => { + const map: CoverageMap = createMap(); + map.fileCoverageFor(path.join(ROOT, IDENTITY)).data.statementMap[0].end = { + line, + column: Number.POSITIVE_INFINITY + }; + expect(portableCoverageMap(map, ROOT, createSources(text))[IDENTITY].statementMap[0].end).toEqual({ + line, + column + }); + }); + + it.each([NaN, Infinity, -Infinity, -1, 0.5, Number.MAX_SAFE_INTEGER + 1])( + 'rejects invalid counts (%s)', + (value) => { + for (const field of ['s', 'f', 'b', 'bT'] as const) { + const map: CoverageMap = createMap(); + const data: IJestFileCoverageData = map.fileCoverageFor(path.join(ROOT, IDENTITY)).data; + if (field === 's' || field === 'f') { + data[field][0] = value; + } else { + Object.values(data[field]!)[0][0] = value; + } + const before = structuredClone(data); + expect(() => portableCoverageMap(map, ROOT, createSources())).toThrow('Invalid coverage count'); + expect(data).toEqual(before); + } + } + ); + + it.each([NaN, Infinity, -Infinity])('rejects non-finite nonsentinel coordinates (%s)', (value) => { + for (const field of ['start', 'end', 'line'] as const) { + const map: CoverageMap = createMap(); + const data: IJestFileCoverageData = map.fileCoverageFor(path.join(ROOT, IDENTITY)).data; + switch (field) { + case 'start': + data.statementMap[0].start.column = value; + break; + case 'end': + if (value === Infinity) continue; + data.statementMap[0].end.column = value; + break; + case 'line': + data.statementMap[0].start.line = value; + break; + } + expect(() => portableCoverageMap(map, ROOT, createSources())).toThrow('Non-finite coverage value'); + } + }); + + it('requires original source even without a sentinel, but permits an empty map', () => { + expect(() => portableCoverageMap(createMap(), ROOT, new Map())).toThrow( + 'Missing original coverage source' + ); + expect(portableCoverageMap(createCoverageMap({}), ROOT, new Map())).toEqual({}); + }); + + it('rejects outside-root, mismatched and colliding file identities instead of dropping coverage', () => { + const filename: string = path.join(ROOT, IDENTITY); + const outside: string = path.resolve(ROOT, '..', 'outside.js'); + expect(() => + portableCoverageMap( + createCoverageMap({ [outside]: createFileCoverage(outside) }), + ROOT, + createSources() + ) + ).toThrow('Invalid build-root-relative coverage identity'); + expect(() => + portableCoverageMap( + createCoverageMap({ [filename]: createFileCoverage(outside) }), + ROOT, + createSources() + ) + ).toThrow('Coverage path does not match map entry'); + + const map: CoverageMap = createMap(); + const alias: string = `${ROOT}${path.sep}src${path.sep}.${path.sep}choose.js`; + map.addFileCoverage(createFileCoverage(alias)); + expect(() => portableCoverageMap(map, ROOT, createSources())).toThrow('Duplicate coverage identity'); + }); +}); From 5174e773251a98c065c814ef11d7b9958d26e89d Mon Sep 17 00:00:00 2001 From: yashwanth195 <59129034+yashwanth195@users.noreply.github.com> Date: Mon, 16 Nov 2026 17:05:46 -0800 Subject: [PATCH 2/2] Clarify Babel coverage portability --- heft-plugins/heft-jest-plugin/README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/heft-plugins/heft-jest-plugin/README.md b/heft-plugins/heft-jest-plugin/README.md index 1ee091b308f..c2cf4d435ce 100644 --- a/heft-plugins/heft-jest-plugin/README.md +++ b/heft-plugins/heft-jest-plugin/README.md @@ -2,8 +2,10 @@ This is a Heft plugin for running Jest. -Portable Istanbul coverage maps provide a foundation for coverage aggregation across Jest shards. -This helper does not enable sharding or change Jest execution. +Portable Istanbul-format coverage maps support future managed Babel coverage aggregation across Jest shards. +The helper makes paths build-root-relative and source-map end-of-line locations JSON-safe without changing counters. +It does not enable sharding, instrument code, or merge raw V8 coverage. +Heft still defaults to V8; raw V8 transport does not require this helper. ## Links