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

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

Closed
butlermd opened this issue Feb 22, 2018 · 8 comments
Labels

Comments

@butlermd
Copy link

butlermd commented Feb 22, 2018

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.

@butlermd
Copy link
Author

So, a couple updates. First, the weirdness of it reporting imports as uncovered lines disappeared at some point. And in fact, the coverage is working well for all the files I have one directory down from components--but still not for the ones that are two directories down.

@giubatt
Copy link

giubatt commented Feb 27, 2018

I had a similar problem, I found this: vire/jest-vue-preprocessor#43
My component didn't have a style tag, and after adding an empty one it started showing up on the coverage. Maybe that helps?

@maxpou
Copy link

maxpou commented Mar 3, 2018

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

@eddyerburgh
Copy link
Member

@butlermd I've removed cacheing in v2.1.1, can you see if this fixed your issue.

@butlermd
Copy link
Author

butlermd commented Mar 5, 2018

I tried @barterr's suggestion to no avail (I also was missing the style tag in a few unneeded components, but it didn't change anything) and I updated to v2.1.1 per @eddyerburgh's request. No difference.

@baldore
Copy link

baldore commented Nov 14, 2018

I'm having the same problem. If for the date exists a solution, please share it. Thanks.

@sebastianjung
Copy link

sebastianjung commented Nov 18, 2018

same here.
Imports are listed as missing coverage and the index.html coverage output only shows one file.

Strangely the reports of all the other files are existent as html files in subfolders.

@eddyerburgh
Copy link
Member

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 #56

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

6 participants