Skip to content

feat: don't use vite-node in coverage packages #8304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

sheremet-va
Copy link
Member

Description

Copied from #8208 to reduce the amount of changes and make debugging easier

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@sheremet-va sheremet-va requested a review from AriPerkkio July 14, 2025 11:30
Copy link

netlify bot commented Jul 14, 2025

Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 2963a15
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6874f425e5d69d0008b236ff
😎 Deploy Preview https://deploy-preview-8304--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@sheremet-va
Copy link
Member Author

@AriPerkkio can you help me with this one? Coverage went up for some files and I am not sure why

@AriPerkkio
Copy link
Member

AriPerkkio commented Jul 15, 2025

The web transformed result is producing invalid coverage. In main the web transformed multi-environment.ts looks like this:

Object.defineProperty(__vite_ssr_exports__, "padding", { enumerable: true, configurable: true, get(){ try { return padding } catch {} }});
Object.defineProperty(__vite_ssr_exports__, "sum", { enumerable: true, configurable: true, get(){ try { return sum } catch {} }});
const padding = `transformMode is csr 
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****`;
function sum(a, b) {
  if (a === 8 && b === 9) {
    return 17;
  } else if (a === 2 && b === 2) {
    return 4;
  } else if (a === 11 && b === 22) {
    return 33;
  } else if (a === 10 && b === 23) {
    return 33;
  };
  return a + b;
}

//# sourceMappingSource=vite-node
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6Ijs7QUFHTyxNQUFNLFVBQVU7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFBQTtBQUFBO0FBQUE7QUFFaEIsU0FBUyxJQUFJLEdBQVcsR0FBVztBQUt4QyxNQUFJLE1BQU0sS0FBSyxNQUFNLEdBQUc7QUFFdEIsV0FBTztBQUFBLEVBQ1QsV0FFUyxNQUFNLEtBQUssTUFBTSxHQUFHO0FBRTNCLFdBQU87QUFBQSxFQUNULFdBQ1MsTUFBTSxNQUFNLE1BQU0sSUFBSTtBQUU3QixXQUFPO0FBQUEsRUFDVCxXQUNTLE1BQU0sTUFBTSxNQUFNLElBQUk7QUFFN0IsV0FBTztBQUFBLEVBQ1Q7QUFHQSxTQUFPLElBQUk7QUFDYiIsIm5hbWVzIjpbXSwiaWdub3JlTGlzdCI6W10sInNvdXJjZXMiOlsibXVsdGktZW52aXJvbm1lbnQudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBUaGUgdmFyaWFibGUgYmVsb3cgaXMgbW9kaWZpZWQgYnkgY3VzdG9tIFZpdGUgcGx1Z2luXG4gKi9cbmV4cG9ydCBjb25zdCBwYWRkaW5nID0gJ2RlZmF1bHQtcGFkZGluZydcblxuZXhwb3J0IGZ1bmN0aW9uIHN1bShhOiBudW1iZXIsIGI6IG51bWJlcikge1xuICAvKlxuICAgKiBUaGVzZSBpZi1icmFuY2hlcyBzaG91bGQgc2hvdyBjb3JyZWN0bHkgb24gY292ZXJhZ2UgcmVwb3J0LlxuICAgKiBPdGhlcndpc2Ugc291cmNlIG1hcHMgYXJlIG9mZi5cbiAgICovXG4gIGlmIChhID09PSA4ICYmIGIgPT09IDkpIHtcbiAgICAvLyBUaGlzIGlzIG5vdCBjb3ZlcmVkIGJ5IGFueSB0ZXN0XG4gICAgcmV0dXJuIDE3XG4gIH1cbiAgLy8gQ29tbWVudFxuICBlbHNlIGlmIChhID09PSAyICYmIGIgPT09IDIpIHtcbiAgICAvLyBUaGlzIGlzIGNvdmVyZWQgYnkgU1NSIHRlc3RcbiAgICByZXR1cm4gNFxuICB9XG4gIGVsc2UgaWYgKGEgPT09IDExICYmIGIgPT09IDIyKSB7XG4gICAgLy8gVGhpcyBpcyBub3QgY292ZXJlZCBieSBhbnkgdGVzdFxuICAgIHJldHVybiAzM1xuICB9XG4gIGVsc2UgaWYgKGEgPT09IDEwICYmIGIgPT09IDIzKSB7XG4gICAgLy8gVGhpcyBpcyBjb3ZlcmVkIGJ5IFdlYiB0ZXN0XG4gICAgcmV0dXJuIDMzXG4gIH1cblxuICAvLyBUaGlzIGlzIGNvdmVyZWQgYnkgU1NSIGFuZCBXZWIgdGVzdCwgc2hvdWxkIHNob3cgMnggaGl0c1xuICByZXR1cm4gYSArIGJcbn1cbiJdLCJmaWxlIjoiL2ZpeHR1cmVzL3NyYy9tdWx0aS1lbnZpcm9ubWVudC50cyJ9

In this PR it's:

export const padding = `transformMode is csr 
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****
*****`;
export function sum(a, b) {
  if (a === 8 && b === 9) {
    return 17;
  } else if (a === 2 && b === 2) {
    return 4;
  } else if (a === 11 && b === 22) {
    return 33;
  } else if (a === 10 && b === 23) {
    return 33;
  }
  return a + b;
}

When comparing the SSR transformed ones, they are both 100% identical:

