100% line coverage when 50% at most with ESM
- Dominant language
- JavaScript
- Stars
- 2.1k
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
I'm filing at the request of @bcoe. The bug may actually be in [v8-to-istanbul](https://github.com/istanbuljs/v8-to-istanbul).
To repro `npm i -g c8 esm nyc`
Then create a file `foo.js`:
```js
const { log } = console
function a() {
if (true) {
log("hi")
} else {
log("false")
}
}
function b() {
if (true) {
log("hi")
} else {
log("false")
}
}
a()
```
and run `c8 node foo.js` which will report:
```shell
hi
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 55 | 75 | 0 | 55 | |
foo.js | 55 | 75 | 0 | 55 |... 13,14,15,16,17 |
----------|----------|----------|----------|----------|-------------------|
```
now change the line `const { log } = console` to `import { log } from "console"`
and run `c8 node -r esm foo.js` which will report:
```shell
hi
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 100 | 100 | 100 | 100 | |
foo.js | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|-------------------|
```
If I run `nyc node -r esm foo.js` instead it will report:
```shell
hi
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 42.86 | 25 | 50 | 42.86 | |
foo.js | 42.86 | 25 | 50 | 42.86 | 7,12,13,15 |
----------|----------|----------|----------|----------|-------------------|
```
and with `report --reporter=html` is
Contributor guide
Assessment
This issue has not been assessed yet.