@@ -95,6 +95,7 @@ export class Vitest {
9595 this . pool = undefined
9696 this . coverageProvider = undefined
9797 this . runningPromise = undefined
98+ this . distPath = undefined !
9899 this . projectsTestFiles . clear ( )
99100
100101 const resolved = resolveConfig ( this . mode , options , server . config , this . logger )
@@ -110,11 +111,6 @@ export class Vitest {
110111
111112 this . vitenode = new ViteNodeServer ( server , this . config . server )
112113
113- // if Vitest is running globally, then we should still import local vitest if possible
114- const projectVitestPath = await this . vitenode . resolveId ( 'vitest' )
115- const vitestDir = projectVitestPath ? resolve ( projectVitestPath . id , '../..' ) : rootDir
116- this . distPath = join ( vitestDir , 'dist' )
117-
118114 const node = this . vitenode
119115 this . runner = new ViteNodeRunner ( {
120116 root : server . config . root ,
@@ -508,7 +504,19 @@ export class Vitest {
508504 await project . initializeGlobalSetup ( )
509505 }
510506
507+ private async initializeDistPath ( ) {
508+ if ( this . distPath )
509+ return
510+
511+ // if Vitest is running globally, then we should still import local vitest if possible
512+ const projectVitestPath = await this . vitenode . resolveId ( 'vitest' )
513+ const vitestDir = projectVitestPath ? resolve ( projectVitestPath . id , '../..' ) : rootDir
514+ this . distPath = join ( vitestDir , 'dist' )
515+ }
516+
511517 async runFiles ( paths : WorkspaceSpec [ ] , allTestsRun : boolean ) {
518+ await this . initializeDistPath ( )
519+
512520 const filepaths = paths . map ( ( [ , file ] ) => file )
513521 this . state . collectPaths ( filepaths )
514522
0 commit comments