-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3cfb91b
commit ba92c85
Showing
10 changed files
with
111 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import libCoverage from "istanbul-lib-coverage"; | ||
import libSourceMaps from "istanbul-lib-source-maps"; | ||
|
||
// 覆盖率回溯,在覆盖率存储之前转换 | ||
export async function remapCoverage(obj: any) { | ||
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 x = data_1[dataKey]["data"]; | ||
obj_1[x.path] = x; | ||
} | ||
return obj_1; | ||
} | ||
|
||
function parseInstrumentCwd(instrumentCwd) { | ||
if (instrumentCwd.includes("=>")) { | ||
const instrumentCwdSplit = instrumentCwd.split("=>"); | ||
return [instrumentCwdSplit[0], instrumentCwdSplit[1]]; | ||
} else { | ||
return [instrumentCwd, ""]; | ||
} | ||
} | ||
function convertInstrumentCwd({ path, instrumentCwd, projectInstrumentCwd }) { | ||
if (!projectInstrumentCwd) { | ||
return path.replace(instrumentCwd, ""); | ||
} else { | ||
// 这里需要解析一下instrumentCwd,如果包含"=>",则需要替换。 | ||
const [leftInstrumentCwd, rightInstrumentCwd] = | ||
parseInstrumentCwd(projectInstrumentCwd); | ||
return path | ||
.replace(instrumentCwd, "") | ||
.replace(leftInstrumentCwd, rightInstrumentCwd); | ||
} | ||
} | ||
// 格式化上报的覆盖率对象 | ||
export function formatReportObject(c: any) { | ||
// 去除斜杠\\ | ||
const removeSlash = (x: any) => | ||
JSON.parse(JSON.stringify(x).replace(/\\\\/g, "/")); | ||
// 暂时解决方案,需要解决sourceMap问题 | ||
const coverage = removeSlash(c.coverage); | ||
const instrumentCwd = removeSlash(c.instrumentCwd); | ||
const projectInstrumentCwd = removeSlash(c.projectInstrumentCwd || ""); | ||
const reversePath = (p: string) => { | ||
const a = convertInstrumentCwd({ | ||
path: p, | ||
instrumentCwd, | ||
projectInstrumentCwd, | ||
}); | ||
let b = ""; | ||
// 从第二个字符开始 | ||
for (let i = 1; i < a.length; i++) { | ||
b += a[i]; | ||
} | ||
return "" + b; | ||
}; | ||
const obj: any = {}; | ||
for (const coverageKey in coverage) { | ||
obj[reversePath(coverageKey)] = { | ||
...coverage[coverageKey], | ||
path: reversePath(coverageKey), | ||
}; | ||
} | ||
|
||
// 确保修改成istanbul格式,去掉start、end为空的情况 | ||
|
||
return { | ||
coverage: obj, | ||
instrumentCwd, | ||
}; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.