Skip to content

Commit

Permalink
chore: repo overall update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao25 committed Nov 22, 2024
1 parent 0572aa7 commit ff820db
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 81 deletions.
57 changes: 0 additions & 57 deletions packages/canyon-report/src/canyon.ts
Original file line number Diff line number Diff line change
@@ -1,57 +0,0 @@
export function init() {
// @ts-ignore
window.__canyon__analytics__dsn__ = `https://collect.canyonjs.org/coverage/client`
setTimeout(()=>{
// @ts-ignore
if (window.__coverage__ && window.__canyon__analytics__dsn__) {
// @ts-ignore
function collectCoverageData(timing) {
// @ts-ignore
const first = Object.values(window.__coverage__)
// @ts-ignore
const {projectID,sha,instrumentCwd} = first[0]

const data = new FormData();
// @ts-ignore
data.append('coverage',JSON.stringify(Object.entries(window.__coverage__).map(([path, {b,f,s}]) => ({
path,
b,
f,
s,
})).reduce((acc, {path, b, f, s}) => {
// @ts-ignore
acc[path] = {b, f, s};
return acc;
}, {})))
// @ts-ignore
data.append('projectID',projectID)
// @ts-ignore
data.append('sha',sha)
data.append('instrumentCwd',instrumentCwd)

navigator.sendBeacon(
// @ts-ignore
window.__canyon__analytics__dsn__,
data,
);
}

// beforeunload 事件:当用户即将离开页面时触发
window.addEventListener("beforeunload", () => {
collectCoverageData("beforeunload");
});

// unload 事件:在页面完全卸载前触发
window.addEventListener("unload", () => {
collectCoverageData("unload");
});

// visibilitychange 事件:当页面变为不可见(如切换到其他标签页)时触发
document.addEventListener("visibilitychange", () => {
if (document.visibilityState === "hidden") {
collectCoverageData("visibilitychange");
}
});
}
},500)
}
17 changes: 12 additions & 5 deletions packages/canyon-report/src/components/Report/Report.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ import { Spin } from "antd";
import { genFileDetailLines, ggggggfn } from "../helpers/file";
// import { genFileDetailLines } from "../helpers";

const onSelectDefault = () => {
return Promise.resolve({
fileContent: "",
fileCoverage: {},
});
}

const Report: FC<ReportProps> = ({
dataSource,
value,
onSelect,
reportName,
dataSource=[],
value="",
onSelect=onSelectDefault,
reportName='untitled',
}) => {
const [filenameKeywords, setFilenameKeywords] = useState("");
const [range, setRange] = useState([0, 100]);
// const [range, setRange] = useState([0, 100]);
const [showMode, setShowMode] = useState("tree");
const [loading, setLoading] = useState(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { createHighlighterCoreInstance } from "../../helpers/loadShiki";

function jisuanColor(coun) {
if (coun === 0) {
return "rgba(255, 0, 0, 0.5)";
return "rgb(252, 225, 229)";
}
if (coun > 0) {
return "rgba(255, 255, 0, 0.5)";
return "rgb(230, 245, 208)";
}
if (coun < 0) {
return "unset";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { Tag, Typography } from "antd";
import { getColor } from "../../helpers";
import { CoverageSummaryData } from "istanbul-lib-coverage";
const { Text } = Typography;
function convertFirstLetterToUpper(name) {
return name.charAt(0).toUpperCase() + name.slice(1);
}
const SummaryNav: FC<{
reportName: string;
value: string;
Expand Down Expand Up @@ -57,7 +60,7 @@ const SummaryMetric: FC<{
{value.pct}%
</span>
<Text style={{ fontSize: "14px" }} type={"secondary"}>
{t(key)}:
{convertFirstLetterToUpper(key)}:
</Text>
<Tag bordered={false}>
{value.covered}/{value.total}
Expand Down
2 changes: 1 addition & 1 deletion packages/canyon-report/src/index.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@import 'antd/dist/reset.css';
/*@import 'antd/dist/reset.css';*/

.shiki > code {
font-size: 12px;
Expand Down
14 changes: 0 additions & 14 deletions packages/canyon-report/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@ import './index.css'
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import {init as canyonInit} from './canyon.ts'

canyonInit()
// @ts-ignore
window.__canyon__ = {
"dsn": "https://canyon-collect-three.vercel.app/coverage/client",
"reporter": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InR6aGFuZ20iLCJpZCI6ODQxNywiaWF0IjoxNzExNjAwMjA1LCJleHAiOjIwMjcxNzYyMDV9.8P2NIRv_skZvboci8TbRgiPesjlopA1cZXtG-ybhuiE",
"instrumentCwd": "/vercel/path0",
"branch": "main",
"commitSha": "91a12fc016b8f0c61dd605a67b38b6c5999fed74",
"sha": "91a12fc016b8f0c61dd605a67b38b6c5999fed74",
"projectID": "118075",
"compareTarget": "-"
}

const rootEl = document.getElementById("root");
if (rootEl) {
Expand Down
2 changes: 1 addition & 1 deletion packages/canyon-report/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ module.exports = {
},
plugins: [],
corePlugins: {
preflight: false,
// preflight: false,
},
};

0 comments on commit ff820db

Please sign in to comment.