-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathshared.ts
More file actions
168 lines (156 loc) · 4.02 KB
/
shared.ts
File metadata and controls
168 lines (156 loc) · 4.02 KB
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
import type {
TestRunnerEvents,
TestSuiteResult,
} from './shared/test-runner.js';
import type { TestCollectorEvents } from './shared/test-collector.js';
import type { BundlerEvents } from './shared/bundler.js';
import type { HarnessPlatform } from '@react-native-harness/platforms';
export type FileReference = {
path: string;
};
export type ImageSnapshotOptions = {
/**
* The name of the snapshot. This is required and must be unique within the test.
*/
name: string;
/**
* Comparison algorithm to use.
* @default 'pixelmatch'
*/
comparisonMethod?: 'pixelmatch' | 'ssim';
/**
* Matching threshold for pixelmatch, ranges from 0 to 1. Smaller values make the comparison more sensitive.
* @default 0.1
*/
threshold?: number;
/**
* Threshold for test failure.
*/
failureThreshold?: number;
/**
* Type of failure threshold.
* @default 'pixel'
*/
failureThresholdType?: 'pixel' | 'percent';
/**
* Minimum similarity score for SSIM comparison (0-1).
* @default 0.95
*/
ssimThreshold?: number;
/**
* Regions to ignore during comparison.
*/
ignoreRegions?: Array<{
x: number;
y: number;
width: number;
height: number;
}>;
/**
* If true, disables detecting and ignoring anti-aliased pixels.
* @default false
*/
includeAA?: boolean;
/**
* Blending factor of unchanged pixels in the diff output.
* Ranges from 0 for pure white to 1 for original brightness
* @default 0.1
*/
alpha?: number;
/**
* The color of differing pixels in the diff output.
* @default [255, 0, 0]
*/
diffColor?: [number, number, number];
/**
* An alternative color to use for dark on light differences to differentiate between "added" and "removed" parts.
* If not provided, all differing pixels use the color specified by `diffColor`.
* @default null
*/
diffColorAlt?: [number, number, number];
};
export type {
TestCollectorEvents,
TestCollectionStartedEvent,
TestCollectionFinishedEvent,
TestSuite,
TestCase,
CollectionResult,
} from './shared/test-collector.js';
export type {
TestRunnerEvents,
TestRunnerFileStartedEvent,
TestRunnerFileFinishedEvent,
TestRunnerSuiteStartedEvent,
TestRunnerTestStartedEvent,
TestRunnerTestFinishedEvent,
TestRunnerSuiteFinishedEvent,
TestSuiteResult,
TestResult,
TestResultStatus,
SerializedError,
CodeFrame,
} from './shared/test-runner.js';
export type {
ModuleBundlingStartedEvent,
ModuleBundlingFinishedEvent,
ModuleBundlingFailedEvent,
SetupFileBundlingStartedEvent,
SetupFileBundlingFinishedEvent,
SetupFileBundlingFailedEvent,
BundlerEvents,
} from './shared/bundler.js';
export type DeviceDescriptor = {
platform: 'ios' | 'android' | 'vega' | 'web';
manufacturer: string;
model: string;
osVersion: string;
};
export type BridgeEvents =
| TestCollectorEvents
| TestRunnerEvents
| BundlerEvents;
export type BridgeEventsMap = {
[K in BridgeEvents['type']]: (
event: Extract<BridgeEvents, { type: K }>
) => void;
};
export type TestExecutionOptions = {
testNamePattern?: string;
setupFiles?: string[];
setupFilesAfterEnv?: string[];
runner: string;
};
export type BridgeClientFunctions = {
runTests: (
path: string,
options: TestExecutionOptions
) => Promise<TestSuiteResult>;
};
export type BinaryDataReference = {
type: 'binary';
transferId: number;
size: number;
mimeType: 'image/png';
};
export type ScreenshotData = BinaryDataReference;
export type BridgeServerFunctions = {
reportReady: (device: DeviceDescriptor) => void;
emitEvent: <TEvent extends BridgeEvents>(
event: TEvent['type'],
data: TEvent
) => void;
'device.screenshot.receive': (
reference: BinaryDataReference,
metadata: { width: number; height: number }
) => Promise<FileReference>;
'test.matchImageSnapshot': (
screenshot: FileReference,
testPath: string,
options: ImageSnapshotOptions,
runner: string
) => Promise<{ pass: boolean; message: string }>;
};
export type HarnessContext = {
platform: HarnessPlatform;
};