diff --git a/packages/canyon-map/package.json b/packages/canyon-map/package.json index 007ccd79..b497396e 100644 --- a/packages/canyon-map/package.json +++ b/packages/canyon-map/package.json @@ -1,6 +1,6 @@ { "name": "canyon-map", - "version": "2.0.0-beta.2", + "version": "2.0.0-beta.3", "description": "", "type": "module", "exports": { @@ -34,4 +34,4 @@ "istanbul-lib-coverage": "^3.2.2", "istanbul-lib-source-maps": "^5.0.6" } -} \ No newline at end of file +} diff --git a/packages/canyon-map/src/coverage.ts b/packages/canyon-map/src/coverage.ts index 4e20183e..2c48b55f 100644 --- a/packages/canyon-map/src/coverage.ts +++ b/packages/canyon-map/src/coverage.ts @@ -1,19 +1,25 @@ import libCoverage from "istanbul-lib-coverage"; import libSourceMaps from "istanbul-lib-source-maps"; // 覆盖率回溯,在覆盖率存储之前转换 -export async function remapCoverage(obj: any) { +export async function remapCoverage(obj:any) { + const oldKeys = Object.keys(obj); const res = await libSourceMaps .createSourceMapStore() .transformCoverage(libCoverage.createCoverageMap(obj)); const { data: data_1 } = res; - const obj_1: any = {}; - for (const dataKey in data_1) { + const obj_1 = {}; + Object.entries(data_1).forEach(([key, value],index) => { // @ts-ignore - const x = data_1[dataKey]["data"]; - obj_1[x.path] = x; - } - return obj_1; + const x = value["data"]; + // @ts-ignore + obj_1[x.path] = { + ...x, + oldPath: oldKeys[index] + }; + }); + return obj_1 } + // 回溯未经过reMapCoverage的数据,但是必须得传入插装路径,因为这里的noReMap是没有插装路径的 export const remapCoverageWithInstrumentCwd = async (noReMap:any, instrumentCwd:string) => { // 如果来自的插桩路径不同,要预处理!!! @@ -33,9 +39,13 @@ export const remapCoverageWithInstrumentCwd = async (noReMap:any, instrumentCwd: const obj2: any = {}; for (const coverageKey in reMapedCov) { const newKey = coverageKey.replace(instrumentCwd + "/", ""); + // @ts-ignore + const oldPath = reMapedCov[coverageKey].oldPath.replace(instrumentCwd + "/", ""); obj2[newKey] = { + // @ts-ignore ...reMapedCov[coverageKey], path: newKey, + oldPath, }; }