@datadog/mobile-react-navigation 1.0.0-rc5 → 1.0.0-rc9
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/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js +77 -51
- package/lib/commonjs/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/react-navigation.js +2 -0
- package/lib/commonjs/rum/instrumentation/react-navigation.js.map +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js +74 -52
- package/lib/module/rum/instrumentation/DdRumReactNavigationTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/react-navigation.js +2 -0
- package/lib/module/rum/instrumentation/react-navigation.js.map +1 -0
- package/lib/typescript/core/src/DdSdkReactNative.d.ts +6 -6
- package/lib/typescript/core/src/DdSdkReactNativeConfiguration.d.ts +15 -3
- package/lib/typescript/core/src/InternalLog.d.ts +5 -0
- package/lib/typescript/core/src/TimeProvider.d.ts +20 -0
- package/lib/typescript/core/src/Timer.d.ts +3 -2
- package/lib/typescript/core/src/index.d.ts +4 -3
- package/lib/typescript/core/src/rum/instrumentation/DdEventsInterceptor.d.ts +1 -0
- package/lib/typescript/core/src/rum/instrumentation/DdRumErrorTracking.d.ts +2 -2
- package/lib/typescript/core/src/rum/instrumentation/DdRumUserInteractionTracking.d.ts +3 -3
- package/lib/typescript/core/src/rum/instrumentation/ShallowObjectEqualityChecker.d.ts +4 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/DdRumResourceTracking.d.ts +15 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/distributedTracing.d.ts +18 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/firstPartyHosts.d.ts +6 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/interfaces/RequestProxy.d.ts +8 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/domain/interfaces/RumResource.d.ts +19 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/ResourceReporter.d.ts +8 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/internalDevResourceBlocklist.d.ts +6 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/DatadogRumResource/resourceTiming.d.ts +17 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/URLHostParser.d.ts +6 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/XHRProxy.d.ts +25 -0
- package/lib/typescript/core/src/rum/instrumentation/resourceTracking/implementation/responseSize.d.ts +3 -0
- package/lib/typescript/core/src/version.d.ts +1 -1
- package/lib/typescript/react-navigation/src/rum/instrumentation/DdRumReactNavigationTracking.d.ts +9 -3
- package/lib/typescript/react-navigation/src/rum/instrumentation/react-navigation.d.ts +116 -0
- package/package.json +11 -6
- package/src/__tests__/rum/instrumentation/DdRumReactNavigationTracking.test.tsx +481 -385
- package/src/__tests__/rum/instrumentation/__utils__/AppStateMock.ts +75 -0
- package/src/__tests__/rum/instrumentation/__utils__/AppStateMockLegacy.ts +61 -0
- package/src/__tests__/rum/instrumentation/__utils__/Navigators/NavigatorsV5.tsx +105 -0
- package/src/__tests__/rum/instrumentation/__utils__/Navigators/NavigatorsV6.tsx +105 -0
- package/src/index.tsx +4 -1
- package/src/rum/instrumentation/DdRumReactNavigationTracking.tsx +145 -64
- package/src/rum/instrumentation/react-navigation.ts +158 -0
- package/lib/typescript/core/src/rum/instrumentation/DdRumResourceTracking.d.ts +0 -30
- package/lib/typescript/core/src/rum/instrumentation/DdRumXhr.d.ts +0 -13
- package/lib/typescript/core/src/rum/instrumentation/TraceIdentifier.d.ts +0 -1
|
@@ -1,411 +1,507 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
1
2
|
/*
|
|
2
3
|
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
|
|
3
4
|
* This product includes software developed at Datadog (https://www.datadoghq.com/).
|
|
4
5
|
* Copyright 2016-Present Datadog, Inc.
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import { NavigationContainer, NavigationContainerRef, Route } from '@react-navigation/native';
|
|
10
|
-
import { DdRum } from '@datadog/mobile-react-native';
|
|
11
|
-
import { DdRumReactNavigationTracking, ViewNamePredicate} from '../../../rum/instrumentation/DdRumReactNavigationTracking';
|
|
8
|
+
import { DdRum, InternalLog } from '@datadog/mobile-react-native';
|
|
9
|
+
import type { Route } from '@react-navigation/native-v5';
|
|
12
10
|
import { render, fireEvent } from '@testing-library/react-native';
|
|
13
|
-
import
|
|
11
|
+
import mockBackHandler from 'react-native/Libraries/Utilities/__mocks__/BackHandler.js';
|
|
12
|
+
import { AppState, BackHandler } from 'react-native';
|
|
13
|
+
import React, { createRef } from 'react';
|
|
14
|
+
|
|
15
|
+
import type { ViewNamePredicate } from '../../../rum/instrumentation/DdRumReactNavigationTracking';
|
|
16
|
+
import { DdRumReactNavigationTracking } from '../../../rum/instrumentation/DdRumReactNavigationTracking';
|
|
17
|
+
|
|
18
|
+
import { AppStateMockLegacy } from './__utils__/AppStateMockLegacy';
|
|
19
|
+
import { AppStateMock } from './__utils__/AppStateMock';
|
|
20
|
+
import {
|
|
21
|
+
FakeNavigator1 as FakeNavigator1v5,
|
|
22
|
+
FakeNavigator2 as FakeNavigator2v5,
|
|
23
|
+
FakeNestedNavigator as FakeNestedNavigatorv5
|
|
24
|
+
} from './__utils__/Navigators/NavigatorsV5';
|
|
25
|
+
import {
|
|
26
|
+
FakeNavigator1 as FakeNavigator1v6,
|
|
27
|
+
FakeNavigator2 as FakeNavigator2v6,
|
|
28
|
+
FakeNestedNavigator as FakeNestedNavigatorv6
|
|
29
|
+
} from './__utils__/Navigators/NavigatorsV6';
|
|
30
|
+
|
|
31
|
+
// TODO: inject this as a global
|
|
32
|
+
function mocked<T extends (...args: any[]) => any>(item: T) {
|
|
33
|
+
return (item as unknown) as jest.MockedFunction<typeof item>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
jest.mock(
|
|
37
|
+
'react-native/Libraries/Utilities/BackHandler',
|
|
38
|
+
() => mockBackHandler
|
|
39
|
+
);
|
|
14
40
|
|
|
15
41
|
jest.mock('@datadog/mobile-react-native', () => {
|
|
16
42
|
return {
|
|
17
43
|
DdRum: {
|
|
18
44
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
19
|
-
startView: jest.fn().mockImplementation(() => {
|
|
20
|
-
stopView: jest.fn().mockImplementation(() => {
|
|
45
|
+
startView: jest.fn().mockImplementation(() => {}),
|
|
46
|
+
stopView: jest.fn().mockImplementation(() => {})
|
|
47
|
+
},
|
|
48
|
+
SdkVerbosity: {
|
|
49
|
+
DEBUG: 'debug',
|
|
50
|
+
INFO: 'info',
|
|
51
|
+
WARN: 'warn',
|
|
52
|
+
ERROR: 'error'
|
|
21
53
|
},
|
|
54
|
+
InternalLog: {
|
|
55
|
+
log: jest.fn()
|
|
56
|
+
}
|
|
22
57
|
};
|
|
23
58
|
});
|
|
24
59
|
|
|
25
|
-
let capturedAppStateChangeCallback = null;
|
|
26
|
-
|
|
27
|
-
jest.mock('react-native/Libraries/AppState/AppState', () => ({
|
|
28
|
-
addEventListener: jest.fn((event, callback) => {
|
|
29
|
-
if (event === 'change') {
|
|
30
|
-
capturedAppStateChangeCallback = callback;
|
|
31
|
-
}
|
|
32
|
-
}),
|
|
33
|
-
removeEventListener: jest.fn().mockImplementation(() => { })
|
|
34
|
-
}));
|
|
35
|
-
|
|
36
|
-
const { Screen, Navigator } = createStackNavigator();
|
|
37
|
-
const navigationRef1: React.RefObject<NavigationContainerRef> = React.createRef();
|
|
38
|
-
const navigationRef2: React.RefObject<NavigationContainerRef> = React.createRef();
|
|
39
|
-
const navigationRef3: React.RefObject<NavigationContainerRef> = React.createRef();
|
|
40
|
-
|
|
41
60
|
// Silence the warning https://github.com/facebook/react-native/issues/11094#issuecomment-263240420
|
|
42
|
-
jest.mock('react-native/Libraries/Animated/
|
|
61
|
+
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
|
|
43
62
|
jest.useFakeTimers();
|
|
44
63
|
|
|
45
|
-
let baseConsoleErrorCalled = false;
|
|
46
|
-
let baseConsoleError = (...params: unknown) => {
|
|
47
|
-
baseConsoleErrorCalled = true
|
|
48
|
-
}
|
|
49
|
-
let originalConsoleError = undefined
|
|
50
|
-
|
|
51
64
|
beforeEach(() => {
|
|
52
|
-
|
|
65
|
+
mocked(InternalLog.log).mockClear();
|
|
53
66
|
jest.setTimeout(20000);
|
|
54
|
-
DdRum.startView.mockClear();
|
|
55
|
-
DdRum.stopView.mockClear();
|
|
56
|
-
AppState.addEventListener.mockClear();
|
|
57
|
-
|
|
58
|
-
baseConsoleErrorCalled = false;
|
|
59
|
-
originalConsoleError = console.error;
|
|
60
|
-
console.error = baseConsoleError;
|
|
67
|
+
mocked(DdRum.startView).mockClear();
|
|
68
|
+
mocked(DdRum.stopView).mockClear();
|
|
69
|
+
mocked(AppState.addEventListener).mockClear();
|
|
70
|
+
mocked(BackHandler.exitApp).mockClear();
|
|
61
71
|
|
|
72
|
+
// @ts-ignore
|
|
62
73
|
DdRumReactNavigationTracking.registeredContainer = null;
|
|
74
|
+
// @ts-ignore
|
|
63
75
|
DdRumReactNavigationTracking.navigationStateChangeListener = null;
|
|
64
|
-
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
afterEach(() => {
|
|
68
|
-
console.error = originalConsoleError
|
|
69
|
-
})
|
|
76
|
+
});
|
|
70
77
|
|
|
71
78
|
// Unit tests
|
|
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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
//
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
79
|
+
describe.each([
|
|
80
|
+
[
|
|
81
|
+
'5',
|
|
82
|
+
{
|
|
83
|
+
FakeNavigator1: FakeNavigator1v5,
|
|
84
|
+
FakeNavigator2: FakeNavigator2v5,
|
|
85
|
+
FakeNestedNavigator: FakeNestedNavigatorv5
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
[
|
|
89
|
+
'6',
|
|
90
|
+
{
|
|
91
|
+
FakeNavigator1: FakeNavigator1v6,
|
|
92
|
+
FakeNavigator2: FakeNavigator2v6,
|
|
93
|
+
FakeNestedNavigator: FakeNestedNavigatorv6
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
])(
|
|
97
|
+
'DdRumReactNavigationTracking on react-navigation v%s',
|
|
98
|
+
(version, { FakeNavigator1, FakeNavigator2, FakeNestedNavigator }) => {
|
|
99
|
+
describe('startTrackingViews', () => {
|
|
100
|
+
it('sends a related RUM ViewEvent when switching screens { navigationContainer listener attached }', async () => {
|
|
101
|
+
// GIVEN
|
|
102
|
+
const navigationRef = createRef<any>();
|
|
103
|
+
const { getByText } = render(
|
|
104
|
+
<FakeNavigator1 navigationRef={navigationRef} />
|
|
105
|
+
);
|
|
106
|
+
const goToAboutButton = getByText('Go to About');
|
|
107
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
108
|
+
navigationRef.current
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
// WHEN
|
|
112
|
+
expect(goToAboutButton).toBeTruthy();
|
|
113
|
+
fireEvent(goToAboutButton, 'press');
|
|
114
|
+
|
|
115
|
+
// THEN
|
|
116
|
+
expect(DdRum.startView).toHaveBeenCalledTimes(2);
|
|
117
|
+
expect(DdRum.startView).toHaveBeenCalledWith(
|
|
118
|
+
expect.any(String),
|
|
119
|
+
'Home'
|
|
120
|
+
);
|
|
121
|
+
expect(DdRum.startView).toHaveBeenCalledWith(
|
|
122
|
+
expect.any(String),
|
|
123
|
+
'About'
|
|
124
|
+
);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('sends a related RUM ViewEvent when switching screens { viewPredicate provided }', async () => {
|
|
128
|
+
// GIVEN
|
|
129
|
+
const navigationRef = createRef<any>();
|
|
130
|
+
const { getByText } = render(
|
|
131
|
+
<FakeNavigator1 navigationRef={navigationRef} />
|
|
132
|
+
);
|
|
133
|
+
const goToAboutButton = getByText('Go to About');
|
|
134
|
+
const customViewName = 'custom_view_name';
|
|
135
|
+
const predicate: ViewNamePredicate = function (
|
|
136
|
+
_route: Route<string, any | undefined>,
|
|
137
|
+
_trackedName: string
|
|
138
|
+
) {
|
|
139
|
+
return customViewName;
|
|
140
|
+
};
|
|
141
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
142
|
+
navigationRef.current,
|
|
143
|
+
predicate
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
// WHEN
|
|
147
|
+
expect(goToAboutButton).toBeTruthy();
|
|
148
|
+
fireEvent(goToAboutButton, 'press');
|
|
149
|
+
|
|
150
|
+
// THEN
|
|
151
|
+
expect(DdRum.startView).toHaveBeenCalledWith(
|
|
152
|
+
expect.any(String),
|
|
153
|
+
'custom_view_name'
|
|
154
|
+
);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('only registers once when startTrackingViews{ multiple times }', async () => {
|
|
158
|
+
// GIVEN
|
|
159
|
+
const navigationRef = createRef<any>();
|
|
160
|
+
const { getByText } = render(
|
|
161
|
+
<FakeNavigator1 navigationRef={navigationRef} />
|
|
162
|
+
);
|
|
163
|
+
const goToAboutButton = getByText('Go to About');
|
|
164
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
165
|
+
navigationRef.current
|
|
166
|
+
);
|
|
167
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
168
|
+
navigationRef.current
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
// WHEN
|
|
172
|
+
expect(goToAboutButton).toBeTruthy();
|
|
173
|
+
fireEvent(goToAboutButton, 'press');
|
|
174
|
+
|
|
175
|
+
// THEN
|
|
176
|
+
expect(DdRum.startView).toHaveBeenCalledTimes(2);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('does nothing when startTrackingViews { undefined any ', async () => {
|
|
180
|
+
// WHEN
|
|
181
|
+
DdRumReactNavigationTracking.startTrackingViews(null);
|
|
182
|
+
|
|
183
|
+
// THEN
|
|
184
|
+
expect(DdRum.startView).toHaveBeenCalledTimes(0);
|
|
185
|
+
expect(InternalLog.log).toHaveBeenCalledTimes(1);
|
|
186
|
+
expect(InternalLog.log).toHaveBeenCalledWith(
|
|
187
|
+
DdRumReactNavigationTracking.NULL_NAVIGATION_REF_ERROR_MESSAGE,
|
|
188
|
+
'error'
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('sends a RUM ViewEvent for each when startTrackingViews { multiple navigation containers when first not detached }', async () => {
|
|
193
|
+
// GIVEN
|
|
194
|
+
const navigationRef1 = createRef<any>();
|
|
195
|
+
const testUtils1: { getByText } = render(
|
|
196
|
+
<FakeNavigator1 navigationRef={navigationRef1} />
|
|
197
|
+
);
|
|
198
|
+
const goToAboutButton1 = testUtils1.getByText('Go to About');
|
|
199
|
+
const navigationRef2 = createRef<any>();
|
|
200
|
+
const testUtils2: { getByText } = render(
|
|
201
|
+
<FakeNavigator2 navigationRef={navigationRef2} />
|
|
202
|
+
);
|
|
203
|
+
const goToAboutButton2 = testUtils2.getByText('Go to About');
|
|
204
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
205
|
+
navigationRef1.current
|
|
206
|
+
);
|
|
207
|
+
// this call will be ignored, because only one NavigationContainer tracking is supported at the time
|
|
208
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
209
|
+
navigationRef2.current
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
// WHEN
|
|
213
|
+
expect(goToAboutButton1).toBeTruthy();
|
|
214
|
+
expect(goToAboutButton2).toBeTruthy();
|
|
215
|
+
fireEvent(goToAboutButton1, 'press');
|
|
216
|
+
fireEvent(goToAboutButton2, 'press');
|
|
217
|
+
|
|
218
|
+
// THEN
|
|
219
|
+
expect(DdRum.startView).toHaveBeenCalledTimes(2);
|
|
220
|
+
expect(InternalLog.log).toHaveBeenCalledWith(
|
|
221
|
+
DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE,
|
|
222
|
+
'error'
|
|
223
|
+
);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('sends a RUM ViewEvent for each when switching screens { nested navigation containers }', async () => {
|
|
227
|
+
// GIVEN
|
|
228
|
+
const navigationRef = createRef<any>();
|
|
229
|
+
const testUtils: { getByText } = render(
|
|
230
|
+
<FakeNestedNavigator navigationRef={navigationRef} />
|
|
231
|
+
);
|
|
232
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
233
|
+
navigationRef.current
|
|
234
|
+
);
|
|
235
|
+
const goToAboutButton = testUtils.getByText('Go to About');
|
|
236
|
+
|
|
237
|
+
// WHEN
|
|
238
|
+
expect(goToAboutButton).toBeTruthy();
|
|
239
|
+
fireEvent(goToAboutButton, 'press');
|
|
240
|
+
|
|
241
|
+
// THEN
|
|
242
|
+
expect(DdRum.startView).toHaveBeenCalledTimes(2);
|
|
243
|
+
expect(DdRum.startView).toHaveBeenCalledWith(
|
|
244
|
+
expect.any(String),
|
|
245
|
+
'Home'
|
|
246
|
+
);
|
|
247
|
+
expect(DdRum.startView).toHaveBeenCalledWith(
|
|
248
|
+
expect.any(String),
|
|
249
|
+
'About'
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
// WHEN
|
|
253
|
+
const goToNestedHome = testUtils.getByText('Go to Nested Home');
|
|
254
|
+
fireEvent(goToNestedHome, 'press');
|
|
255
|
+
|
|
256
|
+
// THEN
|
|
257
|
+
expect(DdRum.startView).toHaveBeenCalledWith(
|
|
258
|
+
expect.any(String),
|
|
259
|
+
'NestedHome'
|
|
260
|
+
);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
describe('stopTrackingViews', () => {
|
|
265
|
+
it('does nothing when switching screens { navigationContainer listener detached }', async () => {
|
|
266
|
+
// GIVEN
|
|
267
|
+
const navigationRef = createRef<any>();
|
|
268
|
+
const { getByText } = render(
|
|
269
|
+
<FakeNavigator1 navigationRef={navigationRef} />
|
|
270
|
+
);
|
|
271
|
+
const goToAboutButton = getByText('Go to About');
|
|
272
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
273
|
+
navigationRef.current
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
// WHEN
|
|
277
|
+
DdRumReactNavigationTracking.stopTrackingViews(
|
|
278
|
+
navigationRef.current
|
|
279
|
+
);
|
|
280
|
+
expect(goToAboutButton).toBeTruthy();
|
|
281
|
+
fireEvent(goToAboutButton, 'press');
|
|
282
|
+
|
|
283
|
+
// THEN
|
|
284
|
+
expect(DdRum.startView).toHaveBeenCalledTimes(1);
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('sends a RUM ViewEvent for each when startTrackingViews { multiple navigation containers when first is detached }', async () => {
|
|
288
|
+
// GIVEN
|
|
289
|
+
const navigationRef1 = createRef<any>();
|
|
290
|
+
const testUtils1: { getByText } = render(
|
|
291
|
+
<FakeNavigator1 navigationRef={navigationRef1} />
|
|
292
|
+
);
|
|
293
|
+
const goToAboutButton1 = testUtils1.getByText('Go to About');
|
|
294
|
+
const navigationRef2 = createRef<any>();
|
|
295
|
+
const testUtils2: { getByText } = render(
|
|
296
|
+
<FakeNavigator2 navigationRef={navigationRef2} />
|
|
297
|
+
);
|
|
298
|
+
const goToAboutButton2 = testUtils2.getByText('Go to About');
|
|
299
|
+
|
|
300
|
+
// WHEN
|
|
301
|
+
expect(goToAboutButton1).toBeTruthy();
|
|
302
|
+
expect(goToAboutButton2).toBeTruthy();
|
|
303
|
+
|
|
304
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
305
|
+
navigationRef1.current
|
|
306
|
+
);
|
|
307
|
+
fireEvent(goToAboutButton1, 'press');
|
|
308
|
+
DdRumReactNavigationTracking.stopTrackingViews(
|
|
309
|
+
navigationRef1.current
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
313
|
+
navigationRef2.current
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
const navigationRef2StartRoute = navigationRef2.current.getCurrentRoute();
|
|
317
|
+
|
|
318
|
+
fireEvent(goToAboutButton2, 'press');
|
|
319
|
+
|
|
320
|
+
// THEN
|
|
321
|
+
expect(DdRum.startView).toHaveBeenCalledTimes(4);
|
|
322
|
+
expect(DdRum.startView).toHaveBeenCalledWith(
|
|
323
|
+
navigationRef2StartRoute.key,
|
|
324
|
+
'Home'
|
|
325
|
+
);
|
|
326
|
+
expect(DdRum.startView).toHaveBeenCalledWith(
|
|
327
|
+
navigationRef2.current?.getCurrentRoute()?.key,
|
|
328
|
+
'About'
|
|
329
|
+
);
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
describe.each([
|
|
334
|
+
['react-native 0.63-0.64', AppStateMockLegacy],
|
|
335
|
+
['react-native 0.65+', AppStateMock]
|
|
336
|
+
])(
|
|
337
|
+
'AppState listener on %s',
|
|
338
|
+
(reactNativeVersion, AppStateMockVersion) => {
|
|
339
|
+
let appStateMock;
|
|
340
|
+
beforeEach(() => {
|
|
341
|
+
appStateMock = new AppStateMockVersion();
|
|
342
|
+
mocked(AppState.addEventListener).mockImplementation(
|
|
343
|
+
// @ts-ignore
|
|
344
|
+
appStateMock.addEventListener
|
|
345
|
+
);
|
|
346
|
+
// @ts-ignore
|
|
347
|
+
if (appStateMock.removeEventListener) {
|
|
348
|
+
AppState.removeEventListener = jest.fn(
|
|
349
|
+
appStateMock.removeEventListener
|
|
350
|
+
);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
it('registers and unregisters AppState', async () => {
|
|
354
|
+
// GIVEN
|
|
355
|
+
const navigationRef1 = createRef<any>();
|
|
356
|
+
render(<FakeNavigator1 navigationRef={navigationRef1} />);
|
|
357
|
+
const navigationRef2 = createRef<any>();
|
|
358
|
+
render(<FakeNavigator2 navigationRef={navigationRef2} />);
|
|
359
|
+
|
|
360
|
+
// WHEN
|
|
361
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
362
|
+
navigationRef1.current
|
|
363
|
+
);
|
|
364
|
+
DdRumReactNavigationTracking.stopTrackingViews(
|
|
365
|
+
navigationRef1.current
|
|
366
|
+
);
|
|
367
|
+
expect(appStateMock.listeners.change).toHaveLength(0);
|
|
368
|
+
|
|
369
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
370
|
+
navigationRef2.current
|
|
371
|
+
);
|
|
372
|
+
|
|
373
|
+
// THEN
|
|
374
|
+
expect(AppState.addEventListener).toHaveBeenCalledTimes(2);
|
|
375
|
+
expect(appStateMock.listeners.change).toHaveLength(1);
|
|
376
|
+
|
|
377
|
+
// WHEN we go in background mode
|
|
378
|
+
appStateMock.changeValue('background');
|
|
379
|
+
|
|
380
|
+
// THEN the listener is only called once
|
|
381
|
+
expect(DdRum.stopView).toHaveBeenCalledTimes(1);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it('does not log AppState changes when tracking is stopped', async () => {
|
|
385
|
+
// GIVEN
|
|
386
|
+
const navigationRef = createRef<any>();
|
|
387
|
+
render(<FakeNavigator1 navigationRef={navigationRef} />);
|
|
388
|
+
|
|
389
|
+
// WHEN
|
|
390
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
391
|
+
navigationRef.current
|
|
392
|
+
);
|
|
393
|
+
DdRumReactNavigationTracking.stopTrackingViews(
|
|
394
|
+
navigationRef.current
|
|
395
|
+
);
|
|
396
|
+
appStateMock.changeValue('background');
|
|
397
|
+
|
|
398
|
+
// THEN
|
|
399
|
+
expect(DdRum.stopView).not.toHaveBeenCalled();
|
|
400
|
+
expect(InternalLog.log).not.toHaveBeenCalledWith(
|
|
401
|
+
'We could not determine the route when changing the application state to: background. No RUM View event will be sent in this case.',
|
|
402
|
+
'error'
|
|
403
|
+
);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it('stops active view when app goes into background', async () => {
|
|
407
|
+
// GIVEN
|
|
408
|
+
const navigationRef = createRef<any>();
|
|
409
|
+
render(<FakeNavigator1 navigationRef={navigationRef} />);
|
|
410
|
+
|
|
411
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
412
|
+
navigationRef.current
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
// WHEN
|
|
416
|
+
appStateMock.changeValue('background');
|
|
417
|
+
|
|
418
|
+
// THEN
|
|
419
|
+
expect(DdRum.stopView).toHaveBeenCalledTimes(1);
|
|
420
|
+
expect(DdRum.stopView).toHaveBeenCalledWith(
|
|
421
|
+
navigationRef.current?.getCurrentRoute()?.key
|
|
422
|
+
);
|
|
423
|
+
expect(
|
|
424
|
+
typeof navigationRef.current?.getCurrentRoute()?.key
|
|
425
|
+
).toBe('string');
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it('starts last view when app goes into foreground', async () => {
|
|
429
|
+
// GIVEN
|
|
430
|
+
const navigationRef = createRef<any>();
|
|
431
|
+
render(<FakeNavigator1 navigationRef={navigationRef} />);
|
|
432
|
+
|
|
433
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
434
|
+
navigationRef.current
|
|
435
|
+
);
|
|
436
|
+
|
|
437
|
+
// WHEN
|
|
438
|
+
appStateMock.changeValue('background');
|
|
439
|
+
appStateMock.changeValue('active');
|
|
440
|
+
|
|
441
|
+
// THEN
|
|
442
|
+
expect(DdRum.stopView).toHaveBeenCalledTimes(1);
|
|
443
|
+
expect(DdRum.startView).toHaveBeenCalledTimes(2);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it('does not stop view when no navigator attached', async () => {
|
|
447
|
+
// GIVEN
|
|
448
|
+
const navigationRef = createRef<any>();
|
|
449
|
+
render(<FakeNavigator1 navigationRef={navigationRef} />);
|
|
450
|
+
|
|
451
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
452
|
+
navigationRef.current
|
|
453
|
+
);
|
|
454
|
+
DdRumReactNavigationTracking.stopTrackingViews(
|
|
455
|
+
navigationRef.current
|
|
456
|
+
);
|
|
457
|
+
|
|
458
|
+
// WHEN
|
|
459
|
+
appStateMock.changeValue('background');
|
|
460
|
+
|
|
461
|
+
// THEN
|
|
462
|
+
expect(DdRum.stopView).not.toHaveBeenCalled();
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
);
|
|
466
|
+
|
|
467
|
+
describe('Android back handler', () => {
|
|
468
|
+
it('does not send an error when the app closes with Android back button', async () => {
|
|
469
|
+
// GIVEN
|
|
470
|
+
const navigationRef1 = createRef<any>();
|
|
471
|
+
const { unmount } = render(
|
|
472
|
+
<FakeNavigator1 navigationRef={navigationRef1} />
|
|
473
|
+
);
|
|
474
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
475
|
+
navigationRef1.current
|
|
476
|
+
);
|
|
477
|
+
|
|
478
|
+
// WHEN back is pressed
|
|
479
|
+
mockBackHandler.mockPressBack();
|
|
480
|
+
// THEN app is closed
|
|
481
|
+
expect(BackHandler.exitApp).toHaveBeenCalled();
|
|
482
|
+
|
|
483
|
+
// WHEN app is restarted and we navigate
|
|
484
|
+
unmount();
|
|
485
|
+
const navigationRef2 = createRef<any>();
|
|
486
|
+
const { getByText } = render(
|
|
487
|
+
<FakeNavigator2 navigationRef={navigationRef2} />
|
|
488
|
+
);
|
|
489
|
+
DdRumReactNavigationTracking.startTrackingViews(
|
|
490
|
+
navigationRef2.current
|
|
491
|
+
);
|
|
492
|
+
const goToAboutButton = getByText('Go to About');
|
|
493
|
+
fireEvent(goToAboutButton, 'press');
|
|
494
|
+
|
|
495
|
+
// THEN new navigation is attached, no error and message is sent
|
|
496
|
+
expect(DdRum.startView).toHaveBeenLastCalledWith(
|
|
497
|
+
expect.any(String),
|
|
498
|
+
'About'
|
|
499
|
+
);
|
|
500
|
+
expect(InternalLog.log).not.toHaveBeenCalledWith(
|
|
501
|
+
DdRumReactNavigationTracking.NAVIGATION_REF_IN_USE_ERROR_MESSAGE,
|
|
502
|
+
'error'
|
|
503
|
+
);
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
);
|