Skip to content

Commit a8620d4

Browse files
authored
feat: warn instead of throw on exception (#29)
1 parent 522720e commit a8620d4

File tree

3 files changed

+106
-12
lines changed

3 files changed

+106
-12
lines changed

lib/report.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,15 @@ class Report {
6060
})
6161

6262
Object.keys(mergedResults).forEach((url) => {
63-
const result = mergedResults[url]
64-
const path = resolve(this.resolve, result.url)
65-
const script = v8toIstanbul(path)
66-
script.applyCoverage(result.functions)
67-
map.merge(script.toIstanbul())
63+
try {
64+
const result = mergedResults[url]
65+
const path = resolve(this.resolve, result.url)
66+
const script = v8toIstanbul(path)
67+
script.applyCoverage(result.functions)
68+
map.merge(script.toIstanbul())
69+
} catch (err) {
70+
console.warn(`file: ${url} error: ${err.stack}`)
71+
}
6872
})
6973

7074
return map
@@ -73,10 +77,14 @@ class Report {
7377
const files = readdirSync(this.tempDirectory)
7478

7579
return files.map((f) => {
76-
return JSON.parse(readFileSync(
77-
resolve(this.tempDirectory, f),
78-
'utf8'
79-
))
80+
try {
81+
return JSON.parse(readFileSync(
82+
resolve(this.tempDirectory, f),
83+
'utf8'
84+
))
85+
} catch (err) {
86+
console.warn(`${err.stack}`)
87+
}
8088
})
8189
}
8290
}

package-lock.json

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ second
88
--------------------|----------|----------|----------|----------|-------------------|
99
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
1010
--------------------|----------|----------|----------|----------|-------------------|
11-
All files | 94.12 | 70.59 | 0 | 94.12 | |
11+
All files | 92.5 | 69.23 | 0 | 92.5 | |
1212
bin | 83.72 | 57.14 | 100 | 83.72 | |
1313
c8.js | 83.72 | 57.14 | 100 | 83.72 |... 22,40,41,42,43 |
14-
lib | 96.41 | 65.38 | 100 | 96.41 | |
14+
lib | 93.71 | 62.96 | 100 | 93.71 | |
1515
parse-args.js | 97.47 | 44.44 | 100 | 97.47 | 55,56 |
16-
report.js | 95.45 | 76.47 | 100 | 95.45 | 51,52,53,54 |
16+
report.js | 90.63 | 72.22 | 100 | 90.63 |... 70,71,85,86,87 |
1717
test/fixtures | 95.16 | 83.33 | 0 | 95.16 | |
1818
async.js | 100 | 100 | 100 | 100 | |
1919
multiple-spawn.js | 100 | 100 | 100 | 100 | |

0 commit comments

Comments
 (0)