@@ -153,6 +153,10 @@ function isCliApiPackage (vitestPackage) {
153153 return vitestPackage . s ?. name === 'startVitest'
154154}
155155
156+ function isTestPackage ( testPackage ) {
157+ return testPackage . V ?. name === 'VitestTestRunner'
158+ }
159+
156160function getSessionStatus ( state ) {
157161 if ( state . getCountOfFailedTests ( ) > 0 ) {
158162 return 'fail'
@@ -240,7 +244,9 @@ function getSortWrapper (sort, frameworkVersion) {
240244 if ( isFlakyTestRetriesEnabled && ! this . ctx . config . retry && flakyTestRetriesCount > 0 ) {
241245 this . ctx . config . retry = flakyTestRetriesCount
242246 try {
243- const workspaceProject = this . ctx . getCoreWorkspaceProject ( )
247+ const workspaceProject = this . ctx . getCoreWorkspaceProject
248+ ? this . ctx . getCoreWorkspaceProject ( )
249+ : this . ctx . getRootProject ( )
244250 workspaceProject . _provided . _ddIsFlakyTestRetriesEnabled = isFlakyTestRetriesEnabled
245251 } catch {
246252 log . warn ( 'Could not send library configuration to workers.' )
@@ -272,7 +278,9 @@ function getSortWrapper (sort, frameworkVersion) {
272278 // TODO: use this to pass session and module IDs to the worker, instead of polluting process.env
273279 // Note: setting this.ctx.config.provide directly does not work because it's cached
274280 try {
275- const workspaceProject = this . ctx . getCoreWorkspaceProject ( )
281+ const workspaceProject = this . ctx . getCoreWorkspaceProject
282+ ? this . ctx . getCoreWorkspaceProject ( )
283+ : this . ctx . getRootProject ( )
276284 workspaceProject . _provided . _ddIsKnownTestsEnabled = isKnownTestsEnabled
277285 workspaceProject . _provided . _ddKnownTests = knownTests
278286 workspaceProject . _provided . _ddIsEarlyFlakeDetectionEnabled = isEarlyFlakeDetectionEnabled
@@ -290,7 +298,9 @@ function getSortWrapper (sort, frameworkVersion) {
290298
291299 if ( isDiEnabled ) {
292300 try {
293- const workspaceProject = this . ctx . getCoreWorkspaceProject ( )
301+ const workspaceProject = this . ctx . getCoreWorkspaceProject
302+ ? this . ctx . getCoreWorkspaceProject ( )
303+ : this . ctx . getRootProject ( )
294304 workspaceProject . _provided . _ddIsDiEnabled = isDiEnabled
295305 } catch {
296306 log . warn ( 'Could not send Dynamic Instrumentation configuration to workers.' )
@@ -305,7 +315,9 @@ function getSortWrapper (sort, frameworkVersion) {
305315 } else {
306316 const testManagementTests = receivedTestManagementTests
307317 try {
308- const workspaceProject = this . ctx . getCoreWorkspaceProject ( )
318+ const workspaceProject = this . ctx . getCoreWorkspaceProject
319+ ? this . ctx . getCoreWorkspaceProject ( )
320+ : this . ctx . getRootProject ( )
309321 workspaceProject . _provided . _ddIsTestManagementTestsEnabled = isTestManagementTestsEnabled
310322 workspaceProject . _provided . _ddTestManagementAttemptToFixRetries = testManagementAttemptToFixRetries
311323 workspaceProject . _provided . _ddTestManagementTests = testManagementTests
@@ -321,7 +333,9 @@ function getSortWrapper (sort, frameworkVersion) {
321333 log . error ( 'Could not get modified tests.' )
322334 } else {
323335 try {
324- const workspaceProject = this . ctx . getCoreWorkspaceProject ( )
336+ const workspaceProject = this . ctx . getCoreWorkspaceProject
337+ ? this . ctx . getCoreWorkspaceProject ( )
338+ : this . ctx . getRootProject ( )
325339 workspaceProject . _provided . _ddIsImpactedTestsEnabled = isImpactedTestsEnabled
326340 workspaceProject . _provided . _ddModifiedFiles = modifiedFiles
327341 } catch {
@@ -443,13 +457,7 @@ function getStartVitestWrapper (cliApiPackage, frameworkVersion) {
443457 return cliApiPackage
444458}
445459
446- addHook ( {
447- name : 'vitest' ,
448- versions : [ '>=1.6.0' ] ,
449- file : 'dist/runners.js'
450- } , ( vitestPackage ) => {
451- const { VitestTestRunner } = vitestPackage
452-
460+ function wrapVitestTestRunner ( VitestTestRunner ) {
453461 // `onBeforeRunTask` is run before any repetition or attempt is run
454462 // `onBeforeRunTask` is an async function
455463 shimmer . wrap ( VitestTestRunner . prototype , 'onBeforeRunTask' , onBeforeRunTask => function ( task ) {
@@ -744,6 +752,30 @@ addHook({
744752
745753 return result
746754 } )
755+ }
756+
757+ addHook ( {
758+ name : 'vitest' ,
759+ versions : [ '>=4.0.0' ] ,
760+ filePattern : 'dist/chunks/test.*'
761+ } , ( testPackage ) => {
762+ if ( ! isTestPackage ( testPackage ) ) {
763+ return testPackage
764+ }
765+
766+ wrapVitestTestRunner ( testPackage . V )
767+
768+ return testPackage
769+ } )
770+
771+ addHook ( {
772+ name : 'vitest' ,
773+ versions : [ '>=1.6.0 <4.0.0' ] ,
774+ file : 'dist/runners.js'
775+ } , ( vitestPackage ) => {
776+ const { VitestTestRunner } = vitestPackage
777+
778+ wrapVitestTestRunner ( VitestTestRunner )
747779
748780 return vitestPackage
749781} )
0 commit comments