-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path-types.ts
132 lines (119 loc) · 4.02 KB
/
-types.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import type { SuiteReport } from './-types/report';
export type CompatTestReport = {
id: number;
name: string;
items: { passed: boolean; message: string }[];
failed: number;
passed: number;
total: number;
runDuration: number;
skipped: boolean;
todo: boolean;
testId: string;
};
export interface Emitter {
emit(name: 'suite-start', data: SuiteReport): void;
emit(name: 'suite-finish', data: SuiteReport): void;
emit(name: 'test-start', data: CompatTestReport): void;
emit(name: 'test-finish', data: CompatTestReport): void;
}
export type ParamConfig = {
id: string;
label: string;
value: boolean;
};
export type GlobalHooksStorage<TC extends TestContext> = {
onSuiteStart: GlobalCallback[];
onSuiteFinish: GlobalCallback[];
beforeModule: GlobalCallback[];
afterModule: GlobalCallback[];
beforeEach: HooksCallback<TC>[];
afterEach: HooksCallback<TC>[];
};
export type GlobalConfig<TC extends TestContext = TestContext> = {
params: {
[key in
| 'concurrency'
| 'tryCatch'
| 'instrument'
| 'hideReport'
| 'memory'
| 'groupLogs'
| 'debug'
| 'container']: ParamConfig;
};
_current: SuiteReport | null;
useTestem: boolean;
useDiagnostic: boolean;
concurrency: number;
globalHooks: GlobalHooksStorage<TC>;
totals: {
tests: number;
primaryModules: number;
modules: number;
skipped: number;
todo: number;
};
};
export interface Diagnostic {
equal<T>(actual: T, expected: T, message?: string): void;
notEqual<T>(actual: T, expected: T, message?: string): void;
deepEqual<T>(actual: T, expected: T, message?: string): void;
notDeepEqual<T>(actual: T, expected: T, message?: string): void;
throws(fn: () => Promise<void>, expected?: string | RegExp, message?: string): Promise<void>;
throws(fn: () => void, expected?: string | RegExp, message?: string): void;
doesNotThrow(fn: () => Promise<void>, expected?: string | RegExp, message?: string): Promise<void>;
doesNotThrow(fn: () => void, expected?: string | RegExp, message?: string): void;
true(actual: boolean, message?: string): void;
false(actual: boolean, message?: string): void;
ok(actual: unknown, message?: string): void;
notOk(actual: unknown, message?: string): void;
expect(count: number): void;
step(name: string): void;
verifySteps(steps: string[], message?: string): void;
satisfies<T extends object, J extends T>(actual: J, expected: T, message?: string): void;
}
export interface TestContext {}
export type GlobalCallback = () => void | Promise<void>;
export interface Hooks<TC extends TestContext = TestContext> {
beforeEach: (cb: HooksCallback<TC>) => void;
afterEach: (cb: HooksCallback<TC>) => void;
beforeModule: (cb: GlobalCallback) => void;
afterModule: (cb: GlobalCallback) => void;
}
export interface GlobalHooks<TC extends TestContext> extends Hooks<TC> {
onSuiteStart: (cb: GlobalCallback) => void;
onSuiteFinish: (cb: GlobalCallback) => void;
}
export type HooksCallback<TC extends TestContext> = (this: TC, assert: Diagnostic) => void | Promise<void>;
export type ModuleCallback<TC extends TestContext> = ((hooks: Hooks<TC>) => void) | (() => void);
export type TestCallback<TC extends TestContext> = (this: TC, assert: Diagnostic) => void | Promise<void>;
export interface TestInfo<TC extends TestContext> {
/* A unique id for the test based on the hash of the full testName */
id: string;
/* The name of the test, not including moduleName */
name: string;
/* The full name of the test including moduleName */
testName: string;
cb: TestCallback<TC>;
skip: boolean;
todo: boolean;
module: ModuleInfo<TC>;
}
export interface OrderedMap<T> {
byName: Map<string, T>;
byOrder: T[];
}
export interface ModuleInfo<TC extends TestContext> {
moduleName: string;
name: string;
cb: ModuleCallback<TC>;
config: {
beforeEach: HooksCallback<TC>[];
afterEach: HooksCallback<TC>[];
beforeModule: GlobalCallback[];
afterModule: GlobalCallback[];
};
tests: OrderedMap<TestInfo<TC>>;
modules: OrderedMap<ModuleInfo<TC>>;
}