-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
RuntimeTestsApi.ts
213 lines (180 loc) · 5.95 KB
/
RuntimeTestsApi.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import { Component, ReactElement } from 'react';
import { TestRunner } from './TestRunner';
import { TestComponent } from './TestComponent';
import type { SharedValue } from 'react-native-reanimated';
import { TestConfiguration, TestValue, NullableTestValue, DescribeDecorator, TestDecorator } from './types';
export { Presets } from './Presets';
const testRunner = new TestRunner();
type DescribeFunction = (name: string, buildSuite: () => void) => void;
export const describe: {
(name: string, buildSuite: () => void): void;
skip: DescribeFunction;
only: DescribeFunction;
} = Object.assign(
(name: string, buildSuite: () => void) => {
testRunner.describe(name, buildSuite, null);
},
{
skip: (name: string, buildSuite: () => void) => {
testRunner.describe(name, buildSuite, DescribeDecorator.SKIP);
},
only: (name: string, buildSuite: () => void) => {
testRunner.describe(name, buildSuite, DescribeDecorator.SKIP);
},
},
);
type TestEachFunction = <T>(
examples: Array<T>,
) => (name: string, testCase: (example: T, index?: number) => void) => void;
type TestEachFunctionWithWarning = <T>(
examples: Array<T>,
) => (name: string, expectedWarning: string, testCase: (example: T, index?: number) => void) => void;
export const test: {
(name: string, testCase: () => void): void;
each: TestEachFunction;
skip: { (name: string, testCase: () => void): void; each: TestEachFunction };
only: { (name: string, testCase: () => void): void; each: TestEachFunction };
failing: { (name: string, warningMessage: string, testCase: () => void): void; each: TestEachFunctionWithWarning };
warn: { (name: string, warningMessage: string, testCase: () => void): void; each: TestEachFunctionWithWarning };
} = Object.assign(
(name: string, testCase: () => void) => {
testRunner.test(name, testCase, null);
},
{
each: <T>(examples: Array<T>) => {
return testRunner.testEach(examples, null);
},
skip: Object.assign(
(name: string, testCase: () => void) => {
testRunner.test(name, testCase, TestDecorator.SKIP);
},
{
each: <T>(examples: Array<T>) => {
return testRunner.testEach(examples, TestDecorator.SKIP);
},
},
),
only: Object.assign(
(name: string, testCase: () => void) => {
testRunner.test(name, testCase, TestDecorator.ONLY);
},
{
each: <T>(examples: Array<T>) => {
return testRunner.testEach(examples, null);
},
},
),
failing: Object.assign(
(name: string, warningMessage: string, testCase: () => void) => {
testRunner.test(name, testCase, TestDecorator.FAILING, warningMessage);
},
{
each: <T>(examples: Array<T>) => {
return testRunner.testEachErrorMsg(examples, TestDecorator.FAILING);
},
},
),
warn: Object.assign(
(name: string, expectedWarning: string, testCase: () => void) => {
testRunner.test(name, testCase, TestDecorator.WARN);
},
{
each: <T>(examples: Array<T>) => {
return testRunner.testEachErrorMsg(examples, TestDecorator.WARN);
},
},
),
},
);
export function beforeAll(job: () => void) {
testRunner.beforeAll(job);
}
export function beforeEach(job: () => void) {
testRunner.beforeEach(job);
}
export function afterEach(job: () => void) {
testRunner.afterEach(job);
}
export function afterAll(job: () => void) {
testRunner.afterAll(job);
}
export async function render(component: ReactElement<Component> | null) {
return testRunner.render(component);
}
export async function clearRenderOutput() {
return testRunner.clearRenderOutput();
}
export function useTestRef(name: string) {
return testRunner.useTestRef(name);
}
const testRunnerCallTrackerFn = testRunner.callTracker;
export function callTracker(name: string) {
'worklet';
return testRunnerCallTrackerFn(name);
}
export function callTrackerFn(name: string) {
'worklet';
return () => {
'worklet';
testRunnerCallTrackerFn(name);
};
}
export function getTrackerCallCount(name: string) {
return testRunner.getTrackerCallCount(name);
}
export function registerValue(name: string, value: SharedValue) {
return testRunner.registerValue(name, value);
}
export async function getRegisteredValue(name: string) {
return await testRunner.getRegisteredValue(name);
}
export function getTestComponent(name: string): TestComponent {
return testRunner.getTestComponent(name);
}
export async function runTests() {
await testRunner.runTests();
}
export async function wait(delay: number) {
return testRunner.wait(delay);
}
const testRunnerNotifyFn = testRunner.notify;
export async function notify(name: string) {
'worklet';
return testRunnerNotifyFn(name);
}
export async function waitForNotify(name: string) {
return testRunner.waitForNotify(name);
}
export function expect(value: TestValue) {
return testRunner.expect(value);
}
export function expectNullable(currentValue: NullableTestValue) {
return testRunner.expectNullable(currentValue);
}
export function expectNotNullable(currentValue: NullableTestValue) {
return testRunner.expectNotNullable(currentValue);
}
export function configure(config: TestConfiguration) {
return testRunner.configure(config);
}
export async function mockAnimationTimer() {
await testRunner.mockAnimationTimer();
}
export async function unmockAnimationTimer() {
await testRunner.unmockAnimationTimer();
}
export async function setAnimationTimestamp(timestamp: number) {
await testRunner.setAnimationTimestamp(timestamp);
}
export async function advanceAnimationByTime(time: number) {
await testRunner.advanceAnimationByTime(time);
}
export async function advanceAnimationByFrames(frameCount: number) {
await testRunner.advanceAnimationByFrames(frameCount);
}
export async function recordAnimationUpdates() {
return testRunner.recordAnimationUpdates();
}
export async function stopRecordingAnimationUpdates() {
testRunner.stopRecordingAnimationUpdates();
}