-
-
Notifications
You must be signed in to change notification settings - Fork 360
Expand file tree
/
Copy pathEndToEndTests.tsx
More file actions
86 lines (77 loc) · 2.42 KB
/
EndToEndTests.tsx
File metadata and controls
86 lines (77 loc) · 2.42 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
import * as Sentry from '@sentry/react-native';
import * as React from 'react';
import { Text, View } from 'react-native';
const E2E_TESTS_READY_TEXT = 'E2E Tests Ready';
const EndToEndTestsScreen = (): JSX.Element => {
const [isReady, setIsReady] = React.useState(false);
const [eventId, setEventId] = React.useState<string | null>(null);
const [error, setError] = React.useState<string>('No error');
React.useEffect(() => {
const client: Sentry.ReactNativeClient | undefined = Sentry.getClient();
if (!client) {
setError('Client is not initialized');
return;
}
// WARNING: This is only for testing purposes.
// We only do this to render the eventId onto the UI for end to end tests.
// Chain with existing beforeSend (set by mobileReplayIntegration) to
// preserve replay_id processing.
const existingBeforeSend = client.getOptions().beforeSend;
client.getOptions().beforeSend = async (e, hint) => {
const result = existingBeforeSend ? await existingBeforeSend(e, hint) : e;
if (result) {
setEventId(result.event_id);
}
return result;
};
setIsReady(true);
}, []);
const testCases = [
{
id: 'captureMessage',
name: 'Capture Message',
action: () => Sentry.captureMessage('React Native Test Message'),
},
{
id: 'captureException',
name: 'Capture Exception',
action: () => Sentry.captureException(new Error('captureException test')),
},
{
id: 'unhandledPromiseRejection',
name: 'Unhandled Promise Rejection',
action: async () => await Promise.reject(new Error('Unhandled Promise Rejection')),
},
{
id: 'feedback',
name: 'Feedback',
action: () => Sentry.showFeedbackButton(),
},
{
id: 'close',
name: 'Close',
action: async () => await Sentry.close(),
},
{
id: 'crash',
name: 'Crash',
action: () => Sentry.nativeCrash(),
},
];
return (
<View>
<Text>{isReady ? E2E_TESTS_READY_TEXT : 'Loading...'}</Text>
<Text>{error}</Text>
{eventId ? <Text testID='eventId'>{eventId}</Text> : <Text>No event ID</Text>}
<Text onPress={() => setEventId(null)}>
Clear Event Id
</Text>
{testCases.map((testCase) => (
<Text key={testCase.id} onPress={testCase.action}>
{testCase.name}
</Text>
))}
</View>
);
};
export default EndToEndTestsScreen;