|
1 | 1 | import type { File, TaskEventPack, TaskResultPack, TestAnnotation } from '@vitest/runner' |
| 2 | +import type { SerializedError } from '@vitest/utils' |
2 | 3 | import type { IncomingMessage } from 'node:http' |
3 | 4 | import type { ViteDevServer } from 'vite' |
4 | 5 | import type { WebSocket } from 'ws' |
5 | 6 | import type { Vitest } from '../node/core' |
6 | | -import type { TestCase } from '../node/reporters/reported-tasks' |
| 7 | +import type { TestCase, TestModule } from '../node/reporters/reported-tasks' |
| 8 | +import type { TestSpecification } from '../node/spec' |
7 | 9 | import type { Reporter } from '../node/types/reporter' |
8 | | -import type { SerializedTestSpecification } from '../runtime/types/utils' |
9 | | -import type { Awaitable, LabelColor, ModuleGraphData, UserConsoleLog } from '../types/general' |
| 10 | +import type { LabelColor, ModuleGraphData, UserConsoleLog } from '../types/general' |
10 | 11 | import type { |
11 | 12 | TransformResultWithSource, |
12 | 13 | WebSocketEvents, |
@@ -163,21 +164,25 @@ export class WebSocketReporter implements Reporter { |
163 | 164 | public clients: Map<WebSocket, WebSocketRPC>, |
164 | 165 | ) {} |
165 | 166 |
|
166 | | - onCollected(files?: File[]): void { |
| 167 | + onTestModuleCollected(testModule: TestModule): void { |
167 | 168 | if (this.clients.size === 0) { |
168 | 169 | return |
169 | 170 | } |
| 171 | + |
170 | 172 | this.clients.forEach((client) => { |
171 | | - client.onCollected?.(files)?.catch?.(noop) |
| 173 | + client.onCollected?.([testModule.task])?.catch?.(noop) |
172 | 174 | }) |
173 | 175 | } |
174 | 176 |
|
175 | | - onSpecsCollected(specs?: SerializedTestSpecification[] | undefined): Awaitable<void> { |
| 177 | + onTestRunStart(specifications: ReadonlyArray<TestSpecification>): void { |
176 | 178 | if (this.clients.size === 0) { |
177 | 179 | return |
178 | 180 | } |
| 181 | + |
| 182 | + const serializedSpecs = specifications.map(spec => spec.toJSON()) |
| 183 | + |
179 | 184 | this.clients.forEach((client) => { |
180 | | - client.onSpecsCollected?.(specs)?.catch?.(noop) |
| 185 | + client.onSpecsCollected?.(serializedSpecs)?.catch?.(noop) |
181 | 186 | }) |
182 | 187 | } |
183 | 188 |
|
@@ -220,7 +225,14 @@ export class WebSocketReporter implements Reporter { |
220 | 225 | }) |
221 | 226 | } |
222 | 227 |
|
223 | | - onFinished(files: File[], errors: unknown[]): void { |
| 228 | + onTestRunEnd(testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>): void { |
| 229 | + if (!this.clients.size) { |
| 230 | + return |
| 231 | + } |
| 232 | + |
| 233 | + const files = testModules.map(testModule => testModule.task) |
| 234 | + const errors = [...unhandledErrors] |
| 235 | + |
224 | 236 | this.clients.forEach((client) => { |
225 | 237 | client.onFinished?.(files, errors)?.catch?.(noop) |
226 | 238 | }) |
|
0 commit comments