/
worker.ts
56 lines (48 loc) · 1.77 KB
/
worker.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import type { MessagePort } from 'node:worker_threads'
import type { File, TaskResultPack, Test } from '@vitest/runner'
import type { FetchFunction, ModuleCacheMap, RawSourceMap, ViteNodeResolveId } from 'vite-node'
import type { BirpcReturn } from 'birpc'
import type { MockMap } from './mocker'
import type { EnvironmentOptions, ResolvedConfig, VitestEnvironment } from './config'
import type { SnapshotResult } from './snapshot'
import type { UserConsoleLog } from './general'
export interface WorkerTestEnvironment {
name: VitestEnvironment
options: EnvironmentOptions | null
}
export interface WorkerContext {
workerId: number
port: MessagePort
config: ResolvedConfig
files: string[]
environment: WorkerTestEnvironment
invalidates?: string[]
}
export type ResolveIdFunction = (id: string, importer?: string) => Promise<ViteNodeResolveId | null>
export interface AfterSuiteRunMeta {
coverage?: unknown
}
export interface WorkerRPC {
fetch: FetchFunction
resolveId: ResolveIdFunction
getSourceMap: (id: string, force?: boolean) => Promise<RawSourceMap | undefined>
onFinished: (files: File[], errors?: unknown[]) => void
onWorkerExit: (error: unknown, code?: number) => void
onPathsCollected: (paths: string[]) => void
onUserConsoleLog: (log: UserConsoleLog) => void
onUnhandledError: (err: unknown, type: string) => void
onCollected: (files: File[]) => void
onAfterSuiteRun: (meta: AfterSuiteRunMeta) => void
onTaskUpdate: (pack: TaskResultPack[]) => void
snapshotSaved: (snapshot: SnapshotResult) => void
resolveSnapshotPath: (testPath: string) => string
}
export interface WorkerGlobalState {
ctx: WorkerContext
config: ResolvedConfig
rpc: BirpcReturn<WorkerRPC>
current?: Test
filepath?: string
moduleCache: ModuleCacheMap
mockMap: MockMap
}