@datadog/mobile-react-native 1.0.0-beta4 → 1.0.0-rc4
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/DatadogSDKReactNative.podspec +1 -1
- package/README.md +73 -1
- package/android/build.gradle +2 -3
- package/android/src/main/java/com/datadog/reactnative/DdRum.kt +25 -24
- package/android/src/main/java/com/datadog/reactnative/DdTrace.kt +6 -6
- package/ios/Sources/DdRum.m +10 -9
- package/ios/Sources/DdRum.swift +24 -24
- package/ios/Sources/DdTrace.m +2 -2
- package/ios/Sources/DdTrace.swift +6 -6
- package/ios/Sources/QueueHolder.swift +1 -1
- package/lib/commonjs/DdSdkReactNative.js +57 -0
- package/lib/commonjs/DdSdkReactNative.js.map +1 -1
- package/lib/commonjs/DdSdkReactNativeConfiguration.js +8 -0
- package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/commonjs/NativeSdkVerbosity.js +26 -0
- package/lib/commonjs/NativeSdkVerbosity.js.map +1 -0
- package/lib/commonjs/ProxyConfiguration.js +53 -0
- package/lib/commonjs/ProxyConfiguration.js.map +1 -0
- package/lib/commonjs/Timer.js +99 -0
- package/lib/commonjs/Timer.js.map +1 -0
- package/lib/commonjs/TrackingConsent.js +6 -0
- package/lib/commonjs/TrackingConsent.js.map +1 -1
- package/lib/commonjs/foundation.js +88 -8
- package/lib/commonjs/foundation.js.map +1 -1
- package/lib/commonjs/index.js +14 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js +51 -11
- package/lib/commonjs/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js +38 -6
- package/lib/commonjs/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js +103 -18
- package/lib/commonjs/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/version.js +10 -0
- package/lib/commonjs/version.js.map +1 -0
- package/lib/module/DdSdkReactNative.js +56 -1
- package/lib/module/DdSdkReactNative.js.map +1 -1
- package/lib/module/DdSdkReactNativeConfiguration.js +9 -1
- package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
- package/lib/module/NativeSdkVerbosity.js +18 -0
- package/lib/module/NativeSdkVerbosity.js.map +1 -0
- package/lib/module/ProxyConfiguration.js +46 -0
- package/lib/module/ProxyConfiguration.js.map +1 -0
- package/lib/module/Timer.js +90 -0
- package/lib/module/Timer.js.map +1 -0
- package/lib/module/TrackingConsent.js +6 -0
- package/lib/module/TrackingConsent.js.map +1 -1
- package/lib/module/foundation.js +89 -3
- package/lib/module/foundation.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js +51 -11
- package/lib/module/rum/instrumentation/DdEventsInterceptor.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js +37 -6
- package/lib/module/rum/instrumentation/DdRumErrorTracking.js.map +1 -1
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js +96 -18
- package/lib/module/rum/instrumentation/DdRumResourceTracking.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/version.js +3 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/DdSdkReactNative.d.ts +11 -0
- package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +6 -0
- package/lib/typescript/NativeSdkVerbosity.d.ts +9 -0
- package/lib/typescript/ProxyConfiguration.d.ts +56 -0
- package/lib/typescript/Timer.d.ts +20 -0
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/rum/instrumentation/DdEventsInterceptor.d.ts +2 -0
- package/lib/typescript/rum/instrumentation/DdRumErrorTracking.d.ts +2 -0
- package/lib/typescript/rum/instrumentation/DdRumResourceTracking.d.ts +4 -0
- package/lib/typescript/rum/instrumentation/DdRumXhr.d.ts +2 -2
- package/lib/typescript/types.d.ts +25 -24
- package/lib/typescript/version.d.ts +1 -0
- package/package.json +12 -13
- package/src/DdSdkReactNative.tsx +47 -0
- package/src/DdSdkReactNativeConfiguration.tsx +7 -1
- package/src/NativeSdkVerbosity.tsx +15 -0
- package/src/ProxyConfiguration.tsx +37 -0
- package/src/Timer.ts +96 -0
- package/src/TrackingConsent.tsx +6 -0
- package/src/__tests__/DdRumWrapper.test.tsx +91 -0
- package/src/__tests__/DdSdkReactNative.test.tsx +541 -0
- package/src/__tests__/Timer.test.ts +145 -0
- package/src/__tests__/rum/instrumentation/DdEventsInterceptor.test.tsx +222 -0
- package/src/__tests__/rum/instrumentation/DdRumErrorTracking.test.tsx +314 -0
- package/src/__tests__/rum/instrumentation/DdRumResourceTracking.test.tsx +677 -0
- package/src/__tests__/rum/instrumentation/DdRumUserInteractionTracking.test.tsx +188 -0
- package/src/__tests__/rum/instrumentation/TraceIdentifier.test.tsx +33 -0
- package/src/foundation.tsx +83 -3
- package/src/index.tsx +3 -2
- package/src/rum/instrumentation/DdEventsInterceptor.tsx +40 -10
- package/src/rum/instrumentation/DdRumErrorTracking.tsx +56 -25
- package/src/rum/instrumentation/DdRumResourceTracking.tsx +92 -22
- package/src/rum/instrumentation/DdRumXhr.tsx +6 -5
- package/src/types.tsx +25 -24
- package/src/version.ts +2 -0
- package/android/.project +0 -17
- package/android/.settings/org.eclipse.buildship.core.prefs +0 -13
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +0 -6
- package/android/gradlew +0 -185
- package/android/gradlew.bat +0 -104
- package/ios/DdSdkReactNative.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- package/ios/Tests/ModulesTest.swift +0 -43
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datadog/mobile-react-native",
|
|
3
|
-
"version": "1.0.0-
|
|
3
|
+
"version": "1.0.0-rc4",
|
|
4
4
|
"description": "A client-side React Native module to interact with Datadog",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datadog",
|
|
@@ -19,15 +19,14 @@
|
|
|
19
19
|
"files": [
|
|
20
20
|
"src",
|
|
21
21
|
"lib",
|
|
22
|
-
"android",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"!**/__mocks__"
|
|
22
|
+
"android/build.gradle",
|
|
23
|
+
"android/gradle.properties",
|
|
24
|
+
"android/src",
|
|
25
|
+
"ios/Sources",
|
|
26
|
+
"ios/DdSdkReactNative.xcodeproj/project.xcworkspace/xcsharedata",
|
|
27
|
+
"ios/DdSdkReactNative.xcodeproj/project.xcworkspace/*.xcworkspacedata",
|
|
28
|
+
"ios/DdSdkReactNative.xcodeproj/*.pbxproj",
|
|
29
|
+
"DatadogSDKReactNative.podspec"
|
|
31
30
|
],
|
|
32
31
|
"types": "lib/typescript/index.d.ts",
|
|
33
32
|
"react-native": "src/index",
|
|
@@ -42,8 +41,8 @@
|
|
|
42
41
|
"prepare": "bob build"
|
|
43
42
|
},
|
|
44
43
|
"peerDependencies": {
|
|
45
|
-
"react": "
|
|
46
|
-
"react-native": "
|
|
44
|
+
"react": ">=16.13.1",
|
|
45
|
+
"react-native": ">=0.63.4 <1.0"
|
|
47
46
|
},
|
|
48
47
|
"jest": {
|
|
49
48
|
"preset": "react-native",
|
|
@@ -69,5 +68,5 @@
|
|
|
69
68
|
]
|
|
70
69
|
]
|
|
71
70
|
},
|
|
72
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "c1bd4e6ded0b84298ca011eba679027ae7fe7841"
|
|
73
72
|
}
|
package/src/DdSdkReactNative.tsx
CHANGED
|
@@ -11,6 +11,9 @@ import { DdRumUserInteractionTracking } from './rum/instrumentation/DdRumUserInt
|
|
|
11
11
|
import { DdRumErrorTracking } from './rum/instrumentation/DdRumErrorTracking'
|
|
12
12
|
import { DdRumResourceTracking } from './rum/instrumentation/DdRumResourceTracking'
|
|
13
13
|
import type { TrackingConsent } from "./TrackingConsent"
|
|
14
|
+
import { ProxyType } from "./ProxyConfiguration"
|
|
15
|
+
|
|
16
|
+
import {version as sdkVersion } from './version';
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* This class initializes the Datadog SDK, and sets up communication with the server.
|
|
@@ -18,6 +21,21 @@ import type { TrackingConsent } from "./TrackingConsent"
|
|
|
18
21
|
export class DdSdkReactNative {
|
|
19
22
|
|
|
20
23
|
private static readonly DD_SOURCE_KEY = "_dd.source";
|
|
24
|
+
private static readonly DD_SDK_VERSION = "_dd.sdk_version";
|
|
25
|
+
private static readonly DD_SERVICE_NAME = "_dd.service_name";
|
|
26
|
+
private static readonly DD_SDK_VERBOSITY_KEY = "_dd.sdk_verbosity";
|
|
27
|
+
private static readonly DD_NATIVE_VIEW_TRACKING_KEY = "_dd.native_view_tracking";
|
|
28
|
+
|
|
29
|
+
// Proxy
|
|
30
|
+
private static readonly DD_PROXY_TYPE_KEY = "_dd.proxy.type";
|
|
31
|
+
private static readonly DD_PROXY_ADDRESS_KEY = "_dd.proxy.address";
|
|
32
|
+
private static readonly DD_PROXY_PORT_KEY = "_dd.proxy.port";
|
|
33
|
+
private static readonly DD_PROXY_USERNAME_KEY = "_dd.proxy.username";
|
|
34
|
+
private static readonly DD_PROXY_PASSWORD_KEY = "_dd.proxy.password";
|
|
35
|
+
|
|
36
|
+
private static readonly DD_NATIVE_LONG_TASK_THRESHOLD_KEY = "_dd.long_task.threshold"
|
|
37
|
+
private static readonly NATIVE_LONG_TASK_THRESHOLD_MS = 200
|
|
38
|
+
|
|
21
39
|
|
|
22
40
|
private static wasInitialized = false
|
|
23
41
|
|
|
@@ -34,6 +52,35 @@ export class DdSdkReactNative {
|
|
|
34
52
|
}
|
|
35
53
|
|
|
36
54
|
configuration.additionalConfig[DdSdkReactNative.DD_SOURCE_KEY] = 'react-native';
|
|
55
|
+
configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERSION] = sdkVersion;
|
|
56
|
+
configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_VIEW_TRACKING_KEY] = configuration.nativeViewTracking;
|
|
57
|
+
if (configuration.verbosity != undefined) {
|
|
58
|
+
configuration.additionalConfig[DdSdkReactNative.DD_SDK_VERBOSITY_KEY] = configuration.verbosity;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (configuration.proxyConfig) {
|
|
62
|
+
const additionalConfig = configuration.additionalConfig;
|
|
63
|
+
const proxyConfig = configuration.proxyConfig;
|
|
64
|
+
|
|
65
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_TYPE_KEY] = proxyConfig.type;
|
|
66
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_ADDRESS_KEY] = proxyConfig.address;
|
|
67
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_PORT_KEY] = proxyConfig.port;
|
|
68
|
+
if (proxyConfig.username && proxyConfig.password) {
|
|
69
|
+
if (proxyConfig.type == ProxyType.SOCKS) {
|
|
70
|
+
console.warn("SOCKS proxy configuration doesn't support Basic authentication.")
|
|
71
|
+
} else {
|
|
72
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_USERNAME_KEY] = proxyConfig.username;
|
|
73
|
+
additionalConfig[DdSdkReactNative.DD_PROXY_PASSWORD_KEY] = proxyConfig.password;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (configuration.serviceName) {
|
|
79
|
+
configuration.additionalConfig[DdSdkReactNative.DD_SERVICE_NAME] = configuration.serviceName;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
configuration.additionalConfig[DdSdkReactNative.DD_NATIVE_LONG_TASK_THRESHOLD_KEY]
|
|
83
|
+
= DdSdkReactNative.NATIVE_LONG_TASK_THRESHOLD_MS
|
|
37
84
|
|
|
38
85
|
DdSdk.initialize(
|
|
39
86
|
new DdSdkConfiguration(
|
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { TrackingConsent } from './TrackingConsent'
|
|
8
|
+
import type { NativeSdkVerbosity } from './NativeSdkVerbosity'
|
|
9
|
+
import type { ProxyConfiguration } from './ProxyConfiguration';
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* The SDK configuration class.
|
|
@@ -15,7 +17,11 @@ export class DdSdkReactNativeConfiguration {
|
|
|
15
17
|
public nativeCrashReportEnabled: boolean = false;
|
|
16
18
|
public sampleRate: number = 100.0;
|
|
17
19
|
public site: string = "US"
|
|
18
|
-
|
|
20
|
+
public verbosity: NativeSdkVerbosity|undefined = undefined
|
|
21
|
+
public nativeViewTracking: boolean = false
|
|
22
|
+
public proxyConfig?: ProxyConfiguration = undefined
|
|
23
|
+
public serviceName?: string = undefined
|
|
24
|
+
|
|
19
25
|
public additionalConfig: {[k: string]: any} = {};
|
|
20
26
|
|
|
21
27
|
constructor(
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* Enum specifying possible consent options for DD SDK.
|
|
9
|
+
*/
|
|
10
|
+
export enum NativeSdkVerbosity {
|
|
11
|
+
DEBUG = "debug",
|
|
12
|
+
INFO = "info",
|
|
13
|
+
WARN = "warn",
|
|
14
|
+
ERROR = "error"
|
|
15
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy server configuration.
|
|
3
|
+
*/
|
|
4
|
+
class ProxyConfiguration {
|
|
5
|
+
constructor(
|
|
6
|
+
/**
|
|
7
|
+
* Proxy type.
|
|
8
|
+
*/
|
|
9
|
+
readonly type: ProxyType,
|
|
10
|
+
/**
|
|
11
|
+
* Proxy address. Can be either in the IP address format, ex. "1.1.1.1", or hostname, ex. "example.com".
|
|
12
|
+
*/
|
|
13
|
+
readonly address: string,
|
|
14
|
+
/**
|
|
15
|
+
* Proxy port.
|
|
16
|
+
*/
|
|
17
|
+
readonly port: number,
|
|
18
|
+
/**
|
|
19
|
+
* Username for Basic authentication scheme.
|
|
20
|
+
*
|
|
21
|
+
* Note: "SOCKS + authentication" scheme is not supported.
|
|
22
|
+
*/
|
|
23
|
+
readonly username?: string,
|
|
24
|
+
/**
|
|
25
|
+
* Password for Basic authentication scheme.
|
|
26
|
+
*/
|
|
27
|
+
readonly password?: string
|
|
28
|
+
) { }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
enum ProxyType {
|
|
32
|
+
HTTP = "http",
|
|
33
|
+
HTTPS = "https",
|
|
34
|
+
SOCKS = "socks"
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { ProxyConfiguration, ProxyType }
|
package/src/Timer.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
type Timestamp = {
|
|
2
|
+
// Result of Date API. Unix timestamp in ms.
|
|
3
|
+
unix: number,
|
|
4
|
+
// Result of performance.now API. Timestamp in ms (with microsecond precision)
|
|
5
|
+
// since JS context start.
|
|
6
|
+
react_native: number | null
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const START_LABEL = "__start"
|
|
10
|
+
const STOP_LABEL = "__stop"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Simple timer which records time ticks. Shouldn't be re-used once stopped.
|
|
14
|
+
* All timestamps/durations returned are in milliseconds.
|
|
15
|
+
*/
|
|
16
|
+
export default class Timer {
|
|
17
|
+
|
|
18
|
+
private times: Record<string, Timestamp> = {};
|
|
19
|
+
|
|
20
|
+
get startTime(): number {
|
|
21
|
+
return this.times[START_LABEL].unix
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get stopTime(): number {
|
|
25
|
+
return this.startTime + this.durationBetween(START_LABEL, STOP_LABEL)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
start(): void {
|
|
29
|
+
this.recordTick(START_LABEL);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
stop(): void {
|
|
33
|
+
this.recordTick(STOP_LABEL)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
recordTick(label: string): void {
|
|
37
|
+
this.times[label] = {
|
|
38
|
+
unix: Date.now(),
|
|
39
|
+
react_native: this.performanceNow()
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
hasTickFor(label: string): boolean {
|
|
44
|
+
return label in this.times;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
durationBetween(startLabel: string, endLabel: string): number {
|
|
48
|
+
this.checkLabelExists(startLabel);
|
|
49
|
+
this.checkLabelExists(endLabel);
|
|
50
|
+
|
|
51
|
+
const startTick = this.times[startLabel];
|
|
52
|
+
const endTick = this.times[endLabel];
|
|
53
|
+
|
|
54
|
+
return this.durationBetweenTicks(startTick, endTick);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
timeAt(label: string): number {
|
|
58
|
+
this.checkLabelExists(label);
|
|
59
|
+
|
|
60
|
+
return this.startTime + this.durationBetween(START_LABEL, label)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
reset(): void {
|
|
64
|
+
this.times = {};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private durationBetweenTicks(start: Timestamp, end: Timestamp): number {
|
|
68
|
+
if (start.react_native != null && end.react_native != null) {
|
|
69
|
+
return end.react_native - start.react_native;
|
|
70
|
+
}
|
|
71
|
+
return end.unix - start.unix;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
private performanceNow(): number | null {
|
|
76
|
+
if (this.canUsePerformanceNow()) {
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
return performance.now();
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private canUsePerformanceNow(): boolean {
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
return global.performance && typeof performance.now === 'function';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private checkLabelExists(label: string) {
|
|
91
|
+
if (!this.hasTickFor(label)) {
|
|
92
|
+
throw new Error(`Label ${label} is not registered`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
}
|
package/src/TrackingConsent.tsx
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
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
|
+
|
|
1
7
|
/**
|
|
2
8
|
* Enum specifying possible consent options for DD SDK.
|
|
3
9
|
*/
|
|
@@ -0,0 +1,91 @@
|
|
|
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 { NativeModules } from 'react-native'
|
|
8
|
+
import { DdRum } from '../foundation'
|
|
9
|
+
|
|
10
|
+
jest.mock('react-native', () => {
|
|
11
|
+
return {
|
|
12
|
+
NativeModules: {
|
|
13
|
+
DdRum: {
|
|
14
|
+
startView: jest.fn().mockImplementation(() => { }),
|
|
15
|
+
stopView: jest.fn().mockImplementation(() => { }),
|
|
16
|
+
startAction: jest.fn().mockImplementation(() => { }),
|
|
17
|
+
stopAction: jest.fn().mockImplementation(() => { }),
|
|
18
|
+
addAction: jest.fn().mockImplementation(() => { }),
|
|
19
|
+
startResource: jest.fn().mockImplementation(() => { }),
|
|
20
|
+
stopResource: jest.fn().mockImplementation(() => { }),
|
|
21
|
+
addError: jest.fn().mockImplementation(() => { }),
|
|
22
|
+
addTiming: jest.fn().mockImplementation(() => { })
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
beforeEach(async () => {
|
|
29
|
+
NativeModules.DdRum.startView.mockClear();
|
|
30
|
+
NativeModules.DdRum.stopView.mockClear();
|
|
31
|
+
NativeModules.DdRum.startAction.mockClear();
|
|
32
|
+
NativeModules.DdRum.stopAction.mockClear();
|
|
33
|
+
NativeModules.DdRum.addAction.mockClear();
|
|
34
|
+
NativeModules.DdRum.startResource.mockClear();
|
|
35
|
+
NativeModules.DdRum.stopResource.mockClear();
|
|
36
|
+
NativeModules.DdRum.addError.mockClear();
|
|
37
|
+
NativeModules.DdRum.addTiming.mockClear();
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
it('M add error source type W addError()', async () => {
|
|
42
|
+
// Given
|
|
43
|
+
const message = "Oops I did it again!";
|
|
44
|
+
const source = "SOURCE"
|
|
45
|
+
const stacktrace = "doSomething() at ./path/to/file.js:67:3";
|
|
46
|
+
const before = Date.now();
|
|
47
|
+
|
|
48
|
+
// When
|
|
49
|
+
DdRum.addError(message, source, stacktrace);
|
|
50
|
+
|
|
51
|
+
// Then
|
|
52
|
+
const after = Date.now();
|
|
53
|
+
expect(NativeModules.DdRum.addError.mock.calls.length).toBe(1);
|
|
54
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][0]).toBe(message);
|
|
55
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][1]).toBe(source);
|
|
56
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][2]).toBe(stacktrace);
|
|
57
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][4]).toBeGreaterThanOrEqual(before);
|
|
58
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][4]).toBeLessThanOrEqual(before);
|
|
59
|
+
const context = NativeModules.DdRum.addError.mock.calls[0][3];
|
|
60
|
+
expect(context["_dd.error.source_type"]).toStrictEqual("react-native");
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
it('M add error source type W addError() {with custom attributes}', async () => {
|
|
65
|
+
// Given
|
|
66
|
+
const message = "Oops I did it again!";
|
|
67
|
+
const source = "SOURCE"
|
|
68
|
+
const stacktrace = "doSomething() at ./path/to/file.js:67:3";
|
|
69
|
+
const random = Math.random();
|
|
70
|
+
const attributes = {
|
|
71
|
+
"foo": "bar",
|
|
72
|
+
"spam": random
|
|
73
|
+
}
|
|
74
|
+
const before = Date.now();
|
|
75
|
+
|
|
76
|
+
// When
|
|
77
|
+
DdRum.addError(message, source, stacktrace, attributes);
|
|
78
|
+
|
|
79
|
+
// Then
|
|
80
|
+
const after = Date.now();
|
|
81
|
+
expect(NativeModules.DdRum.addError.mock.calls.length).toBe(1);
|
|
82
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][0]).toBe(message);
|
|
83
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][1]).toBe(source);
|
|
84
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][2]).toBe(stacktrace);
|
|
85
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][4]).toBeGreaterThanOrEqual(before);
|
|
86
|
+
expect(NativeModules.DdRum.addError.mock.calls[0][4]).toBeLessThanOrEqual(before);
|
|
87
|
+
const context = NativeModules.DdRum.addError.mock.calls[0][3];
|
|
88
|
+
expect(context["_dd.error.source_type"]).toStrictEqual("react-native");
|
|
89
|
+
expect(context["foo"]).toStrictEqual("bar");
|
|
90
|
+
expect(context["spam"]).toStrictEqual(random);
|
|
91
|
+
})
|