You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
When using --changed option with Vue Router, all test files are detected as changed when modifying any component, even though the router uses lazy-loaded imports (() => import(...)).
The dependency graph appears to consider lazy route imports as actual dependencies, causing the entire test suite to run.
Question
Why does Vitest's --changed consider imports in the router as dependencies? Is there a way to configure Vitest to ignore these transitive dependencies or to make --changed smarter about component imports?
Workaround
I created a Vite plugin to virtualize route component imports, which breaks the dependency chain for --changed detection.
This feels like a hacky solution and I'm wondering if there's a more idiomatic way to solve this issue, or if Vitest could handle lazy imports differently out of the box.
importtype{Plugin}from'vite'constPROXY_PREFIX='\0virtual:route-component-proxy__'exportconstvirtualizeRouteComponents=(): Plugin=>({name: 'virtualize-route-components',enforce: 'pre',resolveId(source,importer){if(!importer){returnnull}constisRouteFile=importer.endsWith('/routes.ts')||importer.endsWith('/router/index.ts')if(!isRouteFile||!source.endsWith('.vue')){returnnull}returnPROXY_PREFIX+source},load(id){if(id.startsWith(PROXY_PREFIX)){return`export { default } from '${id.slice(PROXY_PREFIX.length)}'`}returnnull},})
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
When using
--changedoption with Vue Router, all test files are detected as changed when modifying any component, even though the router uses lazy-loadedimports (() => import(...)).The dependency graph appears to consider lazy route imports as actual dependencies, causing the entire test suite to run.
Reproduction link
Steps to reproduce:
UserCard)pnpm vitest list --changed --filesOnlyrouter.js) and commitpnpm vitest list --changed --filesOnlyEnvironment
Vitest: 4.0.18
Vite: 7.3.1
Vue: 3.5.29
Vue Router: 5.0.3
@vue/test-utils: 2.4.6
OS: Linux (WSL Ubuntu)
Node: v24.13.0
Question
Why does Vitest's
--changedconsider imports in the router as dependencies? Is there a way to configure Vitest to ignore these transitive dependencies or to make--changedsmarter about component imports?Workaround
I created a Vite plugin to virtualize route component imports, which breaks the dependency chain for
--changeddetection.This feels like a hacky solution and I'm wondering if there's a more idiomatic way to solve this issue, or if Vitest could handle lazy imports differently out of the box.
Beta Was this translation helpful? Give feedback.
All reactions