Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Zhang (张涛) committed Oct 29, 2024
1 parent f1abd29 commit 7a422e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/canyon-data/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "canyon-data",
"version": "0.1.1-alpha.12",
"version": "0.1.1-alpha.15",
"type": "module",
"main": "dist/canyon-data.cjs",
"module": "dist/canyon-data.js",
Expand Down
12 changes: 8 additions & 4 deletions packages/canyon-data/src/utils/line.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function calculateNewLineCoverageForSingleFile(coverage:FileCoverageData,
3. 在其中,且他们的hit大于0,就是覆盖的
*/


const newLineResult = []
for (let i = 0; i < newLine.length; i++) {
const line = newLine[i];
Expand All @@ -40,7 +41,7 @@ export function calculateNewLineCoverageForSingleFile(coverage:FileCoverageData,

Object.keys(coverage.statementMap).forEach((key) => {
const statementRange = coverage.statementMap[key];
if (statementRange.start.line <= line && statementRange.end.line >= line) {
if (statementRange.start.line <= line && (statementRange.end?.line||statementRange.start.line) >= line) {
isLand = true
if ( coverage.s[key] > 0){
isCovered = true
Expand All @@ -50,7 +51,7 @@ export function calculateNewLineCoverageForSingleFile(coverage:FileCoverageData,

Object.keys(coverage.fnMap).forEach((key) => {
const fnRange = coverage.fnMap[key];
if (fnRange.decl.start.line <= line && fnRange.decl.end.line >= line) {
if (fnRange.decl.start.line <= line && (fnRange.decl.end?.line||fnRange.decl.start.line) >= line) {
isLand = true
if (coverage.f[key] > 0) {
isCovered = true
Expand All @@ -61,7 +62,7 @@ export function calculateNewLineCoverageForSingleFile(coverage:FileCoverageData,
Object.keys(coverage.branchMap).forEach((key) => {
const branchRange = coverage.branchMap[key];
branchRange.locations.forEach((location,index) => {
if (location.start.line <= line && location.end.line >= line) {
if (location.start.line <= line && (location.end?.line||location.start.line) >= line) {
isLand = true
if (coverage.b[key][index] > 0){
isCovered = true
Expand All @@ -77,7 +78,10 @@ export function calculateNewLineCoverageForSingleFile(coverage:FileCoverageData,
}

const newLineResultIsLand = newLineResult.filter((l) => l.isLand)

if(coverage.path ==='src/pages/flightList/index.tsx'){
console.log(newLine)
console.log(newLineResultIsLand)
}
const result = {
total: newLineResultIsLand.length,
covered: newLineResultIsLand.filter((l) => l.covered).length,
Expand Down

0 comments on commit 7a422e3

Please sign in to comment.