Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After merge, unexpected branch not covered at trailing char { #43

Open
loynoir opened this issue Aug 2, 2023 · 6 comments
Open

After merge, unexpected branch not covered at trailing char { #43

loynoir opened this issue Aug 2, 2023 · 6 comments

Comments

@loynoir
Copy link

loynoir commented Aug 2, 2023

Description

Run reproduce.mjs with env RUNTIME=node and RUNTIME=browser.

Merge coverage-final.json from different runtime.

Expect 100% coverage.

Actually, branch not covered at trailing char {

---------------|---------|----------|---------|---------|-------------------
File           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
---------------|---------|----------|---------|---------|-------------------
All files      |     100 |    33.33 |     100 |     100 |                   
 reproduce.mjs |     100 |    33.33 |     100 |     100 | 4-8               
---------------|---------|----------|---------|---------|-------------------
reproduce.mjs:1:const IS_NODE = process.env['RUNTIME'].includes('node')
reproduce.mjs:2:const IS_BROWSER = process.env['RUNTIME'].includes('browser')
reproduce.mjs:3:
reproduce.mjs:4:if (IS_NODE) {
reproduce.mjs:5:  console.log('node')
reproduce.mjs:6:}
reproduce.mjs:7:
reproduce.mjs:8:if (IS_BROWSER) {
reproduce.mjs:9:  console.log('browser')
reproduce.mjs:10:}
reproduce.mjs:11:
reproduce.mjs:12:export { }

Reproduce Repo

https://github.com/loynoir/reproduce-istanbul-lib-coverage-737

Related
istanbuljs/istanbuljs#737

https://playwright.dev/docs/api/class-coverage

@ljharb
Copy link
Owner

ljharb commented Aug 5, 2023

How exactly do i run reproduce.js so that it produces coverage data?

@loynoir
Copy link
Author

loynoir commented Aug 5, 2023

@ljharb
Copy link
Owner

ljharb commented Aug 5, 2023

On node v20.5.0, everything seems to work just fine, including the nyc command. What version of node are you using?

@loynoir
Copy link
Author

loynoir commented Aug 5, 2023

$ git clean -dfx > /dev/null
$
$ node --version
v20.4.0
$ npm i && bash ./test.sh

added 261 packages, and audited 262 packages in 5s

70 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
+ env RUNTIME=node,browser npm exec -- c8 --report-dir build/expected node ./reproduce.mjs
node
browser
---------------|---------|----------|---------|---------|-------------------
File           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
---------------|---------|----------|---------|---------|-------------------
All files      |     100 |      100 |     100 |     100 |                   
 reproduce.mjs |     100 |      100 |     100 |     100 |                   
---------------|---------|----------|---------|---------|-------------------
+ env RUNTIME=node npm exec -- c8 --report-dir build/actual/node node ./reproduce.mjs
node
---------------|---------|----------|---------|---------|-------------------
File           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
---------------|---------|----------|---------|---------|-------------------
All files      |   83.33 |       50 |     100 |   83.33 |                   
 reproduce.mjs |   83.33 |       50 |     100 |   83.33 | 9-10              
---------------|---------|----------|---------|---------|-------------------
+ env RUNTIME=browser npm exec -- c8 --report-dir build/actual/browser node ./reproduce.mjs
browser
---------------|---------|----------|---------|---------|-------------------
File           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
---------------|---------|----------|---------|---------|-------------------
All files      |   83.33 |       50 |     100 |   83.33 |                   
 reproduce.mjs |   83.33 |       50 |     100 |   83.33 | 5-6               
---------------|---------|----------|---------|---------|-------------------
+ mkdir -p ./build/actual/temp
+ npm exec -- istanbul-merge --out ./build/actual/temp/coverage.json ./build/actual/node/coverage-final.json ./build/actual/browser/coverage-final.json
+ npm exec -- nyc report -r lcov -r text --temp-directory ./build/actual/temp --report-dir ./build/actual
---------------|---------|----------|---------|---------|-------------------
File           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
---------------|---------|----------|---------|---------|-------------------
All files      |     100 |    33.33 |     100 |     100 |                   
 reproduce.mjs |     100 |    33.33 |     100 |     100 | 4-8               
---------------|---------|----------|---------|---------|-------------------
$

@ljharb
Copy link
Owner

ljharb commented Aug 5, 2023

ohhh right sorry, it's not that it errors, it's that there's 4 uncovered lines 👀

@ljharb
Copy link
Owner

ljharb commented Aug 5, 2023

All this package is doing is wrapping istanbul's istanbul.createCoverageMap, and using .merge on it. I think this is a bug in istanbul.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants