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

Wrong ranges #44

Closed
anurbol opened this issue Nov 17, 2018 · 3 comments
Closed

Wrong ranges #44

anurbol opened this issue Nov 17, 2018 · 3 comments

Comments

@anurbol
Copy link

anurbol commented Nov 17, 2018

Not necessarily relates to c8, but I was asked to create an issue here.

I have general struggle with coverage features in node.js.

I tried using c8 package and node.js' inspector module.
Neither of them gives correct lineNumber, columnNumber and ranges (startOffset, endOffset), unfortunately.

c8

when I run c8 node test.js where test.js is this file:

function foo() {
  console.log(123)
}

foo()

I get this in the generated report:

{"functionName":"foo","ranges":[{"startOffset":62,"endOffset":99,"count":1}]

Note the startOffset":62 when there is 44 characters total in test.js. I am not even speaking about "endOffset":99.

inspector

after not successing with c8 I tried to place in my test.js code from this example

and run node test.js
then I got this:

{"functionName":"session.post","scriptId":"66","url":"file:///home/nurbol/www/sandbox/test.js","lineNumber":5,"columnNumber":32},"hitCount":0,"children":[16]}

Note the "lineNumber":5 when there is no anything on line number 5!

Then @bcoe gave me an advice to take into accunt require('module').wrapper[0] that is inserted by node.js. But if done so, line number 5 contains session.connect and not session.post (see the json above)!

My setup:

Linux (Lubuntu).
Node 11.2.0 (also tested in 10.13.0 with the same results)
c8 3.2.1

@anurbol anurbol changed the title Wrong lineNumber and columnNumber (when running code from the example in node.js documentation). Wrong ranges Nov 17, 2018
@bcoe
Copy link
Owner

bcoe commented Nov 17, 2018

this is a bug with the header not being removed, because of a breaking change in Node.js around module naming; it will be fixed in future node versions when wrapping behavior changes — the 62 characters is module.wrap not being removed from the offsets.

@anurbol
Copy link
Author

anurbol commented Nov 17, 2018

Thanks! I got it! So it takes 62 characters, and I should simply always (until fixed node versions) subtract this number to get real offsets! Cool!

@shinnn
Copy link
Contributor

shinnn commented Apr 28, 2019

I'm closing this because Node.js v12 has been released.

If you still run into this problem even if you use Node.js v12, feel free to comment more here.

@shinnn shinnn closed this as completed Apr 28, 2019
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

3 participants