-
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
Feb 13, 2024
1 parent
24c1c8d
commit fba52d7
Showing
11 changed files
with
181 additions
and
49 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 was deleted.
Oops, something went wrong.
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,84 @@ | ||
// import {useEffect, useState} from "react"; | ||
import { codeToHtml } from 'shiki'; | ||
|
||
// import { code as code1 } from '../code.ts'; | ||
// import { coreFn } from '../helper.ts'; | ||
// import LineCount from "./line-count.tsx"; | ||
// import LineCoverage from "./line-coverage.tsx"; | ||
// import LineNew from "./line-new.tsx"; | ||
// import fileCoverage from '../meta/coverage.json'; | ||
import LineCoverage from './line/coverage.tsx'; | ||
import LineNew from './line/new.tsx'; | ||
import LineNumber from './line/number.tsx'; | ||
import {coreFn} from "../../helper.ts"; | ||
import {useEffect, useState} from "preact/hooks"; | ||
import {FC} from "preact/compat"; | ||
function getDecode(str: string) { | ||
return decodeURIComponent( | ||
atob(str) | ||
.split('') | ||
.map(function (c) { | ||
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); | ||
}) | ||
.join(''), | ||
); | ||
} | ||
// const code = getDecode(code1); | ||
const Code:FC<{ | ||
fileCoverage: any; | ||
fileContent: string; | ||
fileCodeChange: number[]; | ||
theme:string | ||
}> = ({ fileCoverage, fileContent:code, fileCodeChange,theme }) => { | ||
// const code = `const a=1` | ||
const [html, setHtml] = useState(''); | ||
const { lines } = coreFn(fileCoverage, code); | ||
// console.log(lines,'lines') | ||
useEffect(() => { | ||
codeToHtml(code, { | ||
theme: theme === 'light' ? 'light-plus' : 'tokyo-night', | ||
lang: 'tsx', | ||
decorations: [], | ||
}).then((h) => { | ||
setHtml(h); | ||
}); | ||
}, [theme]); | ||
|
||
return ( | ||
<div | ||
style={{ | ||
display: 'flex', | ||
fontSize: '12px', | ||
lineHeight: '14px', | ||
backgroundColor: theme === 'dark' ? '#1a1b26' : 'white', | ||
}} | ||
> | ||
<LineNumber theme={theme} count={code.split('\n').length} /> | ||
<LineCoverage | ||
theme={theme} | ||
covers={lines.map((i) => { | ||
if (i.executionNumber > 0) { | ||
return { | ||
covered: 'yes', | ||
hits: i.executionNumber, | ||
}; | ||
} else if (i.executionNumber === 0) { | ||
return { | ||
covered: 'no', | ||
hits: i.executionNumber, | ||
}; | ||
} else { | ||
return { | ||
covered: 'neutral', | ||
hits: 0, | ||
}; | ||
} | ||
})} | ||
/> | ||
<LineNew news={fileCodeChange} /> | ||
<div dangerouslySetInnerHTML={{ __html: html }} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Code; |
53 changes: 53 additions & 0 deletions
53
packages/canyon-report/src/Report/components/line/coverage.tsx
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,53 @@ | ||
// import { CSSProperties } from 'react'; | ||
|
||
const LineCoverage = ({ covers, theme }) => { | ||
return ( | ||
<div style={{ textAlign: 'right' }}> | ||
{covers.map(({ covered, hits }, index) => { | ||
if (covered === 'yes') { | ||
return ( | ||
<div | ||
key={index} | ||
style={{ | ||
backgroundColor: | ||
theme === 'light' ? 'rgb(230,245,208)' : '#0A6640', | ||
color: theme === 'light' ? 'rgba(0,0,0,0.5)' : '#eaeaea', | ||
padding: '0 5px', | ||
}} | ||
> | ||
{hits}x | ||
</div> | ||
); | ||
} else if (covered === 'no') { | ||
return ( | ||
<div | ||
key={index} | ||
style={{ | ||
backgroundColor: | ||
theme === 'light' ? 'rgb(252,225,229)' : '#7A5474', | ||
color: theme === 'light' ? 'rgba(0,0,0,0.5)' : '#eaeaea', | ||
padding: '0 5px', | ||
height: '14px', | ||
}} | ||
></div> | ||
); | ||
} else { | ||
return ( | ||
<div | ||
key={index} | ||
style={{ | ||
backgroundColor: | ||
theme === 'light' ? 'rgb(234,234,234)' : 'rgb(45, 52, 54)', | ||
color: theme === 'light' ? 'rgba(0,0,0,0.5)' : '#eaeaea', | ||
padding: '0 5px', | ||
height: '14px', | ||
}} | ||
></div> | ||
); | ||
} | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
export default LineCoverage; |
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,16 @@ | ||
const LineNew = ({news}) => { | ||
// const news = [1, 2, 3, 7, 8, 9, 10, 14, 15]; | ||
return ( | ||
<div style={{ width: '20px', textAlign: 'center' }}> | ||
{[...Array(200)].map((line, index) => { | ||
return ( | ||
<div style={{ height: '14px', color: 'green' }}> | ||
{news.includes(index) ? '+' : ''} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
export default LineNew; |
20 changes: 20 additions & 0 deletions
20
packages/canyon-report/src/Report/components/line/number.tsx
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,20 @@ | ||
// import { CSSProperties } from 'react'; | ||
|
||
// import { CSSProperties } from 'preact-compat'; | ||
|
||
const LineNumber = ({ count, theme }) => { | ||
const style: any = { | ||
color: theme === 'light' ? '#0074D9' : '#0074D9', | ||
textAlign: 'right', | ||
padding: '0 5px 0 20px', | ||
}; | ||
return ( | ||
<div style={style}> | ||
{[...Array(count)].map((i, index) => { | ||
return <div key={index}>{index + 1}</div>; | ||
})} | ||
</div> | ||
); | ||
}; | ||
|
||
export default LineNumber; |
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