Skip to content

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

@butlermd

Description

@butlermd

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions