nyc icon indicating copy to clipboard operation
nyc copied to clipboard

nyc merge in nyc@next gives 'Invalid file coverage object, missing keys, found:data'

Open akoidan opened this issue 5 years ago • 9 comments

Link to bug demonstration repository

git clone https://github.com/akoidan/vue-webpack-typescript
git checkout multicov
yarn install
yarn test

Expected Behavior

  • tests are merged, no errors

Observed Behavior

commands in example will run multiple test and then tries to run nyc merge that would fail with error: 'Invalid file coverage object, missing keys, found:data' To be specific

yarn run test:unit
yarn nyc merge ./nyc/.nyc_output_unit/ ./nyc/.nyc_output/unit.json 

results a json like this:

{
  "/home/andrew/WebstormProjects/vue-webpack-typescript/src/utils/classComponentHooks.ts": {
    "data": {
      "path": "/home/andrew/WebstormProjects/vue-webpack-typescript/src/utils/classComponentHooks.ts",
      "statementMap": {
        "0": {
          "start": {
            "line": 4,
            "column": 0
          },
          "end": {
            "line": 8,
            "column": 3
          }
        }
      },
      "fnMap": {},
      "branchMap": {},
      "s": {
        "0": 0
      },
      "f": {},
      "b": {},
      "all": true
    }
  }
}

Environment Information

npx: installed 1 in 0.76s

  System:
    OS: Linux 5.3 Arch Linux undefined
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
    Memory: 5.92 GB / 31.25 GB
  Binaries:
    Node: 12.13.0 - /usr/bin/node
    Yarn: 1.19.1 - /usr/bin/yarn
    npm: 6.12.1 - /usr/bin/npm
  npmPackages:
    @babel/plugin-proposal-class-properties: 7.7.0 => 7.7.0 
    @babel/plugin-proposal-decorators: 7.7.0 => 7.7.0 
    @babel/preset-env: 7.7.1 => 7.7.1 
    babel-loader: 8.0.6 => 8.0.6 
    babel-plugin-istanbul: 5.2.0 => 5.2.0 
    babel-preset-typescript-vue: 1.0.2 => 1.0.2 
    istanbul-lib-coverage: 2.0.5 => 2.0.5 
    nyc: ^15.0.0-beta.0 => 15.0.0-beta.0 
    source-map-support: 0.5.16 => 0.5.16 
    ts-node: 8.5.2 => 8.5.2 
    typescript: 3.7.2 => 3.7.2 

akoidan avatar Nov 18 '19 03:11 akoidan

Please upgrade babel-plugin-istanbul and istanbul-lib-coverage to the next versions otherwise you are combining multiple versions of istanbul libraries. Once you've done that assuming this is still an issue can you please commit all of your .nyc_output directories? Thanks.

coreyfarrell avatar Nov 18 '19 04:11 coreyfarrell

@akoidan I've just released a new beta of nyc which contains at least one fix to source-map processing. Could you give this a try? I've seen TypeError: Cannot read property 'start' of undefined before, it's often the result of merging sources with incompatible source-maps.

Please be aware your issue is a bit difficult as it is so large. If 15.0.0-beta.1 does not work I'd like for you to commit your nyc directory. I'd like to take a look at the HTML report difference you mentioned as well as the raw .nyc_output files.

coreyfarrell avatar Nov 18 '19 16:11 coreyfarrell

Duplication information here for future readers:

With @next the issue seems to be gone from nyc mocha with ts-node, but when I merge 2 outputs from cypress and mocha and then do a report I'm still getting the same issue:

  • git clone https://github.com/akoidan/vue-webpack-typescript
  • git checkout multicov
  • yarn install
  • yarn test
  • cat ./nyc/coverage/src/utils/xhr.ts.html

At least it's always determenistic now, I always get:

TypeError: Cannot read property 'start' of undefined

Note that if you check

  • ./nyc/coverage_cypress/src/utils/xhr.ts.html
  • ./nyc/coverage_unit/xhr.ts.html

they are both ok. And it's werid that the format of output html is different

akoidan avatar Nov 18 '19 16:11 akoidan

@coreyfarrell You can always get the report by runnign steps I specified above. Anyway I commited the files as you asked (mind the branch nyc):

https://github.com/akoidan/vue-webpack-typescript/tree/nyc/issues/1226/nyc

akoidan avatar Nov 18 '19 16:11 akoidan

@coreyfarrell any updates? Do you need any help from my side?

akoidan avatar Nov 25 '19 23:11 akoidan

@akoidan I'm very busy so I have to ask for your patience.

coreyfarrell avatar Nov 26 '19 23:11 coreyfarrell

@coreyfarrell any updates? ^^

akoidan avatar Oct 01 '20 15:10 akoidan

I'm running into this issue as well.

Maximus1285 avatar Oct 27 '20 04:10 Maximus1285

I was able to resolve this by just updating babel-plugin-istanbul with yarn up -R babel-plugin-istanbul. Cypress's code coverage package hard locks us to [email protected], but the fact that the other dependencies used 3.2.x did not impact this.

The found:data error was a result of one babel-plugin-istanbul being 6.0 and the other being 6.1.

EDIT: For a second project, I had to upgrade both via yarn up -R babel-plugin-istanbul istanbul-lib-coverage.

quisido avatar Dec 22 '21 18:12 quisido