-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
runner.ts
112 lines (101 loc) · 3.51 KB
/
runner.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import type { File, SequenceHooks, SequenceSetupFiles, Suite, TaskResultPack, Test, TestContext } from './tasks'
export interface VitestRunnerConfig {
root: string
setupFiles: string[] | string
name: string
passWithNoTests: boolean
testNamePattern?: RegExp
allowOnly?: boolean
sequence: {
shuffle?: boolean
seed: number
hooks: SequenceHooks
setupFiles: SequenceSetupFiles
}
chaiConfig?: {
truncateThreshold?: number
}
maxConcurrency: number
testTimeout: number
hookTimeout: number
}
export type VitestRunnerImportSource = 'collect' | 'setup'
export interface VitestRunnerConstructor {
new(config: VitestRunnerConfig): VitestRunner
}
export type CancelReason = 'keyboard-input' | 'test-failure' | string & {}
export interface VitestRunner {
/**
* First thing that's getting called before actually collecting and running tests.
*/
onBeforeCollect?(paths: string[]): unknown
/**
* Called after collecting tests and before "onBeforeRun".
*/
onCollected?(files: File[]): unknown
/**
* Called when test runner should cancel next test runs.
* Runner should listen for this method and mark tests and suites as skipped in
* "onBeforeRunSuite" and "onBeforeRunTest" when called.
*/
onCancel?(reason: CancelReason): unknown
/**
* Called before running a single test. Doesn't have "result" yet.
*/
onBeforeRunTest?(test: Test): unknown
/**
* Called before actually running the test function. Already has "result" with "state" and "startTime".
*/
onBeforeTryTest?(test: Test, options: { retry: number; repeats: number }): unknown
/**
* Called after result and state are set.
*/
onAfterRunTest?(test: Test): unknown
/**
* Called right after running the test function. Doesn't have new state yet. Will not be called, if the test function throws.
*/
onAfterTryTest?(test: Test, options: { retry: number; repeats: number }): unknown
/**
* Called before running a single suite. Doesn't have "result" yet.
*/
onBeforeRunSuite?(suite: Suite): unknown
/**
* Called after running a single suite. Has state and result.
*/
onAfterRunSuite?(suite: Suite): unknown
/**
* If defined, will be called instead of usual Vitest suite partition and handling.
* "before" and "after" hooks will not be ignored.
*/
runSuite?(suite: Suite): Promise<void>
/**
* If defined, will be called instead of usual Vitest handling. Useful, if you have your custom test function.
* "before" and "after" hooks will not be ignored.
*/
runTest?(test: Test): Promise<void>
/**
* Called, when a task is updated. The same as "onTaskUpdate" in a reporter, but this is running in the same thread as tests.
*/
onTaskUpdate?(task: TaskResultPack[]): Promise<void>
/**
* Called before running all tests in collected paths.
*/
onBeforeRun?(files: File[]): unknown
/**
* Called right after running all tests in collected paths.
*/
onAfterRun?(files: File[]): unknown
/**
* Called when new context for a test is defined. Useful, if you want to add custom properties to the context.
* If you only want to define custom context, consider using "beforeAll" in "setupFiles" instead.
*/
extendTestContext?(context: TestContext): TestContext
/**
* Called, when files are imported. Can be called in two situations: when collecting tests and when importing setup files.
*/
importFile(filepath: string, source: VitestRunnerImportSource): unknown
/**
* Publicly available configuration.
*/
config: VitestRunnerConfig
}