vitest-dev / vitest

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

Wrong coverage when using isolate: false #6736

Open RodrigoFerretti opened 6 days ago

RodrigoFerretti commented 6 days ago

Describe the bug

This is the same bug as mentioned in https://github.com/vitest-dev/vitest/issues/3846, but now with minimal reproduction.

I've read somewhere that vitest orders the execution by the file's size, descending.

The coverage is ignored for the smaller tests when the method being tested is called in one of the "setupFiles" configured, even though everything should be covered

Reproduction

https://github.com/RodrigoFerretti/vitest-coverage-w-isolate

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish)
    CPU: (8) x64 Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz
    Memory: 5.28 GB / 15.23 GB
    Container: Yes
    Shell: 5.8.1 - /usr/bin/zsh
  Binaries:
    Node: 18.19.0 - ~/.nvm/versions/node/v18.19.0/bin/node
    Yarn: 1.22.22 - ~/.yarn/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v18.19.0/bin/npm
  Browsers:
    Chrome: 127.0.6533.72
  npmPackages:
    @vitest/coverage-v8: 2.0.3 => 2.0.3 
    vite: 5.3.4 => 5.3.4 
    vitest: 2.0.3 => 2.0.3

Used Package Manager

yarn

Validations

AriPerkkio commented 2 days ago

Does this happen when setup files are not importing source files?

RodrigoFerretti commented 1 day ago

@AriPerkkio Removing the "multiply" function from the "setup.ts" file fixes the problem for this reproduction code, but it is impossible for me to do something like this in the project I am working on. I kept the isolate true option to keep the coverage, even though the tests take longer like this.

AriPerkkio commented 1 day ago

Thanks for checking. It helps us debugging when we can narrow down the required conditions to "setupFiles + isolate: false" only.