Skip to content

Wrong ranges #44

Description

@anurbol

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

Activity

  1. changed the title [-]Wrong lineNumber and columnNumber (when running code from the example in node.js documentation).[/-] [+]Wrong ranges[/+] on Nov 17, 2018
  2. bcoe commented on Nov 17, 2018

    @bcoe
    Owner

    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.

  3. anurbol commented on Nov 17, 2018

    @anurbol
    Author

    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!

  4. shinnn commented on Apr 28, 2019

    @shinnn
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions