From 8986e4c458208868cc30670ddecf15de20bf59d9 Mon Sep 17 00:00:00 2001 From: cenfun Date: Sat, 14 Sep 2024 14:12:54 +0800 Subject: [PATCH] fix merging uncovered ranges for server/client side coverage --- lib/converter/converter.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/converter/converter.js b/lib/converter/converter.js index 31641f3..8b9cb6c 100644 --- a/lib/converter/converter.js +++ b/lib/converter/converter.js @@ -1350,13 +1350,11 @@ const isCoveredInRanges = (range, uncoveredBytes) => { const mergeV8Data = (state, stateList) => { // console.log(stateList); - // const sourcePath = state.sourcePath; - // console.log(sourcePath); - // if (sourcePath.endsWith('scroll_zoom.ts')) { - // console.log('merge v8 data ===================================', sourcePath); - // console.log(stateList.map((it) => it.bytes)); - // console.log(stateList.map((it) => it.functions)); - // console.log(stateList.map((it) => it.branches.map((b) => [`${b.start}-${b.end}`, JSON.stringify(b.locations.map((l) => l.count))]))); + // if (state.sourcePath.endsWith('test.tsx')) { + // console.log('merge v8 bytes ===================================', state.sourcePath); + // console.log('bytes before ============', stateList.map((it) => it.bytes)); + // console.log('functions ==============', stateList.map((it) => it.functions)); + // console.log('branches ======================', stateList.map((it) => it.branches.map((b) => [`${b.start}-${b.end}`, JSON.stringify(b.locations.map((l) => l.count))]))); // } // =========================================================== @@ -1373,13 +1371,23 @@ const mergeV8Data = (state, stateList) => { uncoveredBytes.push(range); } }); - uncoveredList.push(uncoveredBytes); + if (uncoveredBytes.length) { + uncoveredList.push(uncoveredBytes); + } }); + + // if (state.sourcePath.endsWith('test.tsx')) { + // console.log('mergedBytes ============', mergedBytes); + // console.log('uncoveredList ============', uncoveredList); + // console.log('======================================================='); + // } + // just remove uncovered range uncoveredList.forEach((currentBytes) => { currentBytes.forEach((range) => { for (const targetBytes of uncoveredList) { if (targetBytes === currentBytes) { + // self continue; } if (isCoveredInRanges(range, targetBytes)) { @@ -1393,6 +1401,10 @@ const mergeV8Data = (state, stateList) => { // will be dedupeCountRanges in collectFileCoverage state.bytes = mergedBytes; + // if (state.sourcePath.endsWith('test.tsx')) { + // console.log('bytes after ============', mergedBytes); + // } + // =========================================================== // functions const allFunctions = stateList.map((it) => it.functions).flat();