Skip to content

Commit

Permalink
added test case for try catch await
Browse files Browse the repository at this point in the history
fixed snapshot order
fixed `}` coverage for bytes
  • Loading branch information
cenfun committed Jun 15, 2024
1 parent c1471b0 commit 6a43602
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 72 deletions.
13 changes: 7 additions & 6 deletions lib/converter/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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_]
Expand All @@ -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)) {
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 30 additions & 0 deletions test/mock/src/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,44 @@ function apple(awesome) {
}
}

// eslint-disable-next-line no-unused-vars
function missed() {

}

// eslint-disable-next-line no-unused-vars
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();
10 changes: 5 additions & 5 deletions test/snapshot/cli.snapshot.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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 %",
Expand Down
18 changes: 9 additions & 9 deletions test/snapshot/esbuild.snapshot.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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 %",
Expand Down
14 changes: 7 additions & 7 deletions test/snapshot/istanbul.snapshot.json
Original file line number Diff line number Diff line change
@@ -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 %",
Expand Down
18 changes: 9 additions & 9 deletions test/snapshot/merge.snapshot.json
Original file line number Diff line number Diff line change
@@ -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 %",
Expand Down
18 changes: 9 additions & 9 deletions test/snapshot/puppeteer.snapshot.json
Original file line number Diff line number Diff line change
@@ -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 %",
Expand Down
18 changes: 9 additions & 9 deletions test/snapshot/rollup.snapshot.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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": "",
Expand Down
18 changes: 9 additions & 9 deletions test/snapshot/swc.snapshot.json
Original file line number Diff line number Diff line change
@@ -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 %",
Expand Down
18 changes: 9 additions & 9 deletions test/snapshot/v8.snapshot.json
Original file line number Diff line number Diff line change
@@ -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 %",
Expand Down

0 comments on commit 6a43602

Please sign in to comment.