jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.08k stars 6.45k forks source link

Failed to Write Coverage Reports:Cannot read property 'loc' of undefined #9659

Closed semihural closed 1 year ago

semihural commented 4 years ago

We are getting this error when trying to run a coverage report whilejest --coverage --ci --coverageDirectory=output/coverage/jest is running in CI. We are trying to publish reports via cobertura in our CI and using yarn to install jest.

Error

 Failed to write coverage reports:
        ERROR: TypeError: Cannot read property 'loc' of undefined
        STACK: TypeError: Cannot read property 'loc' of undefined
    at /home/ubuntu/workspace/oneapihub-ui@2/node_modules/istanbul-reports/lib/lcovonly/index.js:52:27
    at Array.forEach (<anonymous>)
    at LcovOnlyReport.onDetail (/home/ubuntu/workspace/oneapihub-ui@2/node_modules/istanbul-reports/lib/lcovonly/index.js:49:27)

Below contains some part of package.json configuration.

{
    "name": "ui",
    "version": "1.0.0",
"scripts": {
        "dev": "webpack-dev-server --inline --config ui-build/webpack.dev.conf.js",
        "test:dev": "jest --coverage --ci --coverageDirectory=output/coverage/jest",
        "e2e": "node test/e2e/runner.js --startSelenium",
        "e2e-gitlab": "node test/e2e/runner.js",
        "e2e-localhost": "node test/e2e/runner.js --startSelenium --scheme http --target 127.0.0.1:3000 --skiptags no-localhost"
    },
    "jest": {
        "collectCoverage": true,
        "testResultsProcessor": "./node_modules/jest-slack-reporter",
        "coverageReporters": [
          "text",
          "html",
          "lcov",
          "cobertura",
          "json"
        ]
    },
    "jestSlackReporter": {
        "webhookUrl": "https://hooks.slack.com/services/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"
    }
    "devDependencies": {
        "@applitools/eyes-images": "^4.12.20",
        "@testing-library/jest-dom": "^5.1.1",
        "@vue/test-utils": "^1.0.0-beta.29",
        "autoprefixer": "^8.0.0",
        "babel-core": "^6.26.0",
        "babel-eslint": "^8.1.2",
        "babel-jest": "^23.6.0",
        "babel-loader": "^7.1.5",
        "babel-plugin-dynamic-import-node": "^2.2.0",
        "babel-plugin-istanbul": "^4.1.5",
        "babel-plugin-module-resolver": "^3.1.1",
        "babel-plugin-transform-runtime": "^6.22.0",
We were able to display coverage reports as below in CI expectation is display or publish this report via cobertura.

File                                                                        |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
----------------------------------------------------------------------------|----------|----------|----------|----------|-------------------|
All files                                                                   |    78.37 |    74.32 |    78.93 |     82.2 |                   |
 root                                                                       |        0 |        0 |        0 |        0 |                   |
  unknown                                                                   |        0 |        0 |        0 |        0 |                   |
 root/home/ubuntu/workspace/oneapihub-ui@2/backend-mock/services            |      100 |      100 |      100 |      100 |                   |
  utils.js                                                                  |      100 |      100 |      100 |      100 |                   |
 root/home/ubuntu/workspace/oneapihub-ui@2/src/assets/img/icons             |        0 |        0 |        0 |        0 |                   |
  pointing-hand.svg                                                         |        0 |        0 |        0 |        0 |                   |
 root/home/ubuntu/workspace/oneapihub-ui@2/src/assets/swagger-ui-plugins    |      100 |       75 |      100 |      100 |                   |
  InfoBasePathPlugin.jsx                                                    |      100 |      100 |      100 |      100 |                   |
  InfoUrlPlugin.jsx                                                         |      100 |       75 |      100 |      100 |                 9 |
  UpdateBasePathPlugin.jsx                                                  |      100 |       75 |      100 |      100 |                22 |
 root/home/ubuntu/workspace/oneapihub-ui@2/src/components/api               |    86.74 |    76.74 |    84.33 |     86.9 |                   |
  ApiLabelDealer.vue                                                        |      100 |      100 |      100 |      100 |                   |
  ApiService.js                                                             |      100 |      100 |      100 |      100 |                   |
  Details.vue                                                               |    73.12 |    73.02 |    68.97 |    74.44 |... 33,355,356,400 |
  Overview.vue                                                              |      100 |      100 |      100 |      100 |                   |
  OverviewTableRow.vue                                                      |    38.24 |    21.05 |    22.22 |    36.36 |... 01,103,110,111 |
  ProductList.vue                                                           |    80.43 |    83.33 |    72.73 |    79.55 |... 13,114,118,119 |
  RatingAllUsers.vue                                                        |      100 |       75 |      100 |      100 |                64 |
  RatingPerStar.vue                                                         |      100 |      100 |      100 |      100 |                   |
  RatingSubmitDialog.vue                                                    |      100 |      100 |      100 |      100 |                   |
  RatingUserFlow.vue                                                        |      100 |      100 |      100 |      100 |                   |
  RatingUserListing.vue                                                     |      100 |       75 |      100 |      100 |                99 |
  RefreshDialog.vue                                                         |      100 |      100 |      100 |      100 |                   |
  SubscribeDialog.vue                                                       |    93.88 |    85.71 |       95 |    93.55 |... 23,325,334,335 |
  Tryout.vue                                                                |    91.67 |    85.71 |      100 |    93.48 |          70,75,76 |
  VersionSelection.vue                                                      |    86.49 |       70 |    90.91 |    87.88 |       92,93,98,99 |
 root/home/ubuntu/workspace/oneapihub-ui@2/src/components/app               |    88.85 |    78.08 |    87.21 |    88.44 |                   |
  ApikeyCredential.vue                                                      |       50 |      100 |        0 |       50 |       54,55,60,61 |
  AppCredential.vue                                                         |    90.48 |    85.71 |      100 |       90 |             85,86 |

Test Suites: 6 failed, 66 passed, 72 total Tests: 15 failed, 522 passed, 537 total Snapshots: 0 total Time: 104.477s Ran all test suites. error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Light-Keeper commented 4 years ago

I had the same issue and worked around by changing the list of report formats. text and html was enough for my use case.

coverageReporters: [
    'text',
    'html'
  ]
peterdemartini commented 4 years ago

I am getting this same error

penx commented 4 years ago

Issue raised against istanbul here: https://github.com/istanbuljs/istanbuljs/issues/572

If anyone has a better idea of what's going on please add a comment on the ticket.

bencooper222 commented 3 years ago

I'm getting it when I run jest with the --ci and --runInBand option (both locally and in CI). I do not get it when I don't use both of those. It's possible only one of those is causing the error, I haven't isolated the problem yet, but I know the combination is causing the error for me.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] commented 1 year ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.