question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Source map files disappear from coverage report

See original GitHub issue

Hi,

I’m getting coverage issues with Jest. When I set mapCoverage: true, some files disapear from the coverage report.

Example:

# mapCoverage:true
src/api                |      100 |      100 |      100 |      100 |                |
  index.js             |      100 |      100 |      100 |      100 |                |
  linkHeaderParser.js  |      100 |      100 |      100 |      100 |                |
  repositories.js      |      100 |      100 |      100 |      100 |                |
src/components         |     7.84 |     2.94 |     5.88 |    11.76 |                |
  FileExplorer.vue     |        0 |        0 |        0 |        0 |... 51,52,53,54 |
  MenuUserRepoList.vue |        0 |        0 |        0 |        0 |... 32,33,34,35 |
  Profile.vue          |        0 |        0 |        0 |        0 |... 57,58,59,60 |
  Readme.vue           |       80 |       50 |       50 |       80 |             23 |

# mapCoverage:false
src/api                |    92.86 |    84.21 |      100 |    92.86 |                |
  index.js             |    84.62 |    66.67 |      100 |    84.62 |          10,26 |
  linkHeaderParser.js  |      100 |      100 |      100 |      100 |                |
  repositories.js      |      100 |      100 |      100 |      100 |                |
  users.js             |      100 |      100 |      100 |      100 |                |
src/components         |     53.4 |    29.73 |    40.74 |    51.61 |                |
  FileExplorer.vue     |        0 |        0 |        0 |        0 |... 51,52,53,54 |
  FooterBar.vue        |    92.86 |       50 |      100 |      100 |        4,5,6,7 |
  MenuNavBar.vue       |      100 |       50 |      100 |      100 |       20,21,22 |
  MenuUserRepoList.vue |        0 |        0 |        0 |        0 |... 32,33,34,35 |
  Profile.vue          |        0 |        0 |        0 |        0 |... 57,58,59,60 |
  Readme.vue           |    94.74 |    57.14 |       80 |    92.86 |             25 |
  RepoListItem.vue     |      100 |       50 |    66.67 |      100 |       45,46,47 |

(I remove some file for a better readability. See full coverage report (link to travis build):

All sources files are available here: https://github.com/maxpou/gitvub and jest config here

Thank you

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:15
  • Comments:42 (5 by maintainers)

github_iconTop GitHub Comments

49reactions
nirkkicommented, Jan 30, 2018

Looks like the missing files lack the data property. If the component doesn’t have the data segment it is dropped from the coverage report. Adding an empty segment is enough to get it included.

export default {
  name: 'HelloWorld',
  props: {
    msg: { type: String, default: 'Welcome to Your Vue.js App' }
  },
  data () {
    return {}
  }
}
3reactions
kaidjohnsoncommented, Oct 25, 2018

I have been dealing with this issue setting up a new project. It can be reproduced using the latest vue-cli (3.0.5) and following the “Creating a Project” guide (https://cli.vuejs.org/guide/creating-a-project.html#vue-create).

vue create hello-world
> Manually select features
(x) Babel
(x) Unit Testing
> Jest
> In dedicated config files

Edit jest.config.js and add:

  collectCoverage: true,
  collectCoverageFrom: ['src/**/*.{js,vue}'],
  coverageReporters: ['text'],

Run npm run test:unit

Notice that HelloWorld.vue is missing from the test report.

Edit components/HelloWorld.vue and add in an empty data segment

data() {
  return {};
}

Run npm run test:unit again

Notice that HelloWorld.vue suddenly appears with its test coverage.

Thanks @nirkki for the workaround!! I have been parsing bug reports all evening with no luck as to what was causing this missing coverage.

The package.json that results from the vue-cli build:

{
  "name": "hello-world",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "test:unit": "vue-cli-service test:unit"
  },
  "dependencies": {
    "vue": "^2.5.17"
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^3.0.5",
    "@vue/cli-plugin-unit-jest": "^3.0.5",
    "@vue/cli-service": "^3.0.5",
    "@vue/test-utils": "^1.0.0-beta.20",
    "babel-core": "7.0.0-bridge.0",
    "babel-jest": "^23.0.1",
    "vue-template-compiler": "^2.5.17"
  }
}

It’s not a vue-cli issue, either, as I originally ran across the bug with a manual setup. In that scenario, the empty data segment also fixed the issue. That package json looks like:

{
  "name": "new-project",
  "version": "0.0.1",
  "description": "",
  "scripts": {
    "build": "webpack",
    "dev": "webpack-dev-server",
    "lint": "eslint 'src/**/*.{js,vue}'",
    "test": "jest",
    "tdd": "jest --watchAll"
  },
  "devDependencies": {
    "@babel/core": "7.1.2",
    "@babel/plugin-syntax-dynamic-import": "7.0.0",
    "@babel/preset-env": "7.1.0",
    "@vue/test-utils": "1.0.0-beta.25",
    "babel-core": "7.0.0-bridge.0",
    "babel-eslint": "10.0.1",
    "babel-jest": "23.6.0",
    "babel-loader": "8.0.4",
    "clean-webpack-plugin": "0.1.19",
    "eslint": "5.7.0",
    "eslint-plugin-jest": "21.26.1",
    "eslint-plugin-vue": "4.7.1",
    "html-webpack-plugin": "3.2.0",
    "jest": "23.6.0",
    "redux": "4.0.1",
    "reselect": "4.0.0",
    "vue": "2.5.17",
    "vue-cli": "2.9.6",
    "vue-jest": "3.0.0",
    "vue-loader": "15.4.2",
    "vue-router": "3.0.1",
    "vue-template-compiler": "2.5.17",
    "webpack": "4.22.0",
    "webpack-cli": "3.1.2",
    "webpack-dev-server": "3.1.10"
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Missing .vue file in coverage report - Stack Overflow
I use vue-cli 3.0 to create my project, and I use istanbul-instrumenter-loader to create my coverage, but I can't find vue file.
Read more >
JavaScript source map upload - Bugsnag docs
Uploaded source maps can be viewed and deleted by going to Project Settings -> Source maps. Do the uploaded source maps get applied...
Read more >
Debug Angular apps in production without revealing source ...
The source map contains a file property which points to the original file the source map belongs to. If we built our app...
Read more >
ng test - Angular
Option Description Value Type Defau... ‑‑browsers Override which browsers tests are run against. string ‑‑code‑coverage Output a code coverage report. boolean false ‑‑code‑coverage‑exclude Globs to exclude...
Read more >
Source map errors — Firefox Source Docs documentation
Source maps are JSON files providing a way to associate transformed sources, as seen by the ... The source map resource can be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found