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

Function map always returns column 0 as starting column #234

Open
kristijanstefanoski opened this issue Nov 6, 2023 · 0 comments
Open

Comments

@kristijanstefanoski
Copy link

kristijanstefanoski commented Nov 6, 2023

I have a very minimal reproduction of using this module and I noticed one thing, the function start column is always reported as 0, when using nyc directly the column is correctly mapped (for ex. 9).

I have the following file called utils.js:

function testUtil() {
  console.log("util");
}

module.exports = {
  testUtil,
};

Then from a file index.js I import this util and call it, and then convert the coverage like so:

const { CoverageInstrumenter } = require("collect-v8-coverage");
const v8toIstanbul = require("v8-to-istanbul");
const converter = v8toIstanbul("./utils.js");

const instrumenter = new CoverageInstrumenter();
const utils = require("./utils");

(async () => {
  await instrumenter.startInstrumenting();

  utils.testUtil();

  const coverage = await instrumenter.stopInstrumenting();
  const utilsCov = coverage.find((cov) => cov.url.includes("utils.js"));

  await converter.load();
  converter.applyCoverage(utilsCov.functions);
  console.info(JSON.stringify(converter.toIstanbul()));
})();

The output for the fnMap is as follows:

      "fnMap":{
         "0":{
            "name":"testUtil",
            "decl":{
               "start":{
                  "line":1,
                  "column":0
               },
               "end":{
                  "line":3,
                  "column":1
               }
            },
            "loc":{
               "start":{
                  "line":1,
                  "column":0
               },
               "end":{
                  "line":3,
                  "column":1
               }
            },
            "line":1
         }
      },

You can notice the declaration part is obviously wrong as the column is not 0, it should actually be 9? The length of the function keyword + 1 probably?

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

1 participant