@@ -50,6 +50,13 @@ export function setupBrowserRpc(globalServer: ParentBrowserProject) {
50
50
)
51
51
}
52
52
53
+ const method = searchParams . get ( 'method' ) as 'run' | 'collect'
54
+ if ( method !== 'run' && method !== 'collect' ) {
55
+ return error (
56
+ new Error ( `[vitest] Method query in ${ request . url } is invalid. Method should be either "run" or "collect".` ) ,
57
+ )
58
+ }
59
+
53
60
if ( type === 'orchestrator' ) {
54
61
const session = vitest . _browserSessions . getSession ( sessionId )
55
62
// it's possible the session was already resolved by the preview provider
@@ -67,7 +74,7 @@ export function setupBrowserRpc(globalServer: ParentBrowserProject) {
67
74
wss . handleUpgrade ( request , socket , head , ( ws ) => {
68
75
wss . emit ( 'connection' , ws , request )
69
76
70
- const rpc = setupClient ( project , rpcId , ws )
77
+ const rpc = setupClient ( project , rpcId , ws , method )
71
78
const state = project . browser ! . state as BrowserServerState
72
79
const clients = type === 'tester' ? state . testers : state . orchestrators
73
80
clients . set ( rpcId , rpc )
@@ -96,7 +103,7 @@ export function setupBrowserRpc(globalServer: ParentBrowserProject) {
96
103
}
97
104
}
98
105
99
- function setupClient ( project : TestProject , rpcId : string , ws : WebSocket ) {
106
+ function setupClient ( project : TestProject , rpcId : string , ws : WebSocket , method : 'run' | 'collect' ) {
100
107
const mockResolver = new ServerMockResolver ( globalServer . vite , {
101
108
moduleDirectories : project . config . server ?. deps ?. moduleDirectories ,
102
109
} )
@@ -111,19 +118,39 @@ export function setupBrowserRpc(globalServer: ParentBrowserProject) {
111
118
vitest . state . catchError ( error , type )
112
119
} ,
113
120
async onQueued ( file ) {
114
- await vitest . _testRun . enqueued ( project , file )
121
+ if ( method === 'collect' ) {
122
+ vitest . state . collectFiles ( project , [ file ] )
123
+ }
124
+ else {
125
+ await vitest . _testRun . enqueued ( project , file )
126
+ }
115
127
} ,
116
128
async onCollected ( files ) {
117
- await vitest . _testRun . collected ( project , files )
129
+ if ( method === 'collect' ) {
130
+ vitest . state . collectFiles ( project , files )
131
+ }
132
+ else {
133
+ await vitest . _testRun . collected ( project , files )
134
+ }
118
135
} ,
119
136
async onTaskUpdate ( packs , events ) {
120
- await vitest . _testRun . updated ( packs , events )
137
+ if ( method === 'collect' ) {
138
+ vitest . state . updateTasks ( packs )
139
+ }
140
+ else {
141
+ await vitest . _testRun . updated ( packs , events )
142
+ }
121
143
} ,
122
144
onAfterSuiteRun ( meta ) {
123
145
vitest . coverageProvider ?. onAfterSuiteRun ( meta )
124
146
} ,
125
- sendLog ( log ) {
126
- return vitest . _testRun . log ( log )
147
+ async sendLog ( log ) {
148
+ if ( method === 'collect' ) {
149
+ vitest . state . updateUserLog ( log )
150
+ }
151
+ else {
152
+ await vitest . _testRun . log ( log )
153
+ }
127
154
} ,
128
155
resolveSnapshotPath ( testPath ) {
129
156
return vitest . snapshot . resolvePath < ResolveSnapshotPathHandlerContext > ( testPath , {
0 commit comments