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

Merging v8 coverage and istanbul coverage gives NaN #144

Open
dmail opened this issue May 3, 2021 · 0 comments
Open

Merging v8 coverage and istanbul coverage gives NaN #144

dmail opened this issue May 3, 2021 · 0 comments
Labels

Comments

@dmail
Copy link

dmail commented May 3, 2021

Hell there,

I am merging two coverages: first come from v8 and was converted to istanbul format, second from istanbul itself.

When I merge the two with the following code, I end up with incorrect data

const { createCoverageMap } = require("istanbul-lib-coverage")

const istanbulCoverageMap = createCoverageMap()
istanbulCoverageMap.merge(coverageFromIstanbul)
istanbulCoverageMap.merge(coverageFromV8ConvertedToIstanbul)

const mergeResult = {}
const coverageMapData = istanbulCoverageMap.toJSON()
Object.keys(coverageMapData).forEach((key) => {
  mergeResult[key] = coverageMapData[key].toJSON()
})

image

coverageFromIstanbul
{
  "./test/coverage/coverage-universal/file.js": {
    "path": "./test/coverage/coverage-universal/file.js",
    "statementMap": {
      "0": {
        "start": {
          "line": 2,
          "column": 0
        },
        "end": {
          "line": 8,
          "column": 1
        }
      },
      "1": {
        "start": {
          "line": 3,
          "column": 2
        },
        "end": {
          "line": 3,
          "column": 24
        }
      },
      "2": {
        "start": {
          "line": 4,
          "column": 7
        },
        "end": {
          "line": 8,
          "column": 1
        }
      },
      "3": {
        "start": {
          "line": 5,
          "column": 2
        },
        "end": {
          "line": 5,
          "column": 21
        }
      },
      "4": {
        "start": {
          "line": 7,
          "column": 2
        },
        "end": {
          "line": 7,
          "column": 22
        }
      }
    },
    "fnMap": {},
    "branchMap": {
      "0": {
        "loc": {
          "start": {
            "line": 2,
            "column": 0
          },
          "end": {
            "line": 8,
            "column": 1
          }
        },
        "type": "if",
        "locations": [
          {
            "start": {
              "line": 2,
              "column": 0
            },
            "end": {
              "line": 8,
              "column": 1
            }
          },
          {
            "start": {
              "line": 2,
              "column": 0
            },
            "end": {
              "line": 8,
              "column": 1
            }
          }
        ],
        "line": 2
      },
      "1": {
        "loc": {
          "start": {
            "line": 4,
            "column": 7
          },
          "end": {
            "line": 8,
            "column": 1
          }
        },
        "type": "if",
        "locations": [
          {
            "start": {
              "line": 4,
              "column": 7
            },
            "end": {
              "line": 8,
              "column": 1
            }
          },
          {
            "start": {
              "line": 4,
              "column": 7
            },
            "end": {
              "line": 8,
              "column": 1
            }
          }
        ],
        "line": 4
      }
    },
    "s": {
      "0": 1,
      "1": 1,
      "2": 0,
      "3": 0,
      "4": 0
    },
    "f": {},
    "b": {
      "0": [
        1,
        0
      ],
      "1": [
        0,
        0
      ]
    },
    "_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9",
    "hash": "499a0b791cd32d6c8667bf5875758fd5f3ec4ff0"
  }
}
coverageFromV8ConvertedToIstanbul
{
  "./test/coverage/coverage-universal/file.js": {
    "path": "./test/coverage/coverage-universal/file.js",
    "all": false,
    "statementMap": {
      "0": {
        "start": {
          "line": 1,
          "column": 0
        },
        "end": {
          "line": 1,
          "column": 30
        }
      },
      "1": {
        "start": {
          "line": 2,
          "column": 0
        },
        "end": {
          "line": 2,
          "column": 33
        }
      },
      "2": {
        "start": {
          "line": 3,
          "column": 0
        },
        "end": {
          "line": 3,
          "column": 24
        }
      },
      "3": {
        "start": {
          "line": 4,
          "column": 0
        },
        "end": {
          "line": 4,
          "column": 41
        }
      },
      "4": {
        "start": {
          "line": 5,
          "column": 0
        },
        "end": {
          "line": 5,
          "column": 21
        }
      },
      "5": {
        "start": {
          "line": 6,
          "column": 0
        },
        "end": {
          "line": 6,
          "column": 8
        }
      },
      "6": {
        "start": {
          "line": 7,
          "column": 0
        },
        "end": {
          "line": 7,
          "column": 22
        }
      },
      "7": {
        "start": {
          "line": 8,
          "column": 0
        },
        "end": {
          "line": 8,
          "column": 1
        }
      }
    },
    "s": {
      "0": 1,
      "1": 1,
      "2": 0,
      "3": 1,
      "4": 1,
      "5": 1,
      "6": 0,
      "7": 0
    },
    "branchMap": {
      "0": {
        "type": "branch",
        "line": 1,
        "loc": {
          "start": {
            "line": 1,
            "column": 0
          },
          "end": {
            "line": 8,
            "column": 1
          }
        },
        "locations": [
          {
            "start": {
              "line": 1,
              "column": 0
            },
            "end": {
              "line": 8,
              "column": 1
            }
          }
        ]
      },
      "1": {
        "type": "branch",
        "line": 2,
        "loc": {
          "start": {
            "line": 2,
            "column": 32
          },
          "end": {
            "line": 4,
            "column": 1
          }
        },
        "locations": [
          {
            "start": {
              "line": 2,
              "column": 32
            },
            "end": {
              "line": 4,
              "column": 1
            }
          }
        ]
      },
      "2": {
        "type": "branch",
        "line": 6,
        "loc": {
          "start": {
            "line": 6,
            "column": 1
          },
          "end": {
            "line": 8,
            "column": 1
          }
        },
        "locations": [
          {
            "start": {
              "line": 6,
              "column": 1
            },
            "end": {
              "line": 8,
              "column": 1
            }
          }
        ]
      }
    },
    "b": {
      "0": [
        1
      ],
      "1": [
        0
      ],
      "2": [
        0
      ]
    },
    "fnMap": {},
    "f": {}
  }
}
mergeResult
{
  "./test/coverage/coverage-universal/file.js": {
    "path": "./test/coverage/coverage-universal/file.js",
    "statementMap": {
      "0": {
        "start": {
          "line": 2,
          "column": 0
        },
        "end": {
          "line": 8,
          "column": 1
        }
      },
      "1": {
        "start": {
          "line": 3,
          "column": 2
        },
        "end": {
          "line": 3,
          "column": 24
        }
      },
      "2": {
        "start": {
          "line": 4,
          "column": 7
        },
        "end": {
          "line": 8,
          "column": 1
        }
      },
      "3": {
        "start": {
          "line": 5,
          "column": 2
        },
        "end": {
          "line": 5,
          "column": 21
        }
      },
      "4": {
        "start": {
          "line": 7,
          "column": 2
        },
        "end": {
          "line": 7,
          "column": 22
        }
      }
    },
    "fnMap": {},
    "branchMap": {
      "0": {
        "loc": {
          "start": {
            "line": 2,
            "column": 0
          },
          "end": {
            "line": 8,
            "column": 1
          }
        },
        "type": "if",
        "locations": [
          {
            "start": {
              "line": 2,
              "column": 0
            },
            "end": {
              "line": 8,
              "column": 1
            }
          },
          {
            "start": {
              "line": 2,
              "column": 0
            },
            "end": {
              "line": 8,
              "column": 1
            }
          }
        ],
        "line": 2
      },
      "1": {
        "loc": {
          "start": {
            "line": 4,
            "column": 7
          },
          "end": {
            "line": 8,
            "column": 1
          }
        },
        "type": "if",
        "locations": [
          {
            "start": {
              "line": 4,
              "column": 7
            },
            "end": {
              "line": 8,
              "column": 1
            }
          },
          {
            "start": {
              "line": 4,
              "column": 7
            },
            "end": {
              "line": 8,
              "column": 1
            }
          }
        ],
        "line": 4
      }
    },
    "s": {
      "0": 2,
      "1": 2,
      "2": 0,
      "3": 1,
      "4": 1,
      "5": NaN,
      "6": NaN,
      "7": NaN
    },
    "f": {},
    "b": {
      "0": [
        2,
        NaN
      ],
      "1": [
        0,
        NaN
      ],
      "2": [
        0
      ]
    },
    "_coverageSchema": "1a1c01bbd47fc00a2c39e90264f33305004495a9",
    "hash": "499a0b791cd32d6c8667bf5875758fd5f3ec4ff0"
  }
}

The v8 coverage comes from executing the file on Node.js with NODE_V8_COVERAGE enabled.
The istanbul coverage comes from executing a file instrumented by istanbul on Firefox.

The file source code is here

if (typeof window === "object") {
  console.log("browser")
} else if (typeof process === "object") {
  console.log("node")
} else {
  console.log("other")
}
dmail pushed a commit to jsenv/core that referenced this issue May 3, 2021
dmail pushed a commit to jsenv/core that referenced this issue May 4, 2021
By default node v8 will be preferred to collect coverage. Padding coveragePreferIstanbul is meant to be used if multiple coverage sources are used and some of these sources report using istanbul format. This is because both formats are incompatible. See istanbuljs/v8-to-istanbul#144
@bcoe bcoe added the bug label May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants