vitest-dev / vitest

Next generation testing framework powered by Vite.
https://vitest.dev
MIT License
13.08k stars 1.17k forks source link

Coverage issue when v-model and listener on same property #6423

Open Polluux opened 2 months ago

Polluux commented 2 months ago

Describe the bug

Coverage is misbehaving when a custom component has a v-model and a @update listener on the same property.

Ex:

v-model:nameproperty="data" @update:nameproperty.stop

Reproduction

Here is a github repository with documentation and reproduction case :

https://github.com/Polluux/demo-v8-coverage-issue-vmodel-update

System Info

System:
    OS: Linux 6.8 Ubuntu 24.04 LTS 24.04 LTS (Noble Numbat)
    CPU: (8) x64 Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
    Memory: 6.82 GB / 15.49 GB
    Container: Yes
    Shell: 5.2.21 - /bin/bash
  Binaries:
    Node: 22.3.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/bin/yarn
    npm: 9.2.0 - /usr/bin/npm
  Browsers:
    Chrome: 90.0.4430.93
    Chromium: 128.0.6613.84
    Firefox: 129.0
  npmPackages:
    @vitejs/plugin-vue: ^5.1.2 => 5.1.2 
    @vitest/coverage-v8: ^2.0.5 => 2.0.5 
    vite: ^5.4.1 => 5.4.2 
    vitest: ^2.0.5 => 2.0.5

Used Package Manager

npm

Validations

AriPerkkio commented 2 months ago

Here's how the component looks like when it's transpiled.

I don't think this will work with any Javascript code coverage tool.

Polluux commented 2 months ago

Okay so based on your answer I managed to find a quick workaround for this case.

Insead of :

v-model:nameproperty="data"
@update:nameproperty="onData"
...
function onData() {
  // do
}

I'd write :

:nameproperty="data"
@update:nameproperty="onData"
...
function onData(e) {
  nameproperty.value = e;
  // do
}

Behavior looks the same and coverage is working as expected. Still feel a bit sad to not be able to use the "full power" of Vue.

cenfun commented 2 months ago

This is a sourcemap issue.

Following is the coverage of transpiled code: image

You can see the wrong maping image

That's why the uncovered position is started from line 1 image