Skip to content

@vitest/coverage-c8 includes generated __vite_ssr_exports__ helper in coverage #3237

@AriPerkkio

Description

@AriPerkkio

Describe the bug

When a source file declares named export that is transformed into __vite_ssr_exports__ by Vite, the @vitest/coverage-c8 coverage reports increase function count by 1 and consider the Object.defineProperty(__vite_ssr_exports__, ... as part of source code. This is due to Object.defineProperty(__vite_ssr_exports__, ... being included in the source maps.

image

Reproduction

This can be reproduced in Vitest repository's test/coverage-test when c8 is used. All files have function counts that do not match. (#3226 (comment))

This is also seen when adding an unused export. The line that is marked as uncovered contains the Object.defineProperty(__vite_ssr_exports__, ... where get() is not executed since no one imports that file. This get() {} also increases function count by one.

System Info

System:
    OS: macOS 13.3.1
    CPU: (8) arm64 Apple M2
    Memory: 56.73 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.14.0 - ~/.nvm/versions/node/v18.14.0/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.3.1 - ~/.nvm/versions/node/v18.14.0/bin/npm
  Browsers:
    Chrome: 112.0.5615.137
    Safari: 16.4
  npmPackages:
    @vitejs/plugin-vue: latest => 4.1.0 
    @vitest/browser: workspace:* => 0.30.1 
    vite: latest => 4.2.1 
    vitest: workspace:* => 0.30.1

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: coverageIssues and PRs related to the coverage feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions