Skip to content

Commit

Permalink
feat: update canyon-report
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Sep 26, 2024
1 parent 339d229 commit 183c1c1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/canyon-report/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules/
coverage
dist
lib/
html-spa.js
37 changes: 37 additions & 0 deletions packages/canyon-report/html-spa.js
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();
}
};
2 changes: 1 addition & 1 deletion packages/canyon-report/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "canyon-report7",
"version": "0.0.8-beta-18",
"version": "0.0.8-beta-19",
"description": "My webpack project",
"main": "./lib/index.js",
"bin": "./lib/cli.js",
Expand Down

0 comments on commit 183c1c1

Please sign in to comment.