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.

collectCoverage not collecting from all files

See original GitHub issue

package.json

    "@babel/plugin-transform-runtime": "^7.2.0",
    "@babel/preset-env": "^7.3.1",
    "@commitlint/cli": "^7.3.2",
    "@commitlint/config-conventional": "^7.3.1",
    "@vue/cli-plugin-babel": "^3.4.0",
    "@vue/cli-plugin-eslint": "^3.4.0",
    "@vue/cli-plugin-unit-jest": "^3.4.0",
    "@vue/cli-service": "^3.4.0",
    "@vue/eslint-config-prettier": "^4.0.1",
    "@vue/eslint-config-standard": "^4.0.0",
    "@vue/test-utils": "^1.0.0-beta.20",
    "babel-core": "7.0.0-bridge.0",
    "babel-eslint": "^10.0.1",
    "babel-jest": "^23.6.0",
    "eslint": "^5.8.0",
    "eslint-plugin-jest": "^22.2.2",
    "eslint-plugin-vue": "^5.0.0",
    "jest-junit": "^6.0.1",
    "jest-transform-stub": "^1.0.0",
    "jest-vue-preprocessor": "^1.4.0",
    "node-sass": "^4.11.0",
    "prettier": "^1.15.3",
    "sass-loader": "^7.1.0",
    "vue-jest": "^4.0.0-beta.0",
    "vue-template-compiler": "^2.5.21"

jest.config.js

module.exports = {
  moduleFileExtensions: ['js', 'json', 'vue'],
  transform: {
    '^.+\\.vue$': '<rootDir>/node_modules/vue-jest',
    '.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': '<rootDir>/node_modules/jest-transform-stub',
    '^.+\\.js?$': '<rootDir>/node_modules/babel-jest',
  },
  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/src/$1',
  },
  roots: ['<rootDir>/src/'],
  collectCoverage: true,
  coverageDirectory: '<rootDir>/reports/coverage',
  reporters: ['default', ['jest-junit', { output: './reports/junit.xml' }]],
  coverageReporters: ['json-summary', 'lcov', 'text', 'text-summary'],
  collectCoverageFrom: ['**/*.{js,vue}'],
  cache: false,
  snapshotSerializers: ['jest-serializer-vue'],
  testURL: 'http://localhost/',
  testMatch: ['**/__tests__/**/*.js', '**/?(*.)+(spec|test).js'],
  globals: {
    'vue-jest': {
      babelConfig: '<rootDir>/.babelrc',
    },
    __DEV__: true,
    CSInterface: class CSInterface {},
  },
};

.babelrc

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "modules": false,
        "targets": {
          "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
        }
      }
    ]
  ],
  "plugins": ["@babel/plugin-transform-runtime"],
  "env": {
    "test": {
      "presets": ["@babel/preset-env"]
    }
  }
}

I’m using the command vue-cli-service test:unit --no-cache to run tests. All the tests run, but coverage is not collected from anything in the component subdir from within src. This means most of my tests are not collecting coverage.

I’m also having an issue with the jest global I have set up in my jest config not actually working. Nothing I do to my set up seems to fix either of these issues.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
matsieftwcommented, Feb 18, 2019

Sorry, I cannot provide a repo.

Solution to the problem for anyone coming here later:

If your component is stateless/does not have runnable JS in the file, vue-jestwill not run tests on the component.

To work around this, you must add dummy data to your component so vue-jest will run the associated tests for that component.

  data() {
    return {};
  },
0reactions
eddyerburghcommented, Feb 18, 2019

Yes the fix was in beta.1, current version is beta.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest finds tests but doesn't collect coverage - Stack Overflow
I think it's related to this issue '--coverage --watch' should calculate coverage for all files at first iteration and also this issue No ......
Read more >
Configuring Jest to show code coverage for all of your files
js in the root of your project and drop this in there: module.exports = { collectCoverage: true, ...
Read more >
Generating code coverage report in Jest
From this config file, we can see that coverage will not be collected automatically (collectCoverage: false), the report will be generated ...
Read more >
Jest CLI Options
You can run jest --help to view all available options. ... to rootDir matching the files that coverage info needs to be collected...
Read more >
Collect Coverage in Tests - MATLAB & Simulink - MathWorks
However, you can turn off coverage collection for individual test suites and test cases. Note. The Test Manager inherits all coverage settings in...
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