-
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
Allen Zhang (张涛)
committed
Sep 26, 2024
1 parent
339d229
commit 183c1c1
Showing
3 changed files
with
39 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ node_modules/ | |
coverage | ||
dist | ||
lib/ | ||
html-spa.js |
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,37 @@ | ||
const { ReportBase } = require("istanbul-lib-report"); | ||
const CCR = require("./lib"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
module.exports = class CustomReporter extends ReportBase { | ||
constructor(opts) { | ||
super(); | ||
this.coverage = {}; | ||
} | ||
|
||
onStart(root, context) {} | ||
|
||
onDetail(node, context) { | ||
const fileCoverage = node.getFileCoverage().toJSON(); | ||
this.coverage[fileCoverage.path] = fileCoverage; | ||
} | ||
|
||
async onEnd() { | ||
const covPath = path.join(process.cwd(), "coverage/coverage-final.json"); | ||
|
||
// 检查covPath是否存在,如果不存在则创建 | ||
if (!fs.existsSync(path.dirname(covPath))) { | ||
fs.writeFileSync(covPath, JSON.stringify(this.coverage)); | ||
// TODO 应该通过内存传过来 | ||
console.log("新创建的"); | ||
} | ||
|
||
const ccr = CCR({ | ||
name: "My Coverage Report - 2024-02-28", | ||
outputDir: "./coverage-reports", | ||
reports: ["v8", "console-details"], | ||
cleanCache: true, | ||
}); | ||
await ccr.add({}); | ||
await ccr.generate(); | ||
} | ||
}; |
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