Open merlinstardust opened 1 year ago
Hello @merlinstardust. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with need reproduction
will be closed if they have no activity within 3 days.
@AriPerkkio Here's a minimal reproduction repo with PR
https://github.com/merlinstardust/coverage-zero-vitest-example/pull/1
Vue compiler is outputting source maps which are off by one line. This is similar as https://github.com/vitest-dev/vitest/discussions/2874 and https://github.com/vuejs/vue-loader/issues/1778.
Here is what Vue is generating from BottomButtonNav.vue
:
const _sfc_main = {}
import { renderSlot as _renderSlot, createElementVNode as _createElementVNode, openBlock as _openBlock, createElementBlock as _createElementBlock, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from "vue"
const _withScopeId = n => (_pushScopeId("data-v-3da707db"),n=n(),_popScopeId(),n)
const _hoisted_1 = { class: "row bottom-button-nav" }
const _hoisted_2 = {
class: "row left-container",
"data-testid": "left-container"
}
const _hoisted_3 = {
class: "row right-container",
"data-testid": "right-container"
}
function _sfc_render(_ctx, _cache) {
return (_openBlock(), _createElementBlock("div", _hoisted_1, [
_createElementVNode("div", _hoisted_2, [
_renderSlot(_ctx.$slots, "leftSide", {}, undefined, true)
]),
_createElementVNode("div", _hoisted_3, [
_renderSlot(_ctx.$slots, "rightSide", {}, undefined, true)
])
]))
}
import "/x/y/coverage-zero-vitest-example/src/components/BottomButtonNav.vue?vue&type=style&index=0&scoped=3da707db&lang.css"
import _export_sfc from 'plugin-vue:export-helper'
export default /*#__PURE__*/_export_sfc(_sfc_main, [['render',_sfc_render],['__scopeId',"data-v-3da707db"],['__file',"/x/y/coverage-zero-vitest-example/src/components/BottomButtonNav.vue"]])
{
"version": 3,
"sources": [
"/x/y/coverage-zero-vitest-example/src/components/BottomButtonNav.vue"
],
"names": [],
"mappings": ";;;qBACO,KAAK,EAAC,uBAAuB;;EAC3B,KAAK,EAAC,oBAAoB;EAAC,aAAW,EAAC,gBAAgB;;;EAGvD,KAAK,EAAC,qBAAqB;EAAC,aAAW,EAAC,iBAAiB;;;;wBAJhE,oBAOM,OAPN,UAOM;IANJ,oBAEM,OAFN,UAEM;MADJ,YAA6B;;IAE/B,oBAEM,OAFN,UAEM;MADJ,YAA8B",
"file": "/x/y/coverage-zero-vitest-example/src/components/BottomButtonNav.vue",
"sourceRoot": "",
"sourcesContent": [
"<template>\n <div class=\"row bottom-button-nav\">\n <div class=\"row left-container\" data-testid=\"left-container\">\n <slot name=\"leftSide\"></slot>\n </div>\n <div class=\"row right-container\" data-testid=\"right-container\">\n <slot name=\"rightSide\"></slot>\n </div>\n </div>\n</template>\n\n<script setup lang=\"ts\"></script>\n\n<style scoped>\n.bottom-button-nav {\n position: absolute;\n bottom: 0;\n display: flex;\n justify-content: space-between;\n width: calc(100% - 80px);\n margin: 0 40px 40px;\n}\n</style>\n"
]
}
When inspecting the source map it's clearly visible that it's off: https://ariperkkio.github.io/source-map-debugger?s=N4Ig.... Notice how the line 4's _withScopeId
helper function is incorrectly included in source maps. This is the uncovered function that your coverage report includes.
{
"functionName": "_withScopeId",
"ranges": [
{
"startOffset": 587,
"endOffset": 689,
"count": 0
}
],
"isBlockCoverage": false
}
Now when we add one extra line to mappings
everything looks much better:
- "mappings": ";;;qBACO,...",
+ "mappings": ";;;;qBACO,...",
---------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 100 | 100 |
BottomButtonNav.vue | 100 | 100 | 100 | 100 |
---------------------|---------|----------|---------|---------|-------------------
https://ariperkkio.github.io/source-map-debugger?s=N4Ig...
This needs to be fixed in one of the Vue compiler related dependencies that your project is using. Maybe it's the vuejs/vue-loader
linked above.
Any news on this?
+1, having the same issue with coverage for components with no functions in them
Having the same issue. Any potential fix or workarounds on the horizon?
This worked for me:
<script setup lang="ts">
/* without this comment coverage will report 0% for functions */
</script>
+1
Describe the bug
I have a UI component that has no functions in it but
vitest run --coverage
reports 0% coverage for functions.If there are no functions to test, the coverage reporter should report 100%
Reproduction
BottomButtonNav.vue
BottomButtonNav.test.ts
System Info