Object.defineProperty(__vite_ssr_exports__, "padding", { enumerable: true, configurable: true, get(){ try { return padding } catch {} }});
Object.defineProperty(__vite_ssr_exports__, "sum", { enumerable: true, configurable: true, get(){ try { return sum } catch {} }});
const padding = `transformMode is ssr `;
function sum(a, b) {
  if (a === 8 && b === 9) {
    return 17;
  } else if (a === 2 && b === 2) {
    return 4;
  } else if (a === 11 && b === 22) {
    return 33;
  } else if (a === 10 && b === 23) {
    return 33;
  };
  return a + b;
}

//# sourceMappingSource=vite-node
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJtYXBwaW5ncyI6Ijs7QUFHTyxNQUFNLFVBQVU7QUFFaEIsU0FBUyxJQUFJLEdBQVcsR0FBVztBQUt4QyxNQUFJLE1BQU0sS0FBSyxNQUFNLEdBQUc7QUFFdEIsV0FBTztBQUFBLEVBQ1QsV0FFUyxNQUFNLEtBQUssTUFBTSxHQUFHO0FBRTNCLFdBQU87QUFBQSxFQUNULFdBQ1MsTUFBTSxNQUFNLE1BQU0sSUFBSTtBQUU3QixXQUFPO0FBQUEsRUFDVCxXQUNTLE1BQU0sTUFBTSxNQUFNLElBQUk7QUFFN0IsV0FBTztBQUFBLEVBQ1Q7QUFHQSxTQUFPLElBQUk7QUFDYiIsIm5hbWVzIjpbXSwiaWdub3JlTGlzdCI6W10sInNvdXJjZXMiOlsibXVsdGktZW52aXJvbm1lbnQudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBUaGUgdmFyaWFibGUgYmVsb3cgaXMgbW9kaWZpZWQgYnkgY3VzdG9tIFZpdGUgcGx1Z2luXG4gKi9cbmV4cG9ydCBjb25zdCBwYWRkaW5nID0gJ2RlZmF1bHQtcGFkZGluZydcblxuZXhwb3J0IGZ1bmN0aW9uIHN1bShhOiBudW1iZXIsIGI6IG51bWJlcikge1xuICAvKlxuICAgKiBUaGVzZSBpZi1icmFuY2hlcyBzaG91bGQgc2hvdyBjb3JyZWN0bHkgb24gY292ZXJhZ2UgcmVwb3J0LlxuICAgKiBPdGhlcndpc2Ugc291cmNlIG1hcHMgYXJlIG9mZi5cbiAgICovXG4gIGlmIChhID09PSA4ICYmIGIgPT09IDkpIHtcbiAgICAvLyBUaGlzIGlzIG5vdCBjb3ZlcmVkIGJ5IGFueSB0ZXN0XG4gICAgcmV0dXJuIDE3XG4gIH1cbiAgLy8gQ29tbWVudFxuICBlbHNlIGlmIChhID09PSAyICYmIGIgPT09IDIpIHtcbiAgICAvLyBUaGlzIGlzIGNvdmVyZWQgYnkgU1NSIHRlc3RcbiAgICByZXR1cm4gNFxuICB9XG4gIGVsc2UgaWYgKGEgPT09IDExICYmIGIgPT09IDIyKSB7XG4gICAgLy8gVGhpcyBpcyBub3QgY292ZXJlZCBieSBhbnkgdGVzdFxuICAgIHJldHVybiAzM1xuICB9XG4gIGVsc2UgaWYgKGEgPT09IDEwICYmIGIgPT09IDIzKSB7XG4gICAgLy8gVGhpcyBpcyBjb3ZlcmVkIGJ5IFdlYiB0ZXN0XG4gICAgcmV0dXJuIDMzXG4gIH1cblxuICAvLyBUaGlzIGlzIGNvdmVyZWQgYnkgU1NSIGFuZCBXZWIgdGVzdCwgc2hvdWxkIHNob3cgMnggaGl0c1xuICByZXR1cm4gYSArIGJcbn1cbiJdLCJmaWxlIjoiL2ZpeHR1cmVzL3NyYy9tdWx0aS1lbnZpcm9ubWVudC50cyJ9

What's causing the difference? This makes the V8 script coverages startOffset wrong as the prepended SSR helpers are present in coverage results but not in transformed sources.

With following we can see that the executed module had the injected _vite_ssr_exports_ helpers:

$ pwd
/x/vitest/test/coverage-test

$ VITE_NODE_DEBUG_DUMP=1 pnpm exec vitest --config fixtures/configs/vitest.config.multi-transform.ts fixtures/test/multi-environment-fixture-web.test.ts

$ code .vite-node/dump/_fixtures_src_multi-environment_*

@sheremet-va
Copy link
Member Author

What's causing the difference? This makes the V8 script coverages startOffset wrong as the prepended SSR helpers are present in coverage results but not in transformed sources.

environment.transformRequest doesn't inject SSR transform by default. And it does seem useless to inject it here since the code will not run. The transformResult will return ssr: false option (well, it will return ssr: undefined) alongside code and map to see if the transform was applied - can we check it and avoid applying the offset in this case?

@AriPerkkio
Copy link
Member

V8 coverage report for that web/client transformed file has coverage for the get() functions that SSR transform adds. Also the VITE_NODE_DEBUG_DUMP shows that the executed file actually had those.

We are not adding these offsets ourselves.

@sheremet-va
Copy link
Member Author

Hm, this seems like a bug in Vite then. The module graph only keeps the web transform even though moduleRunnerTransform is set to true. I don't even know where it caches the ssr transform then 🤔

@sheremet-va
Copy link
Member Author

Ah, wait, it holds this value because we don't actually use the module runner transform here yet 🤦 It's part of a different PR. Seems like the changes can't be applied without fully moving to the module runner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants