Skip to content

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

@Songyu-Wang

Description

@Songyu-Wang

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions