| 214 | } |
| 215 | |
| 216 | export class WebSocketReporter implements Reporter { |
| 217 | private start = 0 |
| 218 | private end = 0 |
| 219 | constructor( |
| 220 | public ctx: Vitest, |
| 221 | public wss: WebSocketServer, |
| 222 | public clients: Map<WebSocket, WebSocketRPC>, |
| 223 | ) {} |
| 224 | |
| 225 | onTestModuleCollected(testModule: TestModule): void { |
| 226 | if (this.clients.size === 0) { |
| 227 | return |
| 228 | } |
| 229 | |
| 230 | this.clients.forEach((client) => { |
| 231 | client.onCollected?.([testModule.task])?.catch?.(noop) |
| 232 | }) |
| 233 | } |
| 234 | |
| 235 | onTestRunStart(specifications: ReadonlyArray<TestSpecification>): void { |
| 236 | if (this.clients.size === 0) { |
| 237 | return |
| 238 | } |
| 239 | |
| 240 | this.start = performance.now() |
| 241 | const serializedSpecs = specifications.map(spec => spec.toJSON()) |
| 242 | this.clients.forEach((client) => { |
| 243 | client.onSpecsCollected?.(serializedSpecs)?.catch?.(noop) |
| 244 | }) |
| 245 | } |
| 246 | |
| 247 | async onTestCaseAnnotate(testCase: TestCase, annotation: TestAnnotation): Promise<void> { |
| 248 | if (this.clients.size === 0) { |
| 249 | return |
| 250 | } |
| 251 | |
| 252 | this.clients.forEach((client) => { |
| 253 | client.onTestAnnotate?.(testCase.id, annotation)?.catch?.(noop) |
| 254 | }) |
| 255 | } |
| 256 | |
| 257 | async onTestCaseArtifactRecord(testCase: TestCase, artifact: TestArtifact): Promise<void> { |
| 258 | if (this.clients.size === 0) { |
| 259 | return |
| 260 | } |
| 261 | |
| 262 | this.clients.forEach((client) => { |
| 263 | client.onTestArtifactRecord?.(testCase.id, artifact)?.catch?.(noop) |
| 264 | }) |
| 265 | } |
| 266 | |
| 267 | async onTaskUpdate(packs: TaskResultPack[], events: TaskEventPack[]): Promise<void> { |
| 268 | if (this.clients.size === 0) { |
| 269 | return |
| 270 | } |
| 271 | |
| 272 | this.clients.forEach((client) => { |
| 273 | client.onTaskUpdate?.(packs, events)?.catch?.(noop) |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…