@@ -17,7 +17,7 @@ export class ExtensionWorker implements ExtensionWorkerTransport {
1717 public static COLLECT_NAME_PATTERN = '$a'
1818
1919 constructor (
20- public readonly ctx : VitestCore ,
20+ public readonly vitest : VitestCore ,
2121 private readonly debug = false ,
2222 public readonly alwaysAstCollect = false ,
2323 private emitter : WorkerWSEventEmitter ,
@@ -31,15 +31,15 @@ export class ExtensionWorker implements ExtensionWorkerTransport {
3131 }
3232
3333 private get configOverride ( ) : Partial < ResolvedConfig > {
34- return ( this . ctx as any ) . configOverride
34+ return ( this . vitest as any ) . configOverride
3535 }
3636
3737 public setGlobalTestNamePattern ( pattern ?: string | RegExp ) : void {
3838 if ( pattern == null || pattern === '' ) {
3939 this . configOverride . testNamePattern = undefined
4040 }
41- else if ( 'setGlobalTestNamePattern' in this . ctx ) {
42- return this . ctx . setGlobalTestNamePattern ( pattern )
41+ else if ( 'setGlobalTestNamePattern' in this . vitest ) {
42+ return this . vitest . setGlobalTestNamePattern ( pattern )
4343 }
4444 else {
4545 this . configOverride . testNamePattern = typeof pattern === 'string'
@@ -50,22 +50,22 @@ export class ExtensionWorker implements ExtensionWorkerTransport {
5050
5151 public getRootTestProject ( ) : WorkspaceProject {
5252 // vitest 3 uses getRootProject
53- if ( 'getRootProject' in this . ctx ) {
54- return this . ctx . getRootProject ( )
53+ if ( 'getRootProject' in this . vitest ) {
54+ return this . vitest . getRootProject ( )
5555 }
5656 // vitest 3.beta uses getRootTestProject
57- if ( 'getRootTestProject' in this . ctx ) {
58- return ( ( this . ctx as any ) . getRootTestProject as ( ) => WorkspaceProject ) ( )
57+ if ( 'getRootTestProject' in this . vitest ) {
58+ return ( ( this . vitest as any ) . getRootTestProject as ( ) => WorkspaceProject ) ( )
5959 }
60- return ( this . ctx as any ) . getCoreWorkspaceProject ( )
60+ return ( this . vitest as any ) . getCoreWorkspaceProject ( )
6161 }
6262
6363 public async collectTests ( files : [ projectName : string , filepath : string ] [ ] ) {
6464 const astCollect : [ project : WorkspaceProject , filepath : string ] [ ] = [ ]
6565 const otherTests : [ project : WorkspaceProject , filepath : string ] [ ] = [ ]
6666
6767 for ( const [ projectName , filepath ] of files ) {
68- const project = this . ctx . projects . find ( project => project . getName ( ) === projectName )
68+ const project = this . vitest . projects . find ( project => project . getName ( ) === projectName )
6969 assert ( project , `Project ${ projectName } not found for file ${ filepath } ` )
7070 if ( this . alwaysAstCollect || project . config . browser . enabled ) {
7171 astCollect . push ( [ project , filepath ] )
@@ -140,26 +140,26 @@ export class ExtensionWorker implements ExtensionWorkerTransport {
140140
141141 public async runTests ( specsOrPaths : SerializedTestSpecification [ ] | string [ ] | undefined , testNamePattern ?: string ) {
142142 // @ts -expect-error private method in Vitest <=2.1.5
143- await this . ctx . initBrowserProviders ?.( )
143+ await this . vitest . initBrowserProviders ?.( )
144144
145145 const specs = await this . resolveTestSpecs ( specsOrPaths )
146146
147147 await this . runTestFiles ( specs , testNamePattern , ! specsOrPaths )
148148
149149 // debugger never runs in watch mode
150150 if ( this . debug ) {
151- await this . ctx . close ( )
151+ await this . vitest . close ( )
152152 this . emitter . close ( )
153153 }
154154 }
155155
156156 public cancelRun ( ) {
157- return this . ctx . cancelCurrentRun ( 'keyboard-input' )
157+ return this . vitest . cancelCurrentRun ( 'keyboard-input' )
158158 }
159159
160160 public async getFiles ( ) : Promise < [ project : string , file : string ] [ ] > {
161161 // reset cached test files list
162- this . ctx . projects . forEach ( ( project ) => {
162+ this . vitest . projects . forEach ( ( project ) => {
163163 // testFilesList is private
164164 ( project as any ) . testFilesList = null
165165 } )
@@ -168,18 +168,18 @@ export class ExtensionWorker implements ExtensionWorkerTransport {
168168 }
169169
170170 private async globTestSpecifications ( filters ?: string [ ] ) : Promise < TestSpecification [ ] > {
171- if ( 'globTestSpecifications' in this . ctx ) {
172- return this . ctx . globTestSpecifications ( filters )
171+ if ( 'globTestSpecifications' in this . vitest ) {
172+ return this . vitest . globTestSpecifications ( filters )
173173 }
174- return await ( this . ctx as any ) . globTestFiles ( filters )
174+ return await ( this . vitest as any ) . globTestFiles ( filters )
175175 }
176176
177177 private invalidateTree ( mod : any , seen = new Set ( ) ) {
178178 if ( seen . has ( mod ) ) {
179179 return
180180 }
181181 seen . add ( mod )
182- this . ctx . server . moduleGraph . invalidateModule ( mod )
182+ this . vitest . server . moduleGraph . invalidateModule ( mod )
183183 mod . clientImportedModules . forEach ( ( mod : any ) => {
184184 this . invalidateTree ( mod )
185185 } )
@@ -189,7 +189,7 @@ export class ExtensionWorker implements ExtensionWorkerTransport {
189189 }
190190
191191 private async runTestFiles ( specs : SerializedTestSpecification [ ] , testNamePattern ?: string | undefined , runAllFiles = false ) {
192- await ( this . ctx as any ) . runningPromise
192+ await ( this . vitest as any ) . runningPromise
193193 this . watcher . markRerun ( false )
194194
195195 this . setTestNamePattern ( testNamePattern )
@@ -210,10 +210,10 @@ export class ExtensionWorker implements ExtensionWorkerTransport {
210210
211211 const specsToRun = specs . flatMap ( ( spec ) => {
212212 const file = typeof spec === 'string' ? spec : spec [ 1 ]
213- const fileSpecs = this . ctx . getModuleSpecifications
214- ? this . ctx . getModuleSpecifications ( file )
213+ const fileSpecs = this . vitest . getModuleSpecifications
214+ ? this . vitest . getModuleSpecifications ( file )
215215 // supported by the older version
216- : this . ctx . getProjectsByTestFile ( file )
216+ : this . vitest . getProjectsByTestFile ( file )
217217 if ( ! fileSpecs . length ) {
218218 return [ ]
219219 }
@@ -223,16 +223,16 @@ export class ExtensionWorker implements ExtensionWorkerTransport {
223223 this . report ( 'onWatcherRerun' , paths ) ,
224224 // `_onUserTestsRerun` exists only in Vitest 3 and it's private
225225 // the extension needs to migrate to the new API
226- ...( ( this . ctx as any ) . _onUserTestsRerun || [ ] ) . map ( ( fn : any ) => fn ( specs ) ) ,
226+ ...( ( this . vitest as any ) . _onUserTestsRerun || [ ] ) . map ( ( fn : any ) => fn ( specs ) ) ,
227227 ] )
228228
229- await ( this . ctx as any ) . runFiles ( specsToRun , runAllFiles )
229+ await ( this . vitest as any ) . runFiles ( specsToRun , runAllFiles )
230230
231- await this . report ( 'onWatcherStart' , this . ctx . state . getFiles ( paths ) )
231+ await this . report ( 'onWatcherStart' , this . vitest . state . getFiles ( paths ) )
232232 }
233233
234234 private handleFileChanged ( file : string ) : string [ ] {
235- const ctx = this . ctx as any
235+ const ctx = this . vitest as any
236236 // support Vitest 3
237237 if ( ctx . watcher ) {
238238 return ctx . watcher . handleFileChanged ( file ) ? [ file ] : [ ]
@@ -241,11 +241,11 @@ export class ExtensionWorker implements ExtensionWorkerTransport {
241241 }
242242
243243 private scheduleRerun ( files : string [ ] ) : Promise < void > {
244- return ( this . ctx as any ) . scheduleRerun ( files )
244+ return ( this . vitest as any ) . scheduleRerun ( files )
245245 }
246246
247247 private updateLastChanged ( filepath : string ) {
248- this . ctx . projects . forEach ( ( { server, browser } ) => {
248+ this . vitest . projects . forEach ( ( { server, browser } ) => {
249249 const serverMods = server . moduleGraph . getModulesByFile ( filepath )
250250 serverMods ?. forEach ( mod => server . moduleGraph . invalidateModule ( mod ) )
251251 if ( browser ) {
@@ -266,7 +266,7 @@ export class ExtensionWorker implements ExtensionWorkerTransport {
266266 }
267267 }
268268 catch ( err ) {
269- this . ctx . logger . error ( 'Error during analyzing changed files' , err )
269+ this . vitest . logger . error ( 'Error during analyzing changed files' , err )
270270 }
271271 }
272272
@@ -278,28 +278,28 @@ export class ExtensionWorker implements ExtensionWorkerTransport {
278278 this . updateLastChanged ( file )
279279 let content : string | null = null
280280 const projects = [ ]
281- for ( const project of this . ctx . projects ) {
281+ for ( const project of this . vitest . projects ) {
282282 if ( this . isTestFile (
283283 project ,
284284 file ,
285285 ( ) => content ?? ( content = readFileSync ( file , 'utf-8' ) ) ,
286286 ) ) {
287287 testFiles . push ( file )
288288 ; ( project as any ) . testFilesList ?. push ( file )
289- this . ctx . changedTests . add ( file )
289+ this . vitest . changedTests . add ( file )
290290 projects . push ( project )
291291 }
292292 }
293293 // to support Vitest 1.4.0
294- if ( projects . length && ( this . ctx as any ) . projectsTestFiles ) {
295- ( this . ctx as any ) . projectsTestFiles . set ( file , new Set ( projects ) )
294+ if ( projects . length && ( this . vitest as any ) . projectsTestFiles ) {
295+ ( this . vitest as any ) . projectsTestFiles . set ( file , new Set ( projects ) )
296296 }
297297 }
298298
299299 testFiles . forEach ( file => this . scheduleRerun ( [ file ] ) )
300300 }
301301 catch ( err ) {
302- this . ctx . logger . error ( 'Error during analyzing created files' , err )
302+ this . vitest . logger . error ( 'Error during analyzing created files' , err )
303303 }
304304 }
305305
@@ -338,11 +338,11 @@ export class ExtensionWorker implements ExtensionWorkerTransport {
338338 return
339339 }
340340 if ( ! modules ) {
341- this . ctx . server . moduleGraph . invalidateAll ( )
341+ this . vitest . server . moduleGraph . invalidateAll ( )
342342 return
343343 }
344344 modules . forEach ( ( moduleId ) => {
345- const mod = this . ctx . server . moduleGraph . getModuleById ( moduleId )
345+ const mod = this . vitest . server . moduleGraph . getModuleById ( moduleId )
346346 if ( mod ) {
347347 this . invalidateTree ( mod )
348348 }
@@ -364,14 +364,14 @@ export class ExtensionWorker implements ExtensionWorkerTransport {
364364 dispose ( ) {
365365 this . coverage . disable ( )
366366 this . watcher . stopTracking ( )
367- return this . ctx . close ( )
367+ return this . vitest . close ( )
368368 }
369369
370370 close ( ) {
371371 return this . dispose ( )
372372 }
373373
374374 report < T extends keyof Reporter > ( name : T , ...args : ArgumentsType < Reporter [ T ] > ) {
375- return ( this . ctx as any ) . report ( name , ...args )
375+ return ( this . vitest as any ) . report ( name , ...args )
376376 }
377377}
0 commit comments