diff --git a/lib/converter/converter.js b/lib/converter/converter.js index 7628bd5e..4ee199eb 100644 --- a/lib/converter/converter.js +++ b/lib/converter/converter.js @@ -389,6 +389,13 @@ const checkOriginalRangeCode = (range, state, startEndMap, type) => { return false; } + // do not check text for `bytes` + // it could be `} ` uncovered in `try { } catch` + // instead, use `dedupeCountRanges` to accumulate count + if (type === 'bytes') { + return true; + } + // invalid original code // Matches any character that is not a word character from the basic Latin alphabet. // Equivalent to [^A-Za-z0-9_] @@ -400,12 +407,6 @@ const checkOriginalRangeCode = (range, state, startEndMap, type) => { // type: bytes, functions, branches, statements - // do not check repeated range for `bytes` - // instead, use `dedupeCountRanges` to accumulate count - if (type === 'bytes') { - return true; - } - // check repeated range const key = `${start}_${end}`; if (startEndMap.has(key)) { diff --git a/lib/utils/snapshot.js b/lib/utils/snapshot.js index ba90aebb..f8fa79eb 100644 --- a/lib/utils/snapshot.js +++ b/lib/utils/snapshot.js @@ -247,6 +247,9 @@ const getSnapshot = (reportData) => { addPercent(snapshot.summary, summary); + files.sort((a, b) => { + return a.sourcePath - b.sourcePath; + }); files.forEach((file) => { // do NOT add debug file if (file.debug) { diff --git a/test/mock/src/async.js b/test/mock/src/async.js index a2a0be7a..19b5847a 100644 --- a/test/mock/src/async.js +++ b/test/mock/src/async.js @@ -11,10 +11,12 @@ function apple(awesome) { } } +// eslint-disable-next-line no-unused-vars function missed() { } +// eslint-disable-next-line no-unused-vars function missed2() { } @@ -22,3 +24,31 @@ function missed2() { apple(); apple(); apple(); + + +const try_catch_await = async () => { + const list = [new Promise((resolve, reject) => { + setTimeout(resolve, 100); + }), new Promise((resolve, reject) => { + setTimeout(reject, 100); + })]; + + try { + for (const p of list) { + console.log(await p); + } + console.log('uncovered'); + } catch (err) { + console.log(err); + } + + try { + for await (const p of list) { + console.log(p); + } + } catch (err) { + console.log(err); + } +}; + +try_catch_await(); diff --git a/test/snapshot/cli.snapshot.json b/test/snapshot/cli.snapshot.json index 168246ab..f19233f4 100644 --- a/test/snapshot/cli.snapshot.json +++ b/test/snapshot/cli.snapshot.json @@ -1,11 +1,11 @@ { "type": "v8", "summary": { - "bytes": "53.08 %", - "statements": "57.28 %", + "bytes": "51.47 %", + "statements": "55.80 %", "branches": "52.27 %", - "functions": "51.72 %", - "lines": "45.83 %" + "functions": "50.00 %", + "lines": "44.55 %" }, "files": { "test/mock/src/async.js": { @@ -14,7 +14,7 @@ "statements": "0.00 %", "lines": "0.00 %", "bytes": "0.00 %", - "uncoveredLines": "1-24" + "uncoveredLines": "1-54" }, "test/mock/src/closures.js": { "functions": "0.00 %", diff --git a/test/snapshot/esbuild.snapshot.json b/test/snapshot/esbuild.snapshot.json index 57f4d666..6dfe7d6f 100644 --- a/test/snapshot/esbuild.snapshot.json +++ b/test/snapshot/esbuild.snapshot.json @@ -1,11 +1,11 @@ { "type": "v8", "summary": { - "bytes": "80.44 %", - "statements": "82.64 %", + "bytes": "80.86 %", + "statements": "82.92 %", "branches": "59.27 %", - "functions": "82.80 %", - "lines": "70.49 %" + "functions": "83.33 %", + "lines": "71.03 %" }, "files": { "src/comments.js": { @@ -17,12 +17,12 @@ "uncoveredLines": "" }, "src/async.js": { - "functions": "50.00 %", + "functions": "71.43 %", "branches": "62.50 %", - "statements": "85.71 %", - "lines": "72.22 %", - "bytes": "82.62 %", - "uncoveredLines": "9,14-20" + "statements": "89.29 %", + "lines": "80.49 %", + "bytes": "89.40 %", + "uncoveredLines": "9,15-22,40-41,49" }, "src/ignore/v8-ignore-next.js": { "functions": "100.00 %", diff --git a/test/snapshot/istanbul.snapshot.json b/test/snapshot/istanbul.snapshot.json index b3cceffb..956ac02f 100644 --- a/test/snapshot/istanbul.snapshot.json +++ b/test/snapshot/istanbul.snapshot.json @@ -1,18 +1,18 @@ { "type": "istanbul", "summary": { - "lines": "81.81 %", - "statements": "81.91 %", - "functions": "75.64 %", + "lines": "82.13 %", + "statements": "82.22 %", + "functions": "76.54 %", "branches": "58.20 %" }, "files": { "async.js": { - "lines": "100.00 %", - "functions": "33.33 %", - "statements": "100.00 %", + "lines": "95.83 %", + "functions": "66.66 %", + "statements": "95.83 %", "branches": "62.50 %", - "uncoveredLines": "" + "uncoveredLines": "40" }, "branch/assignment.js": { "lines": "80.00 %", diff --git a/test/snapshot/merge.snapshot.json b/test/snapshot/merge.snapshot.json index 4ccb8a3f..fcee27b4 100644 --- a/test/snapshot/merge.snapshot.json +++ b/test/snapshot/merge.snapshot.json @@ -1,20 +1,20 @@ { "type": "v8", "summary": { - "bytes": "73.58 %", - "statements": "77.15 %", + "bytes": "74.08 %", + "statements": "77.52 %", "branches": "59.46 %", - "functions": "71.29 %", - "lines": "63.60 %" + "functions": "72.12 %", + "lines": "64.18 %" }, "files": { "test/mock/src/async.js": { - "functions": "33.33 %", + "functions": "66.67 %", "branches": "62.50 %", - "statements": "84.62 %", - "lines": "72.22 %", - "bytes": "82.62 %", - "uncoveredLines": "9,14-20" + "statements": "88.89 %", + "lines": "80.49 %", + "bytes": "89.40 %", + "uncoveredLines": "9,15-22,40-41,49" }, "test/mock/src/closures.js": { "functions": "71.43 %", diff --git a/test/snapshot/puppeteer.snapshot.json b/test/snapshot/puppeteer.snapshot.json index 921509aa..b39f6f12 100644 --- a/test/snapshot/puppeteer.snapshot.json +++ b/test/snapshot/puppeteer.snapshot.json @@ -1,20 +1,20 @@ { "type": "v8", "summary": { - "bytes": "73.75 %", - "statements": "81.28 %", + "bytes": "74.32 %", + "statements": "81.60 %", "branches": "59.60 %", - "functions": "77.92 %", - "lines": "63.71 %" + "functions": "78.75 %", + "lines": "64.36 %" }, "files": { "test/mock/src/async.js": { - "functions": "33.33 %", + "functions": "66.67 %", "branches": "62.50 %", - "statements": "84.62 %", - "lines": "72.22 %", - "bytes": "82.62 %", - "uncoveredLines": "9,14-20" + "statements": "88.89 %", + "lines": "80.49 %", + "bytes": "89.40 %", + "uncoveredLines": "9,15-22,40-41,49" }, "test/mock/src/closures.js": { "functions": "71.43 %", diff --git a/test/snapshot/rollup.snapshot.json b/test/snapshot/rollup.snapshot.json index 7e75a607..6068a20a 100644 --- a/test/snapshot/rollup.snapshot.json +++ b/test/snapshot/rollup.snapshot.json @@ -1,11 +1,11 @@ { "type": "v8", "summary": { - "bytes": "80.43 %", - "statements": "81.30 %", + "bytes": "80.85 %", + "statements": "81.63 %", "branches": "59.27 %", - "functions": "78.67 %", - "lines": "70.49 %" + "functions": "79.49 %", + "lines": "71.03 %" }, "files": { "src/comments.js": { @@ -17,12 +17,12 @@ "uncoveredLines": "" }, "src/async.js": { - "functions": "33.33 %", + "functions": "66.67 %", "branches": "62.50 %", - "statements": "84.62 %", - "lines": "72.22 %", - "bytes": "82.62 %", - "uncoveredLines": "9,14-20" + "statements": "88.89 %", + "lines": "80.49 %", + "bytes": "89.40 %", + "uncoveredLines": "9,15-22,40-41,49" }, "src/ignore/v8-ignore-next.js": { "functions": "", diff --git a/test/snapshot/swc.snapshot.json b/test/snapshot/swc.snapshot.json index ce3d79f5..6f7b56ed 100644 --- a/test/snapshot/swc.snapshot.json +++ b/test/snapshot/swc.snapshot.json @@ -1,20 +1,20 @@ { "type": "v8", "summary": { - "bytes": "80.44 %", - "statements": "81.80 %", + "bytes": "80.89 %", + "statements": "82.21 %", "branches": "59.27 %", - "functions": "78.67 %", - "lines": "70.49 %" + "functions": "79.75 %", + "lines": "71.17 %" }, "files": { "src/async.js": { - "functions": "33.33 %", + "functions": "71.43 %", "branches": "62.50 %", - "statements": "84.62 %", - "lines": "72.22 %", - "bytes": "82.62 %", - "uncoveredLines": "9,14-20" + "statements": "90.00 %", + "lines": "82.93 %", + "bytes": "90.16 %", + "uncoveredLines": "9,15-22,40-41" }, "src/branch/assignment.js": { "functions": "80.00 %", diff --git a/test/snapshot/v8.snapshot.json b/test/snapshot/v8.snapshot.json index 921509aa..b39f6f12 100644 --- a/test/snapshot/v8.snapshot.json +++ b/test/snapshot/v8.snapshot.json @@ -1,20 +1,20 @@ { "type": "v8", "summary": { - "bytes": "73.75 %", - "statements": "81.28 %", + "bytes": "74.32 %", + "statements": "81.60 %", "branches": "59.60 %", - "functions": "77.92 %", - "lines": "63.71 %" + "functions": "78.75 %", + "lines": "64.36 %" }, "files": { "test/mock/src/async.js": { - "functions": "33.33 %", + "functions": "66.67 %", "branches": "62.50 %", - "statements": "84.62 %", - "lines": "72.22 %", - "bytes": "82.62 %", - "uncoveredLines": "9,14-20" + "statements": "88.89 %", + "lines": "80.49 %", + "bytes": "89.40 %", + "uncoveredLines": "9,15-22,40-41,49" }, "test/mock/src/closures.js": { "functions": "71.43 %",