Skip to content

Commit

Permalink
chore: daily development
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Dec 19, 2024
1 parent 8bf8120 commit fca7536
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/canyon-map/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "canyon-map",
"version": "2.0.0-beta.2",
"version": "2.0.0-beta.3",
"description": "",
"type": "module",
"exports": {
Expand Down Expand Up @@ -34,4 +34,4 @@
"istanbul-lib-coverage": "^3.2.2",
"istanbul-lib-source-maps": "^5.0.6"
}
}
}
24 changes: 17 additions & 7 deletions packages/canyon-map/src/coverage.ts
Original file line number Diff line number Diff line change
@@ -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) => {
// 如果来自的插桩路径不同,要预处理!!!
Expand All @@ -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,
};
}

Expand Down

0 comments on commit fca7536

Please sign in to comment.