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.

Code Coverage missing for all but one file and it's listing the imports as missing coverage

See original GitHub issue

I made sure I updated vue-jest and jest to latest versions with no success.

I have a file structure that looks roughly like this (abstracting the names to simplify)

src
  |- components
     |- module-A
        |- Component1.vue
        |- Component2.vue
     |- module-B
        |- sub-module-C
           |- Component3.vue
        |- sub-module-D
           |- Component4.vue

In this case, all components are SCF .vue files and Component1.vue is the only one showing up in coverage. It looks like this

<template>
  <div>
    ...
  </div>
</template>

<script>
  import Component3 from '../module-B/sub-module-C/Component3';
  import Component3 from '../module-B/sub-module-C/Component3';

  export default {
    components: { Component3, Component3 },
    name: 'age',
  };
</script>

While the coverage looks like this

-----------------|----------|----------|----------|----------|-------------------|
File             |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
-----------------|----------|----------|----------|----------|-------------------|
All files        |        0 |      100 |      100 |        0 |                   |
 Component1.vue  |        0 |      100 |      100 |        0 |          8,9      |
-----------------|----------|----------|----------|----------|-------------------|

So, clearly, it’s not reading this file correctly for coverage purposes.

This is my jest.conf.js. It’s mostly the normal one generated by vue init.

module.exports = {
  rootDir: __dirname,
  moduleFileExtensions: [
    'js',
    'json',
    'vue',
  ],
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/src/$1',
  },
  transform: {
    '^.+\\.js$': '<rootDir>/node_modules/babel-jest',
    '.*\\.(vue)$': '<rootDir>/node_modules/vue-jest',
  },
  testPathIgnorePatterns: [
    '<rootDir>/test/e2e',
  ],
  testRegex: 'src/.*\\.spec\\.js$',
  snapshotSerializers: ['<rootDir>/node_modules/jest-serializer-vue'],
  setupFiles: ['<rootDir>/test/unit/setup'],
  mapCoverage: true,
  coverageDirectory: '<rootDir>/test/unit/coverage',
  collectCoverageFrom: [
    'src/**/*.{js,vue}',
    '!src/**/*.spec.js',
    '!src/main.js',
    '!src/router/index.js',
    '!**/node_modules/**',
  ],
};

The only thing strange I’m doing is putting my tests in the same folder as the files they’re testing. It’s unusual for jest and vue perhaps, but if anything, I’d expect it would give me too much coverage in the report, not too little.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
maxpoucommented, Mar 3, 2018

Hi, this issue is related to #32 (and I just fix this coverage issue).

0reactions
eddyerburghcommented, Jan 6, 2019

I’ve release 4.0.0-beta.0. Please use that version to see if it fixes the coverage issue. If not, please create a new issue with a runnable reproduction.

This issue is being tracked in https://github.com/vuejs/vue-jest/issues/56

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python code coverage missing when files have the same name
This issue is mentioned here. So to fix this you can run python -m pytest -v tests --cov --cov-report=xml:coverage.xml .
Read more >
[Coverage missing]On Sonarqube Coverage is not showing ...
So I can see that module is appearing in Jenkins but code coverage is not showing up in SonarQube. Any help please?
Read more >
Code Coverage Results are incomplete
But even then the code coverage results had some gaps (missing coverage from one project, significant drop in coverage for another project).
Read more >
The Coverage class — Coverage.py 6.5.0 documentation
Coverage (data_file=MISSING, data_suffix=None, cover_pylib=None, ... Only code located in the trees indicated by the file paths or package names will be ...
Read more >
Test Coverage Troubleshooting Tips - Code Climate
If you've only setup the test reporter on a feature branch, then reports won't be uploaded for the default branch. If you're successfully...
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