@datadog/mobile-react-native 1.0.0-rc5 → 1.0.0-rc6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -17
- package/android/gradle.properties +4 -4
- package/lib/commonjs/DdSdkReactNative.js +31 -31
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +18 -7
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/InternalLog.js +5 -5
- package/lib/commonjs/InternalLog.js.map +1 -1
- package/lib/commonjs/ProxyConfiguration.js.map +1 -1
- package/lib/commonjs/SdkVerbosity.js.map +1 -1
- package/lib/commonjs/TimeProvider.js +72 -0
- package/lib/commonjs/TimeProvider.js.map +1 -0
- package/lib/commonjs/Timer.js +10 -23
- package/lib/commonjs/Timer.js.map +1 -1
- package/lib/commonjs/TrackingConsent.js.map +1 -1
- package/lib/commonjs/foundation.js +19 -54
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/index.js +21 -21
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/internal.js +14 -0
- package/lib/commonjs/internal.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +16 -11
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +19 -23
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +60 -42
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js +46 -19
- package/lib/commonjs/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumXhr.js +0 -4
- package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js +1 -1
- package/lib/commonjs/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js +34 -0
- package/lib/commonjs/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
- package/lib/commonjs/rum/instrumentation/TraceIdentifier.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/DdSdkReactNative.js +29 -29
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +19 -8
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/InternalLog.js +5 -5
- package/lib/module/InternalLog.js.map +1 -1
- package/lib/module/ProxyConfiguration.js.map +1 -1
- package/lib/module/SdkVerbosity.js.map +1 -1
- package/lib/module/TimeProvider.js +63 -0
- package/lib/module/TimeProvider.js.map +1 -0
- package/lib/module/Timer.js +14 -23
- package/lib/module/Timer.js.map +1 -1
- package/lib/module/TrackingConsent.js.map +1 -1
- package/lib/module/foundation.js +16 -39
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/internal.js +2 -0
- package/lib/module/internal.js.map +1 -0
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js +12 -10
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +19 -23
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js +57 -38
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js +44 -17
- package/lib/module/rum/instrumentation/DdRumUserInteractionTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumXhr.js +1 -1
- package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js +1 -1
- package/lib/module/rum/instrumentation/NoOpEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js +25 -0
- package/lib/module/rum/instrumentation/ShallowObjectEqualityChecker.js.map +1 -0
- package/lib/module/rum/instrumentation/TraceIdentifier.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/DdSdkReactNative.d.ts +6 -6
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +14 -3
- package/lib/typescript/TimeProvider.d.ts +20 -0
- package/lib/typescript/Timer.d.ts +3 -2
- package/lib/typescript/index.d.ts +2 -2
- package/lib/typescript/internal.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
- package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +2 -2
- package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +10 -9
- package/lib/typescript/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -3
- package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +13 -3
- package/lib/typescript/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +6 -3
- package/src/DdSdkReactNative.tsx +112 -70
- package/src/DdSdkReactNativeConfiguration.tsx +21 -13
- package/src/InternalLog.tsx +13 -16
- package/src/ProxyConfiguration.tsx +5 -5
- package/src/SdkVerbosity.tsx +4 -4
- package/src/TimeProvider.tsx +64 -0
- package/src/Timer.ts +20 -35
- package/src/TrackingConsent.tsx +3 -3
- package/src/__mocks__/InternalLog.tsx +9 -0
- package/src/__tests__/DdRumWrapper.test.tsx +40 -33
- package/src/__tests__/DdSdkReactNative.test.tsx +697 -513
- package/src/__tests__/InternalLog.test.tsx +114 -117
- package/src/__tests__/TimeProvider.test.tsx +75 -0
- package/src/__tests__/Timer.test.ts +148 -57
- package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +151 -92
- package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +168 -116
- package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +714 -644
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +239 -85
- package/src/__tests__/rum/instrumentation/ShallowObjectEqualityChecker.test.ts +31 -0
- package/src/__tests__/rum/instrumentation/TraceIdentifier.test.tsx +13 -15
- package/src/__tests__/rum/instrumentation/__utils__/XMLHttpRequestMock.ts +97 -0
- package/src/foundation.tsx +13 -10
- package/src/index.tsx +13 -4
- package/src/internal.tsx +1 -0
- package/src/rum/instrumentation/DdEventsInterceptor.tsx +51 -35
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +49 -44
- package/src/rum/instrumentation/DdRumResourceTracking.tsx +308 -238
- package/src/rum/instrumentation/DdRumUserInteractionTracking.tsx +72 -29
- package/src/rum/instrumentation/DdRumXhr.tsx +21 -11
- package/src/rum/instrumentation/EventsInterceptor.tsx +3 -3
- package/src/rum/instrumentation/NoOpEventsInterceptor.tsx +2 -2
- package/src/rum/instrumentation/ShallowObjectEqualityChecker.ts +24 -0
- package/src/rum/instrumentation/TraceIdentifier.tsx +19 -19
- package/src/types.tsx +199 -158
- package/src/version.ts +1 -1
|
@@ -4,185 +4,339 @@
|
|
|
4
4
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import React from 'react';
|
|
8
|
-
import { DdRumUserInteractionTracking } from '../../../rum/instrumentation/DdRumUserInteractionTracking'
|
|
9
|
-
import { DdEventsInterceptor } from '../../../rum/instrumentation/DdEventsInterceptor'
|
|
10
|
-
import { View, Text, Button, TouchableOpacity, TouchableHighlight, TouchableNativeFeedback, TouchableWithoutFeedback } from 'react-native';
|
|
11
7
|
import { render, fireEvent } from '@testing-library/react-native';
|
|
12
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
View,
|
|
10
|
+
Text,
|
|
11
|
+
Button,
|
|
12
|
+
TouchableOpacity,
|
|
13
|
+
TouchableHighlight,
|
|
14
|
+
TouchableNativeFeedback,
|
|
15
|
+
TouchableWithoutFeedback,
|
|
16
|
+
StyleSheet
|
|
17
|
+
} from 'react-native';
|
|
18
|
+
import React from 'react';
|
|
19
|
+
|
|
20
|
+
import { DdEventsInterceptor } from '../../../rum/instrumentation/DdEventsInterceptor';
|
|
21
|
+
import { DdRumUserInteractionTracking } from '../../../rum/instrumentation/DdRumUserInteractionTracking';
|
|
13
22
|
|
|
14
23
|
const styles = StyleSheet.create({
|
|
15
24
|
button: {
|
|
16
|
-
alignItems:
|
|
17
|
-
backgroundColor:
|
|
25
|
+
alignItems: 'center',
|
|
26
|
+
backgroundColor: '#DDDDDD',
|
|
18
27
|
padding: 10
|
|
19
|
-
}
|
|
28
|
+
}
|
|
20
29
|
});
|
|
21
30
|
|
|
22
31
|
jest.mock('../../../rum/instrumentation/DdEventsInterceptor');
|
|
23
32
|
|
|
24
|
-
|
|
25
33
|
// Silence the warning https://github.com/facebook/react-native/issues/11094#issuecomment-263240420
|
|
26
|
-
jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper')
|
|
27
|
-
jest.useFakeTimers()
|
|
34
|
+
jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
|
|
35
|
+
jest.useFakeTimers();
|
|
28
36
|
|
|
29
|
-
let originalMethod:
|
|
37
|
+
let originalMethod: typeof React.createElement;
|
|
30
38
|
|
|
31
39
|
beforeEach(() => {
|
|
32
|
-
originalMethod = React.createElement
|
|
33
|
-
jest.setTimeout(20000)
|
|
34
|
-
})
|
|
40
|
+
originalMethod = React.createElement;
|
|
41
|
+
jest.setTimeout(20000);
|
|
42
|
+
});
|
|
35
43
|
|
|
36
44
|
afterEach(() => {
|
|
37
|
-
DdRumUserInteractionTracking['isTracking'] = false
|
|
38
|
-
React.createElement = originalMethod
|
|
39
|
-
})
|
|
45
|
+
DdRumUserInteractionTracking['isTracking'] = false;
|
|
46
|
+
React.createElement = originalMethod;
|
|
47
|
+
});
|
|
40
48
|
|
|
41
|
-
// Because the way RN decouples the component we cannot assert how many times the `interceptOnPress` function was called.
|
|
49
|
+
// Because the way RN decouples the component we cannot assert how many times the `interceptOnPress` function was called.
|
|
42
50
|
// This problem is being handled at the EventInterceptor level.
|
|
43
51
|
|
|
44
52
|
it('M intercept and send a RUM event W onPress { Button component }', async () => {
|
|
45
53
|
// GIVEN
|
|
46
|
-
DdRumUserInteractionTracking.startTracking()
|
|
47
|
-
const { getByText } = render(
|
|
54
|
+
DdRumUserInteractionTracking.startTracking();
|
|
55
|
+
const { getByText } = render(
|
|
48
56
|
<View>
|
|
49
57
|
<Button
|
|
50
58
|
title="Click me"
|
|
51
59
|
accessibilityLabel="click_me_button"
|
|
52
|
-
onPress={
|
|
60
|
+
onPress={event => {}}
|
|
53
61
|
/>
|
|
54
62
|
</View>
|
|
55
|
-
)
|
|
56
|
-
const testButton = getByText(
|
|
63
|
+
);
|
|
64
|
+
const testButton = getByText('Click me');
|
|
57
65
|
|
|
58
66
|
// WHEN
|
|
59
|
-
fireEvent(testButton,
|
|
67
|
+
fireEvent(testButton, 'press');
|
|
60
68
|
|
|
61
69
|
// THEN
|
|
62
|
-
const currentMockedEventsInterceptor =
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
70
|
+
const currentMockedEventsInterceptor =
|
|
71
|
+
DdEventsInterceptor.mock.instances[
|
|
72
|
+
DdEventsInterceptor.mock.instances.length - 1
|
|
73
|
+
];
|
|
74
|
+
const mockedInterceptOnPressFunction =
|
|
75
|
+
currentMockedEventsInterceptor.interceptOnPress;
|
|
76
|
+
expect(mockedInterceptOnPressFunction).toBeCalled();
|
|
77
|
+
});
|
|
66
78
|
|
|
67
79
|
it('M intercept only once W startTracking { called multiple times }', async () => {
|
|
68
80
|
// GIVEN
|
|
69
|
-
DdRumUserInteractionTracking.startTracking()
|
|
70
|
-
DdRumUserInteractionTracking.startTracking()
|
|
71
|
-
DdRumUserInteractionTracking.startTracking()
|
|
72
|
-
const { getByText } = render(
|
|
81
|
+
DdRumUserInteractionTracking.startTracking();
|
|
82
|
+
DdRumUserInteractionTracking.startTracking();
|
|
83
|
+
DdRumUserInteractionTracking.startTracking();
|
|
84
|
+
const { getByText } = render(
|
|
73
85
|
<View>
|
|
74
86
|
<Button
|
|
75
87
|
title="Click me"
|
|
76
88
|
accessibilityLabel="click_me_button"
|
|
77
|
-
onPress={
|
|
89
|
+
onPress={event => {}}
|
|
78
90
|
/>
|
|
79
91
|
</View>
|
|
80
|
-
)
|
|
81
|
-
const testButton = getByText(
|
|
92
|
+
);
|
|
93
|
+
const testButton = getByText('Click me');
|
|
82
94
|
|
|
83
95
|
// WHEN
|
|
84
|
-
fireEvent(testButton,
|
|
96
|
+
fireEvent(testButton, 'press');
|
|
85
97
|
|
|
86
98
|
// THEN
|
|
87
|
-
const currentMockedEventsInterceptor =
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
99
|
+
const currentMockedEventsInterceptor =
|
|
100
|
+
DdEventsInterceptor.mock.instances[
|
|
101
|
+
DdEventsInterceptor.mock.instances.length - 1
|
|
102
|
+
];
|
|
103
|
+
const mockedInterceptOnPressFunction =
|
|
104
|
+
currentMockedEventsInterceptor.interceptOnPress;
|
|
105
|
+
expect(mockedInterceptOnPressFunction).toBeCalled();
|
|
106
|
+
});
|
|
91
107
|
|
|
92
108
|
it('M intercept and send a RUM event W onPress { TouchableOpacity component }', async () => {
|
|
93
109
|
// GIVEN
|
|
94
|
-
DdRumUserInteractionTracking.startTracking()
|
|
95
|
-
const { getByText } = render(
|
|
110
|
+
DdRumUserInteractionTracking.startTracking();
|
|
111
|
+
const { getByText } = render(
|
|
96
112
|
<View>
|
|
97
113
|
<TouchableOpacity
|
|
98
114
|
style={styles.button}
|
|
99
115
|
accessibilityLabel="click_me_touchable_opacity"
|
|
100
|
-
onPress={
|
|
116
|
+
onPress={event => {}}
|
|
101
117
|
>
|
|
102
118
|
<Text>Click me</Text>
|
|
103
119
|
</TouchableOpacity>
|
|
104
120
|
</View>
|
|
105
|
-
)
|
|
106
|
-
const testButton = getByText(
|
|
121
|
+
);
|
|
122
|
+
const testButton = getByText('Click me');
|
|
107
123
|
|
|
108
124
|
// WHEN
|
|
109
|
-
fireEvent(testButton,
|
|
125
|
+
fireEvent(testButton, 'press');
|
|
110
126
|
|
|
111
127
|
// THEN
|
|
112
|
-
const currentMockedEventsInterceptor =
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
128
|
+
const currentMockedEventsInterceptor =
|
|
129
|
+
DdEventsInterceptor.mock.instances[
|
|
130
|
+
DdEventsInterceptor.mock.instances.length - 1
|
|
131
|
+
];
|
|
132
|
+
const mockedInterceptOnPressFunction =
|
|
133
|
+
currentMockedEventsInterceptor.interceptOnPress;
|
|
134
|
+
expect(mockedInterceptOnPressFunction).toBeCalled();
|
|
135
|
+
});
|
|
116
136
|
|
|
117
137
|
it('M intercept and send a RUM event W onPress { TouchableHighlight component }', async () => {
|
|
118
138
|
// GIVEN
|
|
119
|
-
DdRumUserInteractionTracking.startTracking()
|
|
120
|
-
const { getByText } = render(
|
|
139
|
+
DdRumUserInteractionTracking.startTracking();
|
|
140
|
+
const { getByText } = render(
|
|
121
141
|
<View>
|
|
122
|
-
<TouchableHighlight
|
|
123
|
-
onPress={(event) => { }}
|
|
124
|
-
underlayColor="white">
|
|
142
|
+
<TouchableHighlight onPress={event => {}} underlayColor="white">
|
|
125
143
|
<View style={styles.button}>
|
|
126
144
|
<Text>Click me</Text>
|
|
127
145
|
</View>
|
|
128
146
|
</TouchableHighlight>
|
|
129
147
|
</View>
|
|
130
|
-
)
|
|
131
|
-
const testButton = getByText(
|
|
148
|
+
);
|
|
149
|
+
const testButton = getByText('Click me');
|
|
132
150
|
|
|
133
151
|
// WHEN
|
|
134
|
-
fireEvent(testButton,
|
|
152
|
+
fireEvent(testButton, 'press');
|
|
135
153
|
|
|
136
154
|
// THEN
|
|
137
|
-
const currentMockedEventsInterceptor =
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
155
|
+
const currentMockedEventsInterceptor =
|
|
156
|
+
DdEventsInterceptor.mock.instances[
|
|
157
|
+
DdEventsInterceptor.mock.instances.length - 1
|
|
158
|
+
];
|
|
159
|
+
const mockedInterceptOnPressFunction =
|
|
160
|
+
currentMockedEventsInterceptor.interceptOnPress;
|
|
161
|
+
expect(mockedInterceptOnPressFunction).toBeCalled();
|
|
162
|
+
});
|
|
141
163
|
|
|
142
164
|
it('M intercept and send a RUM event W onPress { TouchableNativeFeedback component }', async () => {
|
|
143
165
|
// GIVEN
|
|
144
|
-
DdRumUserInteractionTracking.startTracking()
|
|
145
|
-
const { getByText } = render(
|
|
166
|
+
DdRumUserInteractionTracking.startTracking();
|
|
167
|
+
const { getByText } = render(
|
|
146
168
|
<View>
|
|
147
|
-
<TouchableNativeFeedback
|
|
148
|
-
onPress={(event) => { }}>
|
|
169
|
+
<TouchableNativeFeedback onPress={event => {}}>
|
|
149
170
|
<View style={styles.button}>
|
|
150
171
|
<Text style={styles.button}>Click me</Text>
|
|
151
172
|
</View>
|
|
152
173
|
</TouchableNativeFeedback>
|
|
153
174
|
</View>
|
|
154
|
-
)
|
|
155
|
-
const testButton = getByText(
|
|
175
|
+
);
|
|
176
|
+
const testButton = getByText('Click me');
|
|
156
177
|
|
|
157
178
|
// WHEN
|
|
158
|
-
fireEvent(testButton,
|
|
179
|
+
fireEvent(testButton, 'press');
|
|
159
180
|
|
|
160
181
|
// THEN
|
|
161
|
-
const currentMockedEventsInterceptor =
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
182
|
+
const currentMockedEventsInterceptor =
|
|
183
|
+
DdEventsInterceptor.mock.instances[
|
|
184
|
+
DdEventsInterceptor.mock.instances.length - 1
|
|
185
|
+
];
|
|
186
|
+
const mockedInterceptOnPressFunction =
|
|
187
|
+
currentMockedEventsInterceptor.interceptOnPress;
|
|
188
|
+
expect(mockedInterceptOnPressFunction).toBeCalled();
|
|
189
|
+
});
|
|
165
190
|
|
|
166
191
|
it('M intercept and send a RUM event W onPress { TouchableWithoutFeedback component }', async () => {
|
|
167
192
|
// GIVEN
|
|
168
|
-
DdRumUserInteractionTracking.startTracking()
|
|
169
|
-
const { getByText } = render(
|
|
193
|
+
DdRumUserInteractionTracking.startTracking();
|
|
194
|
+
const { getByText } = render(
|
|
170
195
|
<View>
|
|
171
|
-
<TouchableWithoutFeedback
|
|
172
|
-
onPress={(event) => { }}>
|
|
196
|
+
<TouchableWithoutFeedback onPress={event => {}}>
|
|
173
197
|
<View style={styles.button}>
|
|
174
198
|
<Text style={styles.button}>Click me</Text>
|
|
175
199
|
</View>
|
|
176
200
|
</TouchableWithoutFeedback>
|
|
177
201
|
</View>
|
|
178
|
-
)
|
|
179
|
-
const testButton = getByText(
|
|
202
|
+
);
|
|
203
|
+
const testButton = getByText('Click me');
|
|
204
|
+
|
|
205
|
+
// WHEN
|
|
206
|
+
fireEvent(testButton, 'press');
|
|
207
|
+
|
|
208
|
+
// THEN
|
|
209
|
+
const currentMockedEventsInterceptor =
|
|
210
|
+
DdEventsInterceptor.mock.instances[
|
|
211
|
+
DdEventsInterceptor.mock.instances.length - 1
|
|
212
|
+
];
|
|
213
|
+
const mockedInterceptOnPressFunction =
|
|
214
|
+
currentMockedEventsInterceptor.interceptOnPress;
|
|
215
|
+
expect(mockedInterceptOnPressFunction).toBeCalled();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('M keep memoization working for elements W an onPress prop is passed', async () => {
|
|
219
|
+
// GIVEN
|
|
220
|
+
DdRumUserInteractionTracking.startTracking();
|
|
221
|
+
let rendersCount = 0;
|
|
222
|
+
const DummyComponent = props => {
|
|
223
|
+
rendersCount++;
|
|
224
|
+
return (
|
|
225
|
+
<TouchableWithoutFeedback onPress={props.onPress}>
|
|
226
|
+
<View style={styles.button}>
|
|
227
|
+
<Text style={styles.button}>Click me</Text>
|
|
228
|
+
</View>
|
|
229
|
+
</TouchableWithoutFeedback>
|
|
230
|
+
);
|
|
231
|
+
};
|
|
232
|
+
const stableOnPress = () => {};
|
|
233
|
+
const MemoizedComponent = React.memo(DummyComponent);
|
|
234
|
+
const { rerender } = render(<MemoizedComponent onPress={stableOnPress} />);
|
|
235
|
+
expect(rendersCount).toBe(1);
|
|
180
236
|
|
|
181
237
|
// WHEN
|
|
182
|
-
|
|
238
|
+
rerender(<MemoizedComponent onPress={stableOnPress} />);
|
|
239
|
+
// THEN
|
|
240
|
+
expect(rendersCount).toBe(1);
|
|
183
241
|
|
|
242
|
+
// WHEN
|
|
243
|
+
rerender(<MemoizedComponent onPress={() => {}} />);
|
|
244
|
+
// THEN
|
|
245
|
+
expect(rendersCount).toBe(2);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('M keep memoization working for elements W no onPress prop is passed', async () => {
|
|
249
|
+
// GIVEN
|
|
250
|
+
DdRumUserInteractionTracking.startTracking();
|
|
251
|
+
let rendersCount = 0;
|
|
252
|
+
const DummyComponent = props => {
|
|
253
|
+
rendersCount++;
|
|
254
|
+
return (
|
|
255
|
+
<View style={styles.button}>
|
|
256
|
+
<Text style={styles.button}>{props.title}</Text>
|
|
257
|
+
</View>
|
|
258
|
+
);
|
|
259
|
+
};
|
|
260
|
+
const MemoizedComponent = React.memo(DummyComponent);
|
|
261
|
+
const { rerender } = render(<MemoizedComponent title={'Click me'} />);
|
|
262
|
+
expect(rendersCount).toBe(1);
|
|
263
|
+
|
|
264
|
+
// WHEN
|
|
265
|
+
rerender(<MemoizedComponent title={'Click me'} />);
|
|
184
266
|
// THEN
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
})
|
|
267
|
+
expect(rendersCount).toBe(1);
|
|
268
|
+
|
|
269
|
+
// WHEN
|
|
270
|
+
rerender(<MemoizedComponent title={'New title'} />);
|
|
271
|
+
// THEN
|
|
272
|
+
expect(rendersCount).toBe(2);
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it('M keep memoization working for elements W an onPress prop is passed and custom arePropsEqual specified', async () => {
|
|
276
|
+
// GIVEN
|
|
277
|
+
DdRumUserInteractionTracking.startTracking();
|
|
278
|
+
let rendersCount = 0;
|
|
279
|
+
const DummyComponent = props => {
|
|
280
|
+
rendersCount++;
|
|
281
|
+
return (
|
|
282
|
+
<TouchableWithoutFeedback onPress={props.onPress}>
|
|
283
|
+
<View style={styles.button}>
|
|
284
|
+
<Text style={styles.button}>{props.title}</Text>
|
|
285
|
+
</View>
|
|
286
|
+
</TouchableWithoutFeedback>
|
|
287
|
+
);
|
|
288
|
+
};
|
|
289
|
+
const stableOnPress = () => {};
|
|
290
|
+
const MemoizedComponent = React.memo(
|
|
291
|
+
DummyComponent,
|
|
292
|
+
(previousProps, nextProps) => previousProps.title === nextProps.title
|
|
293
|
+
);
|
|
294
|
+
const { rerender } = render(
|
|
295
|
+
<MemoizedComponent onPress={stableOnPress} title={'Click me'} />
|
|
296
|
+
);
|
|
297
|
+
expect(rendersCount).toBe(1);
|
|
298
|
+
|
|
299
|
+
// WHEN
|
|
300
|
+
rerender(<MemoizedComponent onPress={stableOnPress} title={'Click me'} />);
|
|
301
|
+
// THEN
|
|
302
|
+
expect(rendersCount).toBe(1);
|
|
303
|
+
|
|
304
|
+
// WHEN
|
|
305
|
+
rerender(<MemoizedComponent onPress={stableOnPress} title={'New title'} />);
|
|
306
|
+
// THEN
|
|
307
|
+
expect(rendersCount).toBe(2);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it('M keep memoization working for elements W an onPress prop is passed and custom arePropsEqual specified including onPress check', async () => {
|
|
311
|
+
// GIVEN
|
|
312
|
+
DdRumUserInteractionTracking.startTracking();
|
|
313
|
+
let rendersCount = 0;
|
|
314
|
+
const DummyComponent = props => {
|
|
315
|
+
rendersCount++;
|
|
316
|
+
return (
|
|
317
|
+
<TouchableWithoutFeedback onPress={props.onPress}>
|
|
318
|
+
<View style={styles.button}>
|
|
319
|
+
<Text style={styles.button}>Click me</Text>
|
|
320
|
+
</View>
|
|
321
|
+
</TouchableWithoutFeedback>
|
|
322
|
+
);
|
|
323
|
+
};
|
|
324
|
+
const stableOnPress = () => {};
|
|
325
|
+
const MemoizedComponent = React.memo(
|
|
326
|
+
DummyComponent,
|
|
327
|
+
(previousProps, nextProps) =>
|
|
328
|
+
previousProps.onPress === nextProps.onPress
|
|
329
|
+
);
|
|
330
|
+
const { rerender } = render(<MemoizedComponent onPress={stableOnPress} />);
|
|
331
|
+
expect(rendersCount).toBe(1);
|
|
332
|
+
|
|
333
|
+
// WHEN
|
|
334
|
+
rerender(<MemoizedComponent onPress={stableOnPress} />);
|
|
335
|
+
// THEN
|
|
336
|
+
expect(rendersCount).toBe(1);
|
|
337
|
+
|
|
338
|
+
// WHEN
|
|
339
|
+
rerender(<MemoizedComponent onPress={() => {}} />);
|
|
340
|
+
// THEN
|
|
341
|
+
expect(rendersCount).toBe(2);
|
|
342
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { areObjectShallowEqual } from '../../../rum/instrumentation/ShallowObjectEqualityChecker';
|
|
8
|
+
|
|
9
|
+
describe('areObjectValuesEqual', () => {
|
|
10
|
+
it('returns false for different object values', () => {
|
|
11
|
+
const objectA = { a: 22 };
|
|
12
|
+
const objectB = { a: 23 };
|
|
13
|
+
expect(areObjectShallowEqual(objectA, objectB)).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
it('returns false for subsets', () => {
|
|
16
|
+
const objectA = { a: 22 };
|
|
17
|
+
const objectB = { a: 22, b: 66 };
|
|
18
|
+
expect(areObjectShallowEqual(objectA, objectB)).toBe(false);
|
|
19
|
+
expect(areObjectShallowEqual(objectB, objectA)).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
it('returns false for equal but not stricly equal values', () => {
|
|
22
|
+
const objectA = { a: false };
|
|
23
|
+
const objectB = { a: 0 };
|
|
24
|
+
expect(areObjectShallowEqual(objectA, objectB)).toBe(false);
|
|
25
|
+
});
|
|
26
|
+
it('returns true for identical object values', () => {
|
|
27
|
+
const objectA = { a: 22 };
|
|
28
|
+
const objectB = { a: 22 };
|
|
29
|
+
expect(areObjectShallowEqual(objectA, objectB)).toBe(true);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -1,33 +1,31 @@
|
|
|
1
|
-
import { generateTraceId } from '../../../rum/instrumentation/TraceIdentifier'
|
|
2
|
-
|
|
1
|
+
import { generateTraceId } from '../../../rum/instrumentation/TraceIdentifier';
|
|
3
2
|
|
|
4
3
|
it('M return an unique identifier W toString', async () => {
|
|
5
4
|
// GIVEN
|
|
6
|
-
const generatedIds = new Set<
|
|
7
|
-
const iterations = 100
|
|
8
|
-
|
|
5
|
+
const generatedIds = new Set<string>();
|
|
6
|
+
const iterations = 100;
|
|
7
|
+
let counter = iterations;
|
|
9
8
|
|
|
10
9
|
// WHEN
|
|
11
10
|
while (counter-- > 0) {
|
|
12
|
-
generatedIds.add(generateTraceId())
|
|
11
|
+
generatedIds.add(generateTraceId());
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
// THEN
|
|
16
|
-
expect(generatedIds.size).toBe(iterations)
|
|
17
|
-
})
|
|
15
|
+
expect(generatedIds.size).toBe(iterations);
|
|
16
|
+
});
|
|
18
17
|
|
|
19
18
|
it('M return an 64 bits positive integer W toString', async () => {
|
|
20
|
-
let iterations = 100
|
|
19
|
+
let iterations = 100;
|
|
21
20
|
while (iterations-- > 0) {
|
|
22
21
|
// GIVEN
|
|
23
|
-
const id = generateTraceId()
|
|
22
|
+
const id = generateTraceId();
|
|
24
23
|
|
|
25
24
|
// THEN
|
|
26
|
-
expect(id).toMatch(/[1-9]{1,19}/)
|
|
25
|
+
expect(id).toMatch(/[1-9]{1,19}/);
|
|
27
26
|
// should be less than the max 64 bits integer
|
|
28
|
-
if (id.length
|
|
29
|
-
expect(id <
|
|
27
|
+
if (id.length === 19) {
|
|
28
|
+
expect(id < '9223372036854775807').toBeTruthy();
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
})
|
|
31
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
|
+
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
|
+
* Copyright 2016-Present Datadog, Inc.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export class XMLHttpRequestMock implements XMLHttpRequest {
|
|
8
|
+
static readonly UNSENT = 0;
|
|
9
|
+
static readonly OPENED = 1;
|
|
10
|
+
static readonly HEADERS_RECEIVED = 2;
|
|
11
|
+
static readonly LOADING = 3;
|
|
12
|
+
static readonly DONE = 4;
|
|
13
|
+
|
|
14
|
+
public response: any;
|
|
15
|
+
public responseType: XMLHttpRequestResponseType;
|
|
16
|
+
public status: number = 0;
|
|
17
|
+
public readyState: number = XMLHttpRequestMock.UNSENT;
|
|
18
|
+
public requestHeaders: Map<string, string> = new Map();
|
|
19
|
+
public responseHeaders: Map<string, string> = new Map();
|
|
20
|
+
|
|
21
|
+
constructor() {}
|
|
22
|
+
responseText: string;
|
|
23
|
+
responseURL: string;
|
|
24
|
+
responseXML: Document;
|
|
25
|
+
statusText: string;
|
|
26
|
+
timeout: number;
|
|
27
|
+
upload: XMLHttpRequestUpload;
|
|
28
|
+
withCredentials: boolean;
|
|
29
|
+
getAllResponseHeaders = jest.fn();
|
|
30
|
+
overrideMimeType = jest.fn();
|
|
31
|
+
DONE: number;
|
|
32
|
+
HEADERS_RECEIVED: number;
|
|
33
|
+
LOADING: number;
|
|
34
|
+
OPENED: number;
|
|
35
|
+
UNSENT: number;
|
|
36
|
+
addEventListener = jest.fn();
|
|
37
|
+
removeEventListener = jest.fn();
|
|
38
|
+
onabort: (this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any;
|
|
39
|
+
onerror: (this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any;
|
|
40
|
+
onload: (this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any;
|
|
41
|
+
onloadend: (this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any;
|
|
42
|
+
onloadstart: (this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any;
|
|
43
|
+
onprogress: (this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any;
|
|
44
|
+
ontimeout: (this: XMLHttpRequest, ev: ProgressEvent<EventTarget>) => any;
|
|
45
|
+
dispatchEvent(event: Event): boolean {
|
|
46
|
+
throw new Error('Method not implemented.');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public originalOpenCalled: boolean = false;
|
|
50
|
+
public originalSendCalled: boolean = false;
|
|
51
|
+
public originalOnReadyStateChangeCalled: boolean = false;
|
|
52
|
+
|
|
53
|
+
open(method: string, url: string) {
|
|
54
|
+
this.originalOpenCalled = true;
|
|
55
|
+
}
|
|
56
|
+
send() {
|
|
57
|
+
this.originalSendCalled = true;
|
|
58
|
+
}
|
|
59
|
+
onreadystatechange() {
|
|
60
|
+
this.originalOnReadyStateChangeCalled = true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
abort() {
|
|
64
|
+
this.status = 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
notifyResponseArrived() {
|
|
68
|
+
this.readyState = XMLHttpRequestMock.HEADERS_RECEIVED;
|
|
69
|
+
this.onreadystatechange();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
complete(
|
|
73
|
+
status: number,
|
|
74
|
+
response?: any,
|
|
75
|
+
responseType?: XMLHttpRequestResponseType
|
|
76
|
+
) {
|
|
77
|
+
this.response = response;
|
|
78
|
+
if (response) {
|
|
79
|
+
this.responseType = responseType ?? 'text';
|
|
80
|
+
}
|
|
81
|
+
this.status = status;
|
|
82
|
+
this.readyState = XMLHttpRequestMock.DONE;
|
|
83
|
+
this.onreadystatechange();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
setRequestHeader(header: string, value: string): void {
|
|
87
|
+
this.requestHeaders[header] = value;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
setResponseHeader(header: string, value: string): void {
|
|
91
|
+
this.responseHeaders[header] = value;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
getResponseHeader(header: string): string | null {
|
|
95
|
+
return this.responseHeaders[header];
|
|
96
|
+
}
|
|
97
|
+
}
|