vue-jest
vue-jest copied to clipboard
Coverage isn't calculated properly for non-SFC
Version
3.0.5
Reproduction link
https://github.com/dmitriykirpa/vue-cli-jest-coverage-example
Environment info
System:
OS: macOS 10.15.4
CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Binaries:
Node: 14.2.0 - /usr/local/bin/node
Yarn: 1.21.0 - /usr/local/bin/yarn
npm: 6.14.4 - /usr/local/bin/npm
Browsers:
Chrome: 81.0.4044.138
Firefox: 70.0.1
Safari: 13.1
npmPackages:
@vue/cli-overlay: 4.3.1
@vue/cli-plugin-eslint: ^4.3.0 => 4.3.1
@vue/cli-plugin-router: 4.3.1
@vue/cli-plugin-unit-jest: ^4.3.0 => 4.3.1
@vue/cli-plugin-vuex: 4.3.1
@vue/cli-service: ^4.3.0 => 4.3.1
@vue/cli-shared-utils: 4.3.1
@vue/component-compiler-utils: 3.1.2
@vue/eslint-config-prettier: ^6.0.0 => 6.0.0
@vue/preload-webpack-plugin: 1.1.1
@vue/test-utils: 1.0.0-beta.31 => 1.0.0-beta.31
@vue/web-component-wrapper: 1.2.0
eslint-plugin-vue: ^6.2.2 => 6.2.2
jest-serializer-vue: 2.0.2
vue: ^2.6.11 => 2.6.11
vue-eslint-parser: 7.1.0
vue-hot-reload-api: 2.3.4
vue-jest: 3.0.5
vue-loader: 15.9.2
vue-style-loader: 4.1.2
vue-template-compiler: ^2.6.11 => 2.6.11
vue-template-es2015-compiler: 1.9.1
npmGlobalPackages:
@vue/cli: Not Found
Steps to reproduce
- Create a new
vue-cli
project (or configure it manually) withvue-jest
configured. - Move the
script
section from thesrc/components/HelloWorld.vue
to a separate filescript.js
. - Add the
<script src="./script.js" />
tosrc/components/HelloWorld.vue
- Run
yarn/npm run test:unit --coverage
- Observe the result.
What is expected?
Coverage for script.js
calculated properly
What is actually happening?
Coverage for script.js
is 0
Hi! Thanks fore this.
I started to work on this repo (around 1 month? 2 months?) ago. I am not super familiar with how this all works yet, but I would like to start digging into it more and closing out some of these long standing issues.
Happy to help out if you would like to give it a shot, too.
Same error.
I'm using @vue/cli-plugin-unit-jest
, with this jest.config.js
:
module.exports = {
preset : '@vue/cli-plugin-unit-jest',
transformIgnorePatterns : ['node_modules/(?!(?:@babel|place|folders|here))'],
setupFilesAfterEnv : ['./tests/unit/jest.setup.js'],
collectCoverage : true,
collectCoverageFrom : ['src/**/*.{js,vue}', '!**/__DEMO/**', '!**/vendor/**'],
coverageDirectory : '<rootDir>/coverage',
coveragePathIgnorePatterns : ['/node_modules/', '/src/main.m?js', '/src/index.m?js', '/src/lang', '/src/locale', '/__DEMO/', '/src/manage/'],
coverageThreshold : {
global : {
branches : 90,
functions : 90,
lines : 90,
statements : -10
}
}
};
When i run test everything is ok but coverage report not show correct info.
If i see html report file .vue
contains js code and 100% passed, and .js
file is marked like not passed.
Summary:
file .vue:
file .js:
I'm experiencing the same issue, has there been any progress on this?
Which version of vue-jest are you using @jrkienle ? 3 or 4 (or 5?)
same issue is using vue-jest v3.0.6
Can you please upgrade to v4 and see how that goes? That is the latest version (works with Vue 2).
Same problem for me, I'm using v4.0.0 beta 6.
Same with v5...
If anyone is super motivated to tackle this I can try to help out, I have many other higher priority bugs like proper TS support, releasing Test Utils v2, etc, so I was not able to tackle this.
As far as I can see it's (mostly) working ok for SFCs? Is this just for non sfc components? Is the main use case JSX/TSX?