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

Why are we hardcoding this.covSources[0] in _maybeRemapStartColEndCol function #241

Open
Songyu-Wang opened this issue Feb 20, 2024 · 1 comment

Comments

@Songyu-Wang
Copy link

Songyu-Wang commented Feb 20, 2024

Hello,
So I am trying to convert my v8 coverage to istanbul and got surprised that the translation is not working as expected.

Unfortunately I cannot share a repo for you to debug, so I have to debug this myself.

After loading the source,

async load () {

[
  {
    source: CovSource {
      lines: [Array],
      eof: 736,
      shebangLength: 0,
      wrapperLength: 0
    },
    path: 'webpack://A.ts'
  },
  {
    source: CovSource {
      lines: [Array],
      eof: 1087,
      shebangLength: 0,
      wrapperLength: 0
    },
    path: 'webpack://B.ts'
  },
  {
    source: CovSource {
      lines: [Array],
      eof: 2275,
      shebangLength: 0,
      wrapperLength: 0
    },
    path: 'webpack://C.ts'
  },
  {
    source: CovSource {
      lines: [Array],
      eof: 15840,
      shebangLength: 0,
      wrapperLength: 0
    },
    path: 'webpack://D.ts'
  },
  {
    source: CovSource {
      lines: [Array],
      eof: 1884,
      shebangLength: 0,
      wrapperLength: 0
    },
    path: 'webpack://E.ts'
  },
  {
    source: CovSource {
      lines: [Array],
      eof: 11237,
      shebangLength: 0,
      wrapperLength: 0
    },
    path: 'webpack://F.ts'
  },
  {
    source: CovSource {
      lines: [Array],
      eof: 11691,
      shebangLength: 0,
      wrapperLength: 0
    },
    path: 'webpack://G.ts'
  }
]

are loaded as this.covSources

this.covSources = []

applyCoverage (blocks) {

When applyCoverage is called, const { startCol, endCol, path, covSource } = this._maybeRemapStartColEndCol(range, isEmptyCoverage) should give me one of the covSource above.
const { startCol, endCol, path, covSource } = this._maybeRemapStartColEndCol(range, isEmptyCoverage)

Based on the current implementation,

 {
    source: CovSource {
      lines: [Array],
      eof: 736,
      shebangLength: 0,
      wrapperLength: 0
    },
    path: 'webpack://A.ts'
  },

let covSource = this.covSources[0].source

will always get return regardless of the block value because it will always use the first object in the list. In my case, the functionName is from webpack://G.ts
Edit: See comment below
"functionName": "",

As a result, all the data are messed up...

@Songyu-Wang Songyu-Wang changed the title [Question] Why are we hardcoding this.covSources[0] in _maybeRemapStartColEndCol function Why are we hardcoding this.covSources[0] in _maybeRemapStartColEndCol function Feb 20, 2024
@Songyu-Wang
Copy link
Author

Apologies, I think I overlooked the code that matching the source
https://github.com/istanbuljs/v8-to-istanbul/blob/4488d10cc9d828c4f6fc0650b04f1909dcbadfff/lib/v8-to-istanbul.js#L230C7-L231C23

In my case, I have a mismatch between webpack://G.ts and webpack://./G.ts
and cause everything to default to this.covSources[0]

Could we add a warning whenever we default to this.covSources[0]?

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