@openobserve/browser-core 0.2.12-beta.9 → 0.3.1
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/cjs/boot/displayAlreadyInitializedError.d.ts +2 -0
- package/cjs/boot/displayAlreadyInitializedError.js +10 -0
- package/cjs/boot/displayAlreadyInitializedError.js.map +1 -0
- package/cjs/boot/init.d.ts +14 -0
- package/cjs/boot/init.js +39 -0
- package/cjs/boot/init.js.map +1 -0
- package/cjs/browser/addEventListener.d.ts +87 -0
- package/cjs/browser/addEventListener.js +55 -0
- package/cjs/browser/addEventListener.js.map +1 -0
- package/cjs/browser/browser.types.d.ts +51 -0
- package/cjs/browser/browser.types.js +6 -0
- package/cjs/browser/browser.types.js.map +1 -0
- package/cjs/browser/cookie.d.ts +28 -0
- package/cjs/browser/cookie.js +114 -0
- package/cjs/browser/cookie.js.map +1 -0
- package/cjs/browser/fetchObservable.d.ts +38 -0
- package/cjs/browser/fetchObservable.js +103 -0
- package/cjs/browser/fetchObservable.js.map +1 -0
- package/cjs/browser/pageMayExitObservable.d.ts +14 -0
- package/cjs/browser/pageMayExitObservable.js +45 -0
- package/cjs/browser/pageMayExitObservable.js.map +1 -0
- package/cjs/browser/runOnReadyState.d.ts +5 -0
- package/cjs/browser/runOnReadyState.js +20 -0
- package/cjs/browser/runOnReadyState.js.map +1 -0
- package/cjs/browser/xhrObservable.d.ts +24 -0
- package/cjs/browser/xhrObservable.js +86 -0
- package/cjs/browser/xhrObservable.js.map +1 -0
- package/cjs/domain/allowedTrackingOrigins.d.ts +4 -0
- package/cjs/domain/allowedTrackingOrigins.js +25 -0
- package/cjs/domain/allowedTrackingOrigins.js.map +1 -0
- package/cjs/domain/bufferedData.d.ts +14 -0
- package/cjs/domain/bufferedData.js +22 -0
- package/cjs/domain/bufferedData.js.map +1 -0
- package/cjs/domain/configuration/configuration.d.ts +312 -0
- package/cjs/domain/configuration/configuration.js +138 -0
- package/cjs/domain/configuration/configuration.js.map +1 -0
- package/cjs/domain/configuration/endpointBuilder.d.ts +12 -0
- package/cjs/domain/configuration/endpointBuilder.js +81 -0
- package/cjs/domain/configuration/endpointBuilder.js.map +1 -0
- package/cjs/domain/configuration/index.d.ts +5 -0
- package/cjs/domain/configuration/index.js +16 -0
- package/cjs/domain/configuration/index.js.map +1 -0
- package/cjs/domain/configuration/transportConfiguration.d.ts +20 -0
- package/cjs/domain/configuration/transportConfiguration.js +54 -0
- package/cjs/domain/configuration/transportConfiguration.js.map +1 -0
- package/cjs/domain/connectivity/connectivity.d.ts +14 -0
- package/cjs/domain/connectivity/connectivity.js +14 -0
- package/cjs/domain/connectivity/connectivity.js.map +1 -0
- package/cjs/domain/connectivity/index.d.ts +1 -0
- package/cjs/domain/connectivity/index.js +18 -0
- package/cjs/domain/connectivity/index.js.map +1 -0
- package/cjs/domain/console/consoleObservable.d.ts +21 -0
- package/cjs/domain/console/consoleObservable.js +84 -0
- package/cjs/domain/console/consoleObservable.js.map +1 -0
- package/cjs/domain/context/contextConstants.d.ts +21 -0
- package/cjs/domain/context/contextConstants.js +18 -0
- package/cjs/domain/context/contextConstants.js.map +1 -0
- package/cjs/domain/context/contextManager.d.ts +19 -0
- package/cjs/domain/context/contextManager.js +60 -0
- package/cjs/domain/context/contextManager.js.map +1 -0
- package/cjs/domain/context/contextUtils.d.ts +5 -0
- package/cjs/domain/context/contextUtils.js +16 -0
- package/cjs/domain/context/contextUtils.js.map +1 -0
- package/cjs/domain/context/defineContextMethod.d.ts +6 -0
- package/cjs/domain/context/defineContextMethod.js +21 -0
- package/cjs/domain/context/defineContextMethod.js.map +1 -0
- package/cjs/domain/context/storeContextManager.d.ts +6 -0
- package/cjs/domain/context/storeContextManager.js +40 -0
- package/cjs/domain/context/storeContextManager.js.map +1 -0
- package/cjs/domain/contexts/accountContext.d.ts +26 -0
- package/cjs/domain/contexts/accountContext.js +33 -0
- package/cjs/domain/contexts/accountContext.js.map +1 -0
- package/cjs/domain/contexts/globalContext.d.ts +18 -0
- package/cjs/domain/contexts/globalContext.js +21 -0
- package/cjs/domain/contexts/globalContext.js.map +1 -0
- package/cjs/domain/contexts/rumInternalContext.type.d.ts +14 -0
- package/cjs/domain/contexts/rumInternalContext.type.js +3 -0
- package/cjs/domain/contexts/rumInternalContext.type.js.map +1 -0
- package/cjs/domain/contexts/userContext.d.ts +29 -0
- package/cjs/domain/contexts/userContext.js +45 -0
- package/cjs/domain/contexts/userContext.js.map +1 -0
- package/cjs/domain/deflate/deflate.types.d.ts +40 -0
- package/cjs/domain/deflate/deflate.types.js +3 -0
- package/cjs/domain/deflate/deflate.types.js.map +1 -0
- package/cjs/domain/deflate/index.d.ts +1 -0
- package/cjs/domain/deflate/index.js +18 -0
- package/cjs/domain/deflate/index.js.map +1 -0
- package/cjs/domain/error/error.d.ts +23 -0
- package/cjs/domain/error/error.js +74 -0
- package/cjs/domain/error/error.js.map +1 -0
- package/cjs/domain/error/error.types.d.ts +47 -0
- package/cjs/domain/error/error.types.js +13 -0
- package/cjs/domain/error/error.types.js.map +1 -0
- package/cjs/domain/error/trackRuntimeError.d.ts +11 -0
- package/cjs/domain/error/trackRuntimeError.js +48 -0
- package/cjs/domain/error/trackRuntimeError.js.map +1 -0
- package/cjs/domain/eventRateLimiter/createEventRateLimiter.d.ts +5 -0
- package/cjs/domain/eventRateLimiter/createEventRateLimiter.js +41 -0
- package/cjs/domain/eventRateLimiter/createEventRateLimiter.js.map +1 -0
- package/cjs/domain/extension/extensionUtils.d.ts +10 -0
- package/cjs/domain/extension/extensionUtils.js +30 -0
- package/cjs/domain/extension/extensionUtils.js.map +1 -0
- package/cjs/domain/intakeSites.d.ts +8 -0
- package/cjs/domain/intakeSites.js +11 -0
- package/cjs/domain/intakeSites.js.map +1 -0
- package/cjs/domain/report/browser.types.d.ts +34 -0
- package/cjs/domain/report/browser.types.js +3 -0
- package/cjs/domain/report/browser.types.js.map +1 -0
- package/cjs/domain/report/reportObservable.d.ts +14 -0
- package/cjs/domain/report/reportObservable.js +99 -0
- package/cjs/domain/report/reportObservable.js.map +1 -0
- package/cjs/domain/resourceUtils.d.ts +18 -0
- package/cjs/domain/resourceUtils.js +20 -0
- package/cjs/domain/resourceUtils.js.map +1 -0
- package/cjs/domain/session/oldCookiesMigration.d.ts +11 -0
- package/cjs/domain/session/oldCookiesMigration.js +40 -0
- package/cjs/domain/session/oldCookiesMigration.js.map +1 -0
- package/cjs/domain/session/sessionConstants.d.ts +15 -0
- package/cjs/domain/session/sessionConstants.js +16 -0
- package/cjs/domain/session/sessionConstants.js.map +1 -0
- package/cjs/domain/session/sessionManager.d.ts +28 -0
- package/cjs/domain/session/sessionManager.js +201 -0
- package/cjs/domain/session/sessionManager.js.map +1 -0
- package/cjs/domain/session/sessionState.d.ts +16 -0
- package/cjs/domain/session/sessionState.js +70 -0
- package/cjs/domain/session/sessionState.js.map +1 -0
- package/cjs/domain/session/sessionStateValidation.d.ts +3 -0
- package/cjs/domain/session/sessionStateValidation.js +11 -0
- package/cjs/domain/session/sessionStateValidation.js.map +1 -0
- package/cjs/domain/session/sessionStore.d.ts +38 -0
- package/cjs/domain/session/sessionStore.js +185 -0
- package/cjs/domain/session/sessionStore.js.map +1 -0
- package/cjs/domain/session/sessionStoreOperations.d.ts +12 -0
- package/cjs/domain/session/sessionStoreOperations.js +119 -0
- package/cjs/domain/session/sessionStoreOperations.js.map +1 -0
- package/cjs/domain/session/storeStrategies/sessionInCookie.d.ts +12 -0
- package/cjs/domain/session/storeStrategies/sessionInCookie.js +104 -0
- package/cjs/domain/session/storeStrategies/sessionInCookie.js.map +1 -0
- package/cjs/domain/session/storeStrategies/sessionInLocalStorage.d.ts +6 -0
- package/cjs/domain/session/storeStrategies/sessionInLocalStorage.js +42 -0
- package/cjs/domain/session/storeStrategies/sessionInLocalStorage.js.map +1 -0
- package/cjs/domain/session/storeStrategies/sessionStoreStrategy.d.ts +16 -0
- package/cjs/domain/session/storeStrategies/sessionStoreStrategy.js +5 -0
- package/cjs/domain/session/storeStrategies/sessionStoreStrategy.js.map +1 -0
- package/cjs/domain/synthetics/syntheticsWorkerValues.d.ts +12 -0
- package/cjs/domain/synthetics/syntheticsWorkerValues.js +31 -0
- package/cjs/domain/synthetics/syntheticsWorkerValues.js.map +1 -0
- package/cjs/domain/tags.d.ts +6 -0
- package/cjs/domain/tags.js +67 -0
- package/cjs/domain/tags.js.map +1 -0
- package/cjs/domain/telemetry/index.d.ts +4 -0
- package/cjs/domain/telemetry/index.js +28 -0
- package/cjs/domain/telemetry/index.js.map +1 -0
- package/cjs/domain/telemetry/rawTelemetryEvent.types.d.ts +18 -0
- package/cjs/domain/telemetry/rawTelemetryEvent.types.js +9 -0
- package/cjs/domain/telemetry/rawTelemetryEvent.types.js.map +1 -0
- package/cjs/domain/telemetry/telemetry.d.ts +56 -0
- package/cjs/domain/telemetry/telemetry.js +241 -0
- package/cjs/domain/telemetry/telemetry.js.map +1 -0
- package/cjs/domain/telemetry/telemetryEvent.types.d.ts +866 -0
- package/cjs/domain/telemetry/telemetryEvent.types.js +7 -0
- package/cjs/domain/telemetry/telemetryEvent.types.js.map +1 -0
- package/cjs/domain/trackingConsent.d.ts +13 -0
- package/cjs/domain/trackingConsent.js +28 -0
- package/cjs/domain/trackingConsent.js.map +1 -0
- package/cjs/index.d.ts +100 -0
- package/cjs/index.js +194 -0
- package/cjs/index.js.map +1 -0
- package/cjs/tools/abstractHooks.d.ts +24 -0
- package/cjs/tools/abstractHooks.js +41 -0
- package/cjs/tools/abstractHooks.js.map +1 -0
- package/cjs/tools/abstractLifeCycle.d.ts +23 -0
- package/cjs/tools/abstractLifeCycle.js +28 -0
- package/cjs/tools/abstractLifeCycle.js.map +1 -0
- package/cjs/tools/boundedBuffer.d.ts +16 -0
- package/cjs/tools/boundedBuffer.js +32 -0
- package/cjs/tools/boundedBuffer.js.map +1 -0
- package/cjs/tools/catchUserErrors.d.ts +1 -0
- package/cjs/tools/catchUserErrors.js +15 -0
- package/cjs/tools/catchUserErrors.js.map +1 -0
- package/cjs/tools/display.d.ts +38 -0
- package/cjs/tools/display.js +44 -0
- package/cjs/tools/display.js.map +1 -0
- package/cjs/tools/encoder.d.ts +54 -0
- package/cjs/tools/encoder.js +40 -0
- package/cjs/tools/encoder.js.map +1 -0
- package/cjs/tools/experimentalFeatures.d.ts +21 -0
- package/cjs/tools/experimentalFeatures.js +50 -0
- package/cjs/tools/experimentalFeatures.js.map +1 -0
- package/cjs/tools/getZoneJsOriginalValue.d.ts +19 -0
- package/cjs/tools/getZoneJsOriginalValue.js +29 -0
- package/cjs/tools/getZoneJsOriginalValue.js.map +1 -0
- package/cjs/tools/globalObject.d.ts +19 -0
- package/cjs/tools/globalObject.js +44 -0
- package/cjs/tools/globalObject.js.map +1 -0
- package/cjs/tools/instrumentMethod.d.ts +75 -0
- package/cjs/tools/instrumentMethod.js +118 -0
- package/cjs/tools/instrumentMethod.js.map +1 -0
- package/cjs/tools/matchOption.d.ts +8 -0
- package/cjs/tools/matchOption.js +35 -0
- package/cjs/tools/matchOption.js.map +1 -0
- package/cjs/tools/mergeInto.d.ts +25 -0
- package/cjs/tools/mergeInto.js +98 -0
- package/cjs/tools/mergeInto.js.map +1 -0
- package/cjs/tools/monitor.d.ts +9 -0
- package/cjs/tools/monitor.js +62 -0
- package/cjs/tools/monitor.js.map +1 -0
- package/cjs/tools/observable.d.ts +30 -0
- package/cjs/tools/observable.js +89 -0
- package/cjs/tools/observable.js.map +1 -0
- package/cjs/tools/queueMicrotask.d.ts +1 -0
- package/cjs/tools/queueMicrotask.js +17 -0
- package/cjs/tools/queueMicrotask.js.map +1 -0
- package/cjs/tools/readBytesFromStream.d.ts +10 -0
- package/cjs/tools/readBytesFromStream.js +28 -0
- package/cjs/tools/readBytesFromStream.js.map +1 -0
- package/cjs/tools/requestIdleCallback.d.ts +12 -0
- package/cjs/tools/requestIdleCallback.js +35 -0
- package/cjs/tools/requestIdleCallback.js.map +1 -0
- package/cjs/tools/sendToExtension.d.ts +3 -0
- package/cjs/tools/sendToExtension.js +11 -0
- package/cjs/tools/sendToExtension.js.map +1 -0
- package/cjs/tools/serialisation/context.d.ts +9 -0
- package/cjs/tools/serialisation/context.js +3 -0
- package/cjs/tools/serialisation/context.js.map +1 -0
- package/cjs/tools/serialisation/jsonStringify.d.ts +13 -0
- package/cjs/tools/serialisation/jsonStringify.js +48 -0
- package/cjs/tools/serialisation/jsonStringify.js.map +1 -0
- package/cjs/tools/serialisation/sanitize.d.ts +18 -0
- package/cjs/tools/serialisation/sanitize.js +188 -0
- package/cjs/tools/serialisation/sanitize.js.map +1 -0
- package/cjs/tools/stackTrace/computeStackTrace.d.ts +25 -0
- package/cjs/tools/stackTrace/computeStackTrace.js +187 -0
- package/cjs/tools/stackTrace/computeStackTrace.js.map +1 -0
- package/cjs/tools/stackTrace/handlingStack.d.ts +10 -0
- package/cjs/tools/stackTrace/handlingStack.js +46 -0
- package/cjs/tools/stackTrace/handlingStack.js.map +1 -0
- package/cjs/tools/taskQueue.d.ts +15 -0
- package/cjs/tools/taskQueue.js +54 -0
- package/cjs/tools/taskQueue.js.map +1 -0
- package/cjs/tools/timer.d.ts +5 -0
- package/cjs/tools/timer.js +22 -0
- package/cjs/tools/timer.js.map +1 -0
- package/cjs/tools/utils/arrayUtils.d.ts +3 -0
- package/cjs/tools/utils/arrayUtils.js +20 -0
- package/cjs/tools/utils/arrayUtils.js.map +1 -0
- package/cjs/tools/utils/browserDetection.d.ts +8 -0
- package/cjs/tools/utils/browserDetection.js +33 -0
- package/cjs/tools/utils/browserDetection.js.map +1 -0
- package/cjs/tools/utils/byteUtils.d.ts +8 -0
- package/cjs/tools/utils/byteUtils.js +34 -0
- package/cjs/tools/utils/byteUtils.js.map +1 -0
- package/cjs/tools/utils/functionUtils.d.ts +8 -0
- package/cjs/tools/utils/functionUtils.js +43 -0
- package/cjs/tools/utils/functionUtils.js.map +1 -0
- package/cjs/tools/utils/numberUtils.d.ts +9 -0
- package/cjs/tools/utils/numberUtils.js +24 -0
- package/cjs/tools/utils/numberUtils.js.map +1 -0
- package/cjs/tools/utils/objectUtils.d.ts +10 -0
- package/cjs/tools/utils/objectUtils.js +23 -0
- package/cjs/tools/utils/objectUtils.js.map +1 -0
- package/cjs/tools/utils/polyfills.d.ts +7 -0
- package/cjs/tools/utils/polyfills.js +23 -0
- package/cjs/tools/utils/polyfills.js.map +1 -0
- package/cjs/tools/utils/responseUtils.d.ts +2 -0
- package/cjs/tools/utils/responseUtils.js +17 -0
- package/cjs/tools/utils/responseUtils.js.map +1 -0
- package/cjs/tools/utils/stringUtils.d.ts +23 -0
- package/cjs/tools/utils/stringUtils.js +91 -0
- package/cjs/tools/utils/stringUtils.js.map +1 -0
- package/cjs/tools/utils/timeUtils.d.ts +53 -0
- package/cjs/tools/utils/timeUtils.js +101 -0
- package/cjs/tools/utils/timeUtils.js.map +1 -0
- package/cjs/tools/utils/timezone.d.ts +1 -0
- package/cjs/tools/utils/timezone.js +13 -0
- package/cjs/tools/utils/timezone.js.map +1 -0
- package/cjs/tools/utils/typeUtils.d.ts +4 -0
- package/cjs/tools/utils/typeUtils.js +16 -0
- package/cjs/tools/utils/typeUtils.js.map +1 -0
- package/cjs/tools/utils/urlPolyfill.d.ts +5 -0
- package/cjs/tools/utils/urlPolyfill.js +59 -0
- package/cjs/tools/utils/urlPolyfill.js.map +1 -0
- package/cjs/tools/valueHistory.d.ts +27 -0
- package/cjs/tools/valueHistory.js +104 -0
- package/cjs/tools/valueHistory.js.map +1 -0
- package/cjs/transport/batch.d.ts +16 -0
- package/cjs/transport/batch.js +110 -0
- package/cjs/transport/batch.js.map +1 -0
- package/cjs/transport/eventBridge.d.ts +21 -0
- package/cjs/transport/eventBridge.js +46 -0
- package/cjs/transport/eventBridge.js.map +1 -0
- package/cjs/transport/flushController.d.ts +65 -0
- package/cjs/transport/flushController.js +123 -0
- package/cjs/transport/flushController.js.map +1 -0
- package/cjs/transport/httpRequest.d.ts +56 -0
- package/cjs/transport/httpRequest.js +95 -0
- package/cjs/transport/httpRequest.js.map +1 -0
- package/cjs/transport/index.d.ts +7 -0
- package/cjs/transport/index.js +15 -0
- package/cjs/transport/index.js.map +1 -0
- package/cjs/transport/sendWithRetryStrategy.d.ts +41 -0
- package/cjs/transport/sendWithRetryStrategy.js +163 -0
- package/cjs/transport/sendWithRetryStrategy.js.map +1 -0
- package/esm/boot/displayAlreadyInitializedError.d.ts +2 -0
- package/esm/boot/displayAlreadyInitializedError.js +7 -0
- package/esm/boot/displayAlreadyInitializedError.js.map +1 -0
- package/esm/boot/init.d.ts +14 -0
- package/esm/boot/init.js +35 -0
- package/esm/boot/init.js.map +1 -0
- package/esm/browser/addEventListener.d.ts +87 -0
- package/esm/browser/addEventListener.js +51 -0
- package/esm/browser/addEventListener.js.map +1 -0
- package/esm/browser/browser.types.d.ts +51 -0
- package/esm/browser/browser.types.js +5 -0
- package/esm/browser/browser.types.js.map +1 -0
- package/esm/browser/cookie.d.ts +28 -0
- package/esm/browser/cookie.js +103 -0
- package/esm/browser/cookie.js.map +1 -0
- package/esm/browser/fetchObservable.d.ts +38 -0
- package/esm/browser/fetchObservable.js +99 -0
- package/esm/browser/fetchObservable.js.map +1 -0
- package/esm/browser/pageMayExitObservable.d.ts +14 -0
- package/esm/browser/pageMayExitObservable.js +40 -0
- package/esm/browser/pageMayExitObservable.js.map +1 -0
- package/esm/browser/runOnReadyState.d.ts +5 -0
- package/esm/browser/runOnReadyState.js +16 -0
- package/esm/browser/runOnReadyState.js.map +1 -0
- package/esm/browser/xhrObservable.d.ts +24 -0
- package/esm/browser/xhrObservable.js +83 -0
- package/esm/browser/xhrObservable.js.map +1 -0
- package/esm/domain/allowedTrackingOrigins.d.ts +4 -0
- package/esm/domain/allowedTrackingOrigins.js +21 -0
- package/esm/domain/allowedTrackingOrigins.js.map +1 -0
- package/esm/domain/bufferedData.d.ts +14 -0
- package/esm/domain/bufferedData.js +19 -0
- package/esm/domain/bufferedData.js.map +1 -0
- package/esm/domain/configuration/configuration.d.ts +312 -0
- package/esm/domain/configuration/configuration.js +132 -0
- package/esm/domain/configuration/configuration.js.map +1 -0
- package/esm/domain/configuration/endpointBuilder.d.ts +12 -0
- package/esm/domain/configuration/endpointBuilder.js +77 -0
- package/esm/domain/configuration/endpointBuilder.js.map +1 -0
- package/esm/domain/configuration/index.d.ts +5 -0
- package/esm/domain/configuration/index.js +4 -0
- package/esm/domain/configuration/index.js.map +1 -0
- package/esm/domain/configuration/transportConfiguration.d.ts +20 -0
- package/esm/domain/configuration/transportConfiguration.js +50 -0
- package/esm/domain/configuration/transportConfiguration.js.map +1 -0
- package/esm/domain/connectivity/connectivity.d.ts +14 -0
- package/esm/domain/connectivity/connectivity.js +11 -0
- package/esm/domain/connectivity/connectivity.js.map +1 -0
- package/esm/domain/connectivity/index.d.ts +1 -0
- package/esm/domain/connectivity/index.js +2 -0
- package/esm/domain/connectivity/index.js.map +1 -0
- package/esm/domain/console/consoleObservable.d.ts +21 -0
- package/esm/domain/console/consoleObservable.js +80 -0
- package/esm/domain/console/consoleObservable.js.map +1 -0
- package/esm/domain/context/contextConstants.d.ts +21 -0
- package/esm/domain/context/contextConstants.js +15 -0
- package/esm/domain/context/contextConstants.js.map +1 -0
- package/esm/domain/context/contextManager.d.ts +19 -0
- package/esm/domain/context/contextManager.js +57 -0
- package/esm/domain/context/contextManager.js.map +1 -0
- package/esm/domain/context/contextUtils.d.ts +5 -0
- package/esm/domain/context/contextUtils.js +13 -0
- package/esm/domain/context/contextUtils.js.map +1 -0
- package/esm/domain/context/defineContextMethod.d.ts +6 -0
- package/esm/domain/context/defineContextMethod.js +17 -0
- package/esm/domain/context/defineContextMethod.js.map +1 -0
- package/esm/domain/context/storeContextManager.d.ts +6 -0
- package/esm/domain/context/storeContextManager.js +35 -0
- package/esm/domain/context/storeContextManager.js.map +1 -0
- package/esm/domain/contexts/accountContext.d.ts +26 -0
- package/esm/domain/contexts/accountContext.js +29 -0
- package/esm/domain/contexts/accountContext.js.map +1 -0
- package/esm/domain/contexts/globalContext.d.ts +18 -0
- package/esm/domain/contexts/globalContext.js +17 -0
- package/esm/domain/contexts/globalContext.js.map +1 -0
- package/esm/domain/contexts/rumInternalContext.type.d.ts +14 -0
- package/esm/domain/contexts/rumInternalContext.type.js +2 -0
- package/esm/domain/contexts/rumInternalContext.type.js.map +1 -0
- package/esm/domain/contexts/userContext.d.ts +29 -0
- package/esm/domain/contexts/userContext.js +41 -0
- package/esm/domain/contexts/userContext.js.map +1 -0
- package/esm/domain/deflate/deflate.types.d.ts +40 -0
- package/esm/domain/deflate/deflate.types.js +2 -0
- package/esm/domain/deflate/deflate.types.js.map +1 -0
- package/esm/domain/deflate/index.d.ts +1 -0
- package/esm/domain/deflate/index.js +2 -0
- package/esm/domain/deflate/index.js.map +1 -0
- package/esm/domain/error/error.d.ts +23 -0
- package/esm/domain/error/error.js +65 -0
- package/esm/domain/error/error.js.map +1 -0
- package/esm/domain/error/error.types.d.ts +47 -0
- package/esm/domain/error/error.types.js +10 -0
- package/esm/domain/error/error.types.js.map +1 -0
- package/esm/domain/error/trackRuntimeError.d.ts +11 -0
- package/esm/domain/error/trackRuntimeError.js +43 -0
- package/esm/domain/error/trackRuntimeError.js.map +1 -0
- package/esm/domain/eventRateLimiter/createEventRateLimiter.d.ts +5 -0
- package/esm/domain/eventRateLimiter/createEventRateLimiter.js +38 -0
- package/esm/domain/eventRateLimiter/createEventRateLimiter.js.map +1 -0
- package/esm/domain/extension/extensionUtils.d.ts +10 -0
- package/esm/domain/extension/extensionUtils.js +25 -0
- package/esm/domain/extension/extensionUtils.js.map +1 -0
- package/esm/domain/intakeSites.d.ts +8 -0
- package/esm/domain/intakeSites.js +8 -0
- package/esm/domain/intakeSites.js.map +1 -0
- package/esm/domain/report/browser.types.d.ts +34 -0
- package/esm/domain/report/browser.types.js +2 -0
- package/esm/domain/report/browser.types.js.map +1 -0
- package/esm/domain/report/reportObservable.d.ts +14 -0
- package/esm/domain/report/reportObservable.js +95 -0
- package/esm/domain/report/reportObservable.js.map +1 -0
- package/esm/domain/resourceUtils.d.ts +18 -0
- package/esm/domain/resourceUtils.js +17 -0
- package/esm/domain/resourceUtils.js.map +1 -0
- package/esm/domain/session/oldCookiesMigration.d.ts +11 -0
- package/esm/domain/session/oldCookiesMigration.js +36 -0
- package/esm/domain/session/oldCookiesMigration.js.map +1 -0
- package/esm/domain/session/sessionConstants.d.ts +15 -0
- package/esm/domain/session/sessionConstants.js +13 -0
- package/esm/domain/session/sessionConstants.js.map +1 -0
- package/esm/domain/session/sessionManager.d.ts +28 -0
- package/esm/domain/session/sessionManager.js +196 -0
- package/esm/domain/session/sessionManager.js.map +1 -0
- package/esm/domain/session/sessionState.d.ts +16 -0
- package/esm/domain/session/sessionState.js +60 -0
- package/esm/domain/session/sessionState.js.map +1 -0
- package/esm/domain/session/sessionStateValidation.d.ts +3 -0
- package/esm/domain/session/sessionStateValidation.js +7 -0
- package/esm/domain/session/sessionStateValidation.js.map +1 -0
- package/esm/domain/session/sessionStore.d.ts +38 -0
- package/esm/domain/session/sessionStore.js +179 -0
- package/esm/domain/session/sessionStore.js.map +1 -0
- package/esm/domain/session/sessionStoreOperations.d.ts +12 -0
- package/esm/domain/session/sessionStoreOperations.js +114 -0
- package/esm/domain/session/sessionStoreOperations.js.map +1 -0
- package/esm/domain/session/storeStrategies/sessionInCookie.d.ts +12 -0
- package/esm/domain/session/storeStrategies/sessionInCookie.js +98 -0
- package/esm/domain/session/storeStrategies/sessionInCookie.js.map +1 -0
- package/esm/domain/session/storeStrategies/sessionInLocalStorage.d.ts +6 -0
- package/esm/domain/session/storeStrategies/sessionInLocalStorage.js +37 -0
- package/esm/domain/session/storeStrategies/sessionInLocalStorage.js.map +1 -0
- package/esm/domain/session/storeStrategies/sessionStoreStrategy.d.ts +16 -0
- package/esm/domain/session/storeStrategies/sessionStoreStrategy.js +2 -0
- package/esm/domain/session/storeStrategies/sessionStoreStrategy.js.map +1 -0
- package/esm/domain/synthetics/syntheticsWorkerValues.d.ts +12 -0
- package/esm/domain/synthetics/syntheticsWorkerValues.js +24 -0
- package/esm/domain/synthetics/syntheticsWorkerValues.js.map +1 -0
- package/esm/domain/tags.d.ts +6 -0
- package/esm/domain/tags.js +60 -0
- package/esm/domain/tags.js.map +1 -0
- package/esm/domain/telemetry/index.d.ts +4 -0
- package/esm/domain/telemetry/index.js +3 -0
- package/esm/domain/telemetry/index.js.map +1 -0
- package/esm/domain/telemetry/rawTelemetryEvent.types.d.ts +18 -0
- package/esm/domain/telemetry/rawTelemetryEvent.types.js +6 -0
- package/esm/domain/telemetry/rawTelemetryEvent.types.js.map +1 -0
- package/esm/domain/telemetry/telemetry.d.ts +56 -0
- package/esm/domain/telemetry/telemetry.js +228 -0
- package/esm/domain/telemetry/telemetry.js.map +1 -0
- package/esm/domain/telemetry/telemetryEvent.types.d.ts +866 -0
- package/esm/domain/telemetry/telemetryEvent.types.js +6 -0
- package/esm/domain/telemetry/telemetryEvent.types.js.map +1 -0
- package/esm/domain/trackingConsent.d.ts +13 -0
- package/esm/domain/trackingConsent.js +24 -0
- package/esm/domain/trackingConsent.js.map +1 -0
- package/esm/index.d.ts +100 -0
- package/esm/index.js +76 -0
- package/esm/index.js.map +1 -0
- package/esm/tools/abstractHooks.d.ts +24 -0
- package/esm/tools/abstractHooks.js +37 -0
- package/esm/tools/abstractHooks.js.map +1 -0
- package/esm/tools/abstractLifeCycle.d.ts +23 -0
- package/esm/tools/abstractLifeCycle.js +24 -0
- package/esm/tools/abstractLifeCycle.js.map +1 -0
- package/esm/tools/boundedBuffer.d.ts +16 -0
- package/esm/tools/boundedBuffer.js +29 -0
- package/esm/tools/boundedBuffer.js.map +1 -0
- package/esm/tools/catchUserErrors.d.ts +1 -0
- package/esm/tools/catchUserErrors.js +12 -0
- package/esm/tools/catchUserErrors.js.map +1 -0
- package/esm/tools/display.d.ts +38 -0
- package/esm/tools/display.js +41 -0
- package/esm/tools/display.js.map +1 -0
- package/esm/tools/encoder.d.ts +54 -0
- package/esm/tools/encoder.js +37 -0
- package/esm/tools/encoder.js.map +1 -0
- package/esm/tools/experimentalFeatures.d.ts +21 -0
- package/esm/tools/experimentalFeatures.js +42 -0
- package/esm/tools/experimentalFeatures.js.map +1 -0
- package/esm/tools/getZoneJsOriginalValue.d.ts +19 -0
- package/esm/tools/getZoneJsOriginalValue.js +26 -0
- package/esm/tools/getZoneJsOriginalValue.js.map +1 -0
- package/esm/tools/globalObject.d.ts +19 -0
- package/esm/tools/globalObject.js +40 -0
- package/esm/tools/globalObject.js.map +1 -0
- package/esm/tools/instrumentMethod.d.ts +75 -0
- package/esm/tools/instrumentMethod.js +114 -0
- package/esm/tools/instrumentMethod.js.map +1 -0
- package/esm/tools/matchOption.d.ts +8 -0
- package/esm/tools/matchOption.js +31 -0
- package/esm/tools/matchOption.js.map +1 -0
- package/esm/tools/mergeInto.d.ts +25 -0
- package/esm/tools/mergeInto.js +93 -0
- package/esm/tools/mergeInto.js.map +1 -0
- package/esm/tools/monitor.d.ts +9 -0
- package/esm/tools/monitor.js +52 -0
- package/esm/tools/monitor.js.map +1 -0
- package/esm/tools/observable.d.ts +30 -0
- package/esm/tools/observable.js +83 -0
- package/esm/tools/observable.js.map +1 -0
- package/esm/tools/queueMicrotask.d.ts +1 -0
- package/esm/tools/queueMicrotask.js +14 -0
- package/esm/tools/queueMicrotask.js.map +1 -0
- package/esm/tools/readBytesFromStream.d.ts +10 -0
- package/esm/tools/readBytesFromStream.js +25 -0
- package/esm/tools/readBytesFromStream.js.map +1 -0
- package/esm/tools/requestIdleCallback.d.ts +12 -0
- package/esm/tools/requestIdleCallback.js +30 -0
- package/esm/tools/requestIdleCallback.js.map +1 -0
- package/esm/tools/sendToExtension.d.ts +3 -0
- package/esm/tools/sendToExtension.js +8 -0
- package/esm/tools/sendToExtension.js.map +1 -0
- package/esm/tools/serialisation/context.d.ts +9 -0
- package/esm/tools/serialisation/context.js +2 -0
- package/esm/tools/serialisation/context.js.map +1 -0
- package/esm/tools/serialisation/jsonStringify.d.ts +13 -0
- package/esm/tools/serialisation/jsonStringify.js +44 -0
- package/esm/tools/serialisation/jsonStringify.js.map +1 -0
- package/esm/tools/serialisation/sanitize.d.ts +18 -0
- package/esm/tools/serialisation/sanitize.js +185 -0
- package/esm/tools/serialisation/sanitize.js.map +1 -0
- package/esm/tools/stackTrace/computeStackTrace.d.ts +25 -0
- package/esm/tools/stackTrace/computeStackTrace.js +183 -0
- package/esm/tools/stackTrace/computeStackTrace.js.map +1 -0
- package/esm/tools/stackTrace/handlingStack.d.ts +10 -0
- package/esm/tools/stackTrace/handlingStack.js +41 -0
- package/esm/tools/stackTrace/handlingStack.js.map +1 -0
- package/esm/tools/taskQueue.d.ts +15 -0
- package/esm/tools/taskQueue.js +50 -0
- package/esm/tools/taskQueue.js.map +1 -0
- package/esm/tools/timer.d.ts +5 -0
- package/esm/tools/timer.js +16 -0
- package/esm/tools/timer.js.map +1 -0
- package/esm/tools/utils/arrayUtils.d.ts +3 -0
- package/esm/tools/utils/arrayUtils.js +15 -0
- package/esm/tools/utils/arrayUtils.js.map +1 -0
- package/esm/tools/utils/browserDetection.d.ts +8 -0
- package/esm/tools/utils/browserDetection.js +28 -0
- package/esm/tools/utils/browserDetection.js.map +1 -0
- package/esm/tools/utils/byteUtils.d.ts +8 -0
- package/esm/tools/utils/byteUtils.js +29 -0
- package/esm/tools/utils/byteUtils.js.map +1 -0
- package/esm/tools/utils/functionUtils.d.ts +8 -0
- package/esm/tools/utils/functionUtils.js +39 -0
- package/esm/tools/utils/functionUtils.js.map +1 -0
- package/esm/tools/utils/numberUtils.d.ts +9 -0
- package/esm/tools/utils/numberUtils.js +18 -0
- package/esm/tools/utils/numberUtils.js.map +1 -0
- package/esm/tools/utils/objectUtils.d.ts +10 -0
- package/esm/tools/utils/objectUtils.js +17 -0
- package/esm/tools/utils/objectUtils.js.map +1 -0
- package/esm/tools/utils/polyfills.d.ts +7 -0
- package/esm/tools/utils/polyfills.js +18 -0
- package/esm/tools/utils/polyfills.js.map +1 -0
- package/esm/tools/utils/responseUtils.d.ts +2 -0
- package/esm/tools/utils/responseUtils.js +13 -0
- package/esm/tools/utils/responseUtils.js.map +1 -0
- package/esm/tools/utils/stringUtils.d.ts +23 -0
- package/esm/tools/utils/stringUtils.js +84 -0
- package/esm/tools/utils/stringUtils.js.map +1 -0
- package/esm/tools/utils/timeUtils.d.ts +53 -0
- package/esm/tools/utils/timeUtils.js +84 -0
- package/esm/tools/utils/timeUtils.js.map +1 -0
- package/esm/tools/utils/timezone.d.ts +1 -0
- package/esm/tools/utils/timezone.js +10 -0
- package/esm/tools/utils/timezone.js.map +1 -0
- package/esm/tools/utils/typeUtils.d.ts +4 -0
- package/esm/tools/utils/typeUtils.js +13 -0
- package/esm/tools/utils/typeUtils.js.map +1 -0
- package/esm/tools/utils/urlPolyfill.d.ts +5 -0
- package/esm/tools/utils/urlPolyfill.js +52 -0
- package/esm/tools/utils/urlPolyfill.js.map +1 -0
- package/esm/tools/valueHistory.d.ts +27 -0
- package/esm/tools/valueHistory.js +100 -0
- package/esm/tools/valueHistory.js.map +1 -0
- package/esm/transport/batch.d.ts +16 -0
- package/esm/transport/batch.js +106 -0
- package/esm/transport/batch.js.map +1 -0
- package/esm/transport/eventBridge.d.ts +21 -0
- package/esm/transport/eventBridge.js +41 -0
- package/esm/transport/eventBridge.js.map +1 -0
- package/esm/transport/flushController.d.ts +65 -0
- package/esm/transport/flushController.js +119 -0
- package/esm/transport/flushController.js.map +1 -0
- package/esm/transport/httpRequest.d.ts +56 -0
- package/esm/transport/httpRequest.js +89 -0
- package/esm/transport/httpRequest.js.map +1 -0
- package/esm/transport/index.d.ts +7 -0
- package/esm/transport/index.js +5 -0
- package/esm/transport/index.js.map +1 -0
- package/esm/transport/sendWithRetryStrategy.d.ts +41 -0
- package/esm/transport/sendWithRetryStrategy.js +158 -0
- package/esm/transport/sendWithRetryStrategy.js.map +1 -0
- package/package.json +2 -2
- package/src/boot/displayAlreadyInitializedError.spec.ts +18 -0
- package/src/boot/displayAlreadyInitializedError.ts +1 -1
- package/src/boot/init.spec.ts +50 -0
- package/src/boot/init.ts +1 -1
- package/src/browser/addEventListener.spec.ts +141 -0
- package/src/browser/addEventListener.ts +2 -2
- package/src/browser/cookie.spec.ts +53 -0
- package/src/browser/fetchObservable.spec.ts +334 -0
- package/src/browser/pageMayExitObservable.spec.ts +56 -0
- package/src/browser/xhrObservable.spec.ts +405 -0
- package/src/domain/allowedTrackingOrigins.spec.ts +210 -0
- package/src/domain/bufferedData.spec.ts +34 -0
- package/src/domain/configuration/configuration.spec.ts +236 -0
- package/src/domain/configuration/configuration.ts +6 -5
- package/src/domain/configuration/endpointBuilder.spec.ts +173 -0
- package/src/domain/configuration/endpointBuilder.ts +18 -12
- package/src/domain/configuration/transportConfiguration.spec.ts +130 -0
- package/src/domain/connectivity/connectivity.spec.ts +50 -0
- package/src/domain/console/consoleObservable.spec.ts +151 -0
- package/src/domain/context/contextManager.spec.ts +152 -0
- package/src/domain/context/contextUtils.spec.ts +26 -0
- package/src/domain/context/storeContextManager.spec.ts +103 -0
- package/src/domain/context/storeContextManager.ts +1 -1
- package/src/domain/contexts/accountContext.spec.ts +99 -0
- package/src/domain/contexts/globalContext.spec.ts +88 -0
- package/src/domain/contexts/userContext.spec.ts +156 -0
- package/src/domain/error/error.spec.ts +294 -0
- package/src/domain/error/trackRuntimeError.spec.ts +343 -0
- package/src/domain/eventRateLimiter/createEventRateLimiter.spec.ts +119 -0
- package/src/domain/extension/extensionUtils.spec.ts +47 -0
- package/src/domain/report/reportObservable.spec.ts +71 -0
- package/src/domain/session/oldCookiesMigration.spec.ts +76 -0
- package/src/domain/session/sessionManager.spec.ts +684 -0
- package/src/domain/session/sessionState.spec.ts +88 -0
- package/src/domain/session/sessionStore.spec.ts +647 -0
- package/src/domain/session/sessionStoreOperations.spec.ts +234 -0
- package/src/domain/session/storeStrategies/sessionInCookie.spec.ts +228 -0
- package/src/domain/session/storeStrategies/sessionInLocalStorage.spec.ts +75 -0
- package/src/domain/synthetics/syntheticsWorkerValues.spec.ts +82 -0
- package/src/domain/tags.spec.ts +74 -0
- package/src/domain/telemetry/telemetry.spec.ts +494 -0
- package/src/domain/trackingConsent.spec.ts +44 -0
- package/src/tools/abstractHooks.spec.ts +76 -0
- package/src/tools/abstractLifeCycle.spec.ts +46 -0
- package/src/tools/boundedBuffer.spec.ts +40 -0
- package/src/tools/catchUserErrors.spec.ts +20 -0
- package/src/tools/display.ts +3 -3
- package/src/tools/encoder.spec.ts +112 -0
- package/src/tools/experimentalFeatures.spec.ts +60 -0
- package/src/tools/getZoneJsOriginalValue.spec.ts +36 -0
- package/src/tools/instrumentMethod.spec.ts +381 -0
- package/src/tools/matchOption.spec.ts +41 -0
- package/src/tools/mergeInto.spec.ts +198 -0
- package/src/tools/monitor.spec.ts +172 -0
- package/src/tools/observable.spec.ts +259 -0
- package/src/tools/queueMicrotask.spec.ts +24 -0
- package/src/tools/readBytesFromStream.spec.ts +62 -0
- package/src/tools/requestIdleCallback.spec.ts +65 -0
- package/src/tools/serialisation/jsonStringify.spec.ts +76 -0
- package/src/tools/serialisation/sanitize.spec.ts +284 -0
- package/src/tools/stackTrace/capturedExceptions.specHelper.ts +316 -0
- package/src/tools/stackTrace/computeStackTrace.spec.ts +1007 -0
- package/src/tools/stackTrace/handlingStack.spec.ts +20 -0
- package/src/tools/taskQueue.spec.ts +60 -0
- package/src/tools/timer.spec.ts +76 -0
- package/src/tools/utils/browserDetection.spec.ts +120 -0
- package/src/tools/utils/byteUtils.spec.ts +29 -0
- package/src/tools/utils/functionUtils.spec.ts +229 -0
- package/src/tools/utils/numberUtils.spec.ts +27 -0
- package/src/tools/utils/stringUtils.spec.ts +74 -0
- package/src/tools/utils/typeUtils.spec.ts +25 -0
- package/src/tools/utils/urlPolyfill.spec.ts +55 -0
- package/src/tools/valueHistory.spec.ts +180 -0
- package/src/transport/batch.spec.ts +261 -0
- package/src/transport/eventBridge.spec.ts +90 -0
- package/src/transport/flushController.spec.ts +267 -0
- package/src/transport/httpRequest.spec.ts +400 -0
- package/src/transport/httpRequest.ts +3 -3
- package/src/transport/sendWithRetryStrategy.spec.ts +393 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { mockClock, mockZoneJs } from '../../test'
|
|
2
|
+
import type { Clock, MockZoneJs } from '../../test'
|
|
3
|
+
import type { InstrumentedMethodCall } from './instrumentMethod'
|
|
4
|
+
import { instrumentMethod, instrumentSetter } from './instrumentMethod'
|
|
5
|
+
import { noop } from './utils/functionUtils'
|
|
6
|
+
|
|
7
|
+
describe('instrumentMethod', () => {
|
|
8
|
+
const THIRD_PARTY_RESULT = 42
|
|
9
|
+
|
|
10
|
+
it('replaces the original method', () => {
|
|
11
|
+
const original = () => 1
|
|
12
|
+
const object = { method: original }
|
|
13
|
+
|
|
14
|
+
instrumentMethod(object, 'method', noop)
|
|
15
|
+
|
|
16
|
+
expect(object.method).not.toBe(original)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('calls the instrumentation before the original method', () => {
|
|
20
|
+
const originalSpy = jasmine.createSpy()
|
|
21
|
+
const instrumentationSpy = jasmine.createSpy()
|
|
22
|
+
const object = { method: originalSpy }
|
|
23
|
+
|
|
24
|
+
instrumentMethod(object, 'method', instrumentationSpy)
|
|
25
|
+
|
|
26
|
+
object.method()
|
|
27
|
+
|
|
28
|
+
expect(instrumentationSpy).toHaveBeenCalledBefore(originalSpy)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('does not set a method originally undefined', () => {
|
|
32
|
+
const object: { method?: () => number } = {}
|
|
33
|
+
|
|
34
|
+
instrumentMethod(object, 'method', noop)
|
|
35
|
+
|
|
36
|
+
expect(object.method).toBeUndefined()
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('sets an event handler even if it was originally undefined', () => {
|
|
40
|
+
const object: { onevent?: () => void } = { onevent: undefined }
|
|
41
|
+
|
|
42
|
+
const instrumentationSpy = jasmine.createSpy()
|
|
43
|
+
instrumentMethod(object, 'onevent', instrumentationSpy)
|
|
44
|
+
|
|
45
|
+
expect(object.onevent).toBeDefined()
|
|
46
|
+
|
|
47
|
+
object.onevent!()
|
|
48
|
+
expect(instrumentationSpy).toHaveBeenCalled()
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('do not set an event handler even if the event is not supported (i.e. property does not exist on object)', () => {
|
|
52
|
+
const object: { onevent?: () => void } = {}
|
|
53
|
+
|
|
54
|
+
const instrumentationSpy = jasmine.createSpy()
|
|
55
|
+
instrumentMethod(object, 'onevent', instrumentationSpy)
|
|
56
|
+
|
|
57
|
+
expect('onevent' in object).toBeFalse()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('calls the instrumentation with method target and parameters', () => {
|
|
61
|
+
const object = { method: (a: number, b: number) => a + b }
|
|
62
|
+
const instrumentationSpy = jasmine.createSpy<(call: InstrumentedMethodCall<typeof object, 'method'>) => void>()
|
|
63
|
+
instrumentMethod(object, 'method', instrumentationSpy)
|
|
64
|
+
|
|
65
|
+
object.method(2, 3)
|
|
66
|
+
|
|
67
|
+
expect(instrumentationSpy).toHaveBeenCalledOnceWith({
|
|
68
|
+
target: object,
|
|
69
|
+
parameters: jasmine.any(Object),
|
|
70
|
+
onPostCall: jasmine.any(Function),
|
|
71
|
+
handlingStack: undefined,
|
|
72
|
+
})
|
|
73
|
+
expect(instrumentationSpy.calls.mostRecent().args[0].parameters[0]).toBe(2)
|
|
74
|
+
expect(instrumentationSpy.calls.mostRecent().args[0].parameters[1]).toBe(3)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('allows replacing a parameter', () => {
|
|
78
|
+
const object = { method: (a: number) => a }
|
|
79
|
+
instrumentMethod(object, 'method', ({ parameters }) => {
|
|
80
|
+
parameters[0] = 2
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
expect(object.method(1)).toBe(2)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('allows adding a parameter', () => {
|
|
87
|
+
const object = { method: (a?: number) => a }
|
|
88
|
+
instrumentMethod(object, 'method', ({ parameters }) => {
|
|
89
|
+
parameters[0] = 2
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
expect(object.method()).toBe(2)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('calls the "onPostCall" callback with the original method result', () => {
|
|
96
|
+
const object = { method: () => 1 }
|
|
97
|
+
const onPostCallSpy = jasmine.createSpy()
|
|
98
|
+
instrumentMethod(object, 'method', ({ onPostCall }) => onPostCall(onPostCallSpy))
|
|
99
|
+
|
|
100
|
+
object.method()
|
|
101
|
+
|
|
102
|
+
expect(onPostCallSpy).toHaveBeenCalledOnceWith(1)
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('allows other instrumentations from third parties', () => {
|
|
106
|
+
const object = { method: () => 1 }
|
|
107
|
+
const instrumentationSpy = jasmine.createSpy()
|
|
108
|
+
instrumentMethod(object, 'method', instrumentationSpy)
|
|
109
|
+
|
|
110
|
+
thirdPartyInstrumentation(object)
|
|
111
|
+
|
|
112
|
+
expect(object.method()).toBe(THIRD_PARTY_RESULT)
|
|
113
|
+
expect(instrumentationSpy).toHaveBeenCalled()
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('computes the handling stack', () => {
|
|
117
|
+
const object = { method: () => 1 }
|
|
118
|
+
const instrumentationSpy = jasmine.createSpy()
|
|
119
|
+
instrumentMethod(object, 'method', instrumentationSpy, { computeHandlingStack: true })
|
|
120
|
+
|
|
121
|
+
function foo() {
|
|
122
|
+
object.method()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
foo()
|
|
126
|
+
|
|
127
|
+
expect(instrumentationSpy.calls.mostRecent().args[0].handlingStack).toEqual(
|
|
128
|
+
jasmine.stringMatching(/^HandlingStack: instrumented method\n {2}at foo @/)
|
|
129
|
+
)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
describe('stop()', () => {
|
|
133
|
+
it('does not call the instrumentation anymore', () => {
|
|
134
|
+
const object = { method: () => 1 }
|
|
135
|
+
const instrumentationSpy = jasmine.createSpy()
|
|
136
|
+
const { stop } = instrumentMethod(object, 'method', () => instrumentationSpy)
|
|
137
|
+
|
|
138
|
+
stop()
|
|
139
|
+
|
|
140
|
+
object.method()
|
|
141
|
+
expect(instrumentationSpy).not.toHaveBeenCalled()
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
describe('when the method has been instrumented by a third party', () => {
|
|
145
|
+
it('should not break the third party instrumentation', () => {
|
|
146
|
+
const object = { method: () => 1 }
|
|
147
|
+
const { stop } = instrumentMethod(object, 'method', noop)
|
|
148
|
+
|
|
149
|
+
thirdPartyInstrumentation(object)
|
|
150
|
+
const instrumentedMethod = object.method
|
|
151
|
+
|
|
152
|
+
stop()
|
|
153
|
+
|
|
154
|
+
expect(object.method).toBe(instrumentedMethod)
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
it('does not call the instrumentation', () => {
|
|
158
|
+
const object = { method: () => 1 }
|
|
159
|
+
const instrumentationSpy = jasmine.createSpy()
|
|
160
|
+
const { stop } = instrumentMethod(object, 'method', instrumentationSpy)
|
|
161
|
+
|
|
162
|
+
thirdPartyInstrumentation(object)
|
|
163
|
+
|
|
164
|
+
stop()
|
|
165
|
+
|
|
166
|
+
expect(instrumentationSpy).not.toHaveBeenCalled()
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
it('should not throw errors if original method was undefined', () => {
|
|
170
|
+
const object: { onevent?: () => number } = {}
|
|
171
|
+
const instrumentationStub = () => 2
|
|
172
|
+
const { stop } = instrumentMethod(object, 'onevent', instrumentationStub)
|
|
173
|
+
|
|
174
|
+
thirdPartyInstrumentation(object)
|
|
175
|
+
|
|
176
|
+
stop()
|
|
177
|
+
|
|
178
|
+
expect(object.onevent).not.toThrow()
|
|
179
|
+
})
|
|
180
|
+
})
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
function thirdPartyInstrumentation(object: { method?: () => number; onevent?: () => void }) {
|
|
184
|
+
const originalMethod = object.method
|
|
185
|
+
if (typeof originalMethod === 'function') {
|
|
186
|
+
object.method = () => {
|
|
187
|
+
originalMethod()
|
|
188
|
+
return THIRD_PARTY_RESULT
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const originalOnEvent = object.onevent
|
|
193
|
+
object.onevent = () => {
|
|
194
|
+
if (originalOnEvent) {
|
|
195
|
+
originalOnEvent()
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
describe('instrumentSetter', () => {
|
|
202
|
+
let clock: Clock
|
|
203
|
+
let zoneJs: MockZoneJs
|
|
204
|
+
|
|
205
|
+
beforeEach(() => {
|
|
206
|
+
clock = mockClock()
|
|
207
|
+
zoneJs = mockZoneJs()
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
it('replaces the original setter', () => {
|
|
211
|
+
const originalSetter = () => {
|
|
212
|
+
// do nothing particular, only used to test if this setter gets replaced
|
|
213
|
+
}
|
|
214
|
+
const object = {} as { foo: number }
|
|
215
|
+
Object.defineProperty(object, 'foo', { set: originalSetter, configurable: true })
|
|
216
|
+
|
|
217
|
+
instrumentSetter(object, 'foo', noop)
|
|
218
|
+
|
|
219
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
220
|
+
expect(Object.getOwnPropertyDescriptor(object, 'foo')!.set).not.toBe(originalSetter)
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
it('skips instrumentation if there is no original setter', () => {
|
|
224
|
+
const object = { foo: 1 }
|
|
225
|
+
|
|
226
|
+
instrumentSetter(object, 'foo', noop)
|
|
227
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
228
|
+
expect(Object.getOwnPropertyDescriptor(object, 'foo')!.set).toBeUndefined()
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
it('skips instrumentation if the descriptor is not configurable', () => {
|
|
232
|
+
const originalSetter = () => {
|
|
233
|
+
// do nothing particular, only used to test if this setter gets replaced
|
|
234
|
+
}
|
|
235
|
+
const object = {} as { foo: number }
|
|
236
|
+
Object.defineProperty(object, 'foo', { set: originalSetter, configurable: false })
|
|
237
|
+
|
|
238
|
+
instrumentSetter(object, 'foo', noop)
|
|
239
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
240
|
+
expect(Object.getOwnPropertyDescriptor(object, 'foo')!.set).toBe(originalSetter)
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
it('calls the original setter', () => {
|
|
244
|
+
const originalSetterSpy = jasmine.createSpy()
|
|
245
|
+
const object = {} as { foo: number }
|
|
246
|
+
Object.defineProperty(object, 'foo', { set: originalSetterSpy, configurable: true })
|
|
247
|
+
|
|
248
|
+
instrumentSetter(object, 'foo', noop)
|
|
249
|
+
|
|
250
|
+
object.foo = 1
|
|
251
|
+
expect(originalSetterSpy).toHaveBeenCalledOnceWith(1)
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
it('calls the instrumentation asynchronously', () => {
|
|
255
|
+
const instrumentationSetterSpy = jasmine.createSpy()
|
|
256
|
+
const object = {} as { foo: number }
|
|
257
|
+
Object.defineProperty(object, 'foo', { set: noop, configurable: true })
|
|
258
|
+
|
|
259
|
+
instrumentSetter(object, 'foo', instrumentationSetterSpy)
|
|
260
|
+
|
|
261
|
+
object.foo = 1
|
|
262
|
+
expect(instrumentationSetterSpy).not.toHaveBeenCalled()
|
|
263
|
+
clock.tick(0)
|
|
264
|
+
expect(instrumentationSetterSpy).toHaveBeenCalledOnceWith(object, 1)
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
it('does not use the Zone.js setTimeout function', () => {
|
|
268
|
+
const zoneJsSetTimeoutSpy = jasmine.createSpy()
|
|
269
|
+
zoneJs.replaceProperty(window, 'setTimeout', zoneJsSetTimeoutSpy)
|
|
270
|
+
|
|
271
|
+
const object = {} as { foo: number }
|
|
272
|
+
Object.defineProperty(object, 'foo', { set: noop, configurable: true })
|
|
273
|
+
|
|
274
|
+
instrumentSetter(object, 'foo', noop)
|
|
275
|
+
object.foo = 2
|
|
276
|
+
|
|
277
|
+
clock.tick(0)
|
|
278
|
+
|
|
279
|
+
expect(zoneJsSetTimeoutSpy).not.toHaveBeenCalled()
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
it('allows other instrumentations from third parties', () => {
|
|
283
|
+
const object = {} as { foo: number }
|
|
284
|
+
Object.defineProperty(object, 'foo', { set: noop, configurable: true })
|
|
285
|
+
const instrumentationSetterSpy = jasmine.createSpy()
|
|
286
|
+
instrumentSetter(object, 'foo', instrumentationSetterSpy)
|
|
287
|
+
|
|
288
|
+
const thirdPartyInstrumentationSpy = thirdPartyInstrumentation(object)
|
|
289
|
+
|
|
290
|
+
object.foo = 2
|
|
291
|
+
expect(thirdPartyInstrumentationSpy).toHaveBeenCalledOnceWith(2)
|
|
292
|
+
clock.tick(0)
|
|
293
|
+
expect(instrumentationSetterSpy).toHaveBeenCalledOnceWith(object, 2)
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
describe('stop()', () => {
|
|
297
|
+
it('restores the original behavior', () => {
|
|
298
|
+
const object = {} as { foo: number }
|
|
299
|
+
const originalSetter = () => {
|
|
300
|
+
// do nothing particular, only used to test if this setter gets replaced
|
|
301
|
+
}
|
|
302
|
+
Object.defineProperty(object, 'foo', { set: originalSetter, configurable: true })
|
|
303
|
+
const { stop } = instrumentSetter(object, 'foo', noop)
|
|
304
|
+
|
|
305
|
+
stop()
|
|
306
|
+
|
|
307
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
308
|
+
expect(Object.getOwnPropertyDescriptor(object, 'foo')!.set).toBe(originalSetter)
|
|
309
|
+
})
|
|
310
|
+
|
|
311
|
+
it('does not call the instrumentation anymore', () => {
|
|
312
|
+
const object = {} as { foo: number }
|
|
313
|
+
Object.defineProperty(object, 'foo', { set: noop, configurable: true })
|
|
314
|
+
const instrumentationSetterSpy = jasmine.createSpy()
|
|
315
|
+
const { stop } = instrumentSetter(object, 'foo', instrumentationSetterSpy)
|
|
316
|
+
|
|
317
|
+
stop()
|
|
318
|
+
|
|
319
|
+
object.foo = 2
|
|
320
|
+
clock.tick(0)
|
|
321
|
+
|
|
322
|
+
expect(instrumentationSetterSpy).not.toHaveBeenCalled()
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
it('does not call instrumentation pending in the event loop via setTimeout', () => {
|
|
326
|
+
const object = {} as { foo: number }
|
|
327
|
+
Object.defineProperty(object, 'foo', { set: noop, configurable: true })
|
|
328
|
+
const instrumentationSetterSpy = jasmine.createSpy()
|
|
329
|
+
const { stop } = instrumentSetter(object, 'foo', instrumentationSetterSpy)
|
|
330
|
+
|
|
331
|
+
object.foo = 2
|
|
332
|
+
stop()
|
|
333
|
+
clock.tick(0)
|
|
334
|
+
|
|
335
|
+
expect(instrumentationSetterSpy).not.toHaveBeenCalled()
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
describe('when the method has been instrumented by a third party', () => {
|
|
339
|
+
it('should not break the third party instrumentation', () => {
|
|
340
|
+
const object = {} as { foo: number }
|
|
341
|
+
Object.defineProperty(object, 'foo', { set: noop, configurable: true })
|
|
342
|
+
const { stop } = instrumentSetter(object, 'foo', noop)
|
|
343
|
+
|
|
344
|
+
const thirdPartyInstrumentationSpy = thirdPartyInstrumentation(object)
|
|
345
|
+
|
|
346
|
+
stop()
|
|
347
|
+
|
|
348
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
349
|
+
expect(Object.getOwnPropertyDescriptor(object, 'foo')!.set).toBe(thirdPartyInstrumentationSpy)
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
it('does not call the instrumentation', () => {
|
|
353
|
+
const object = {} as { foo: number }
|
|
354
|
+
Object.defineProperty(object, 'foo', { set: noop, configurable: true })
|
|
355
|
+
const instrumentationSetterSpy = jasmine.createSpy()
|
|
356
|
+
const { stop } = instrumentSetter(object, 'foo', instrumentationSetterSpy)
|
|
357
|
+
|
|
358
|
+
thirdPartyInstrumentation(object)
|
|
359
|
+
|
|
360
|
+
stop()
|
|
361
|
+
|
|
362
|
+
object.foo = 2
|
|
363
|
+
clock.tick(0)
|
|
364
|
+
|
|
365
|
+
expect(instrumentationSetterSpy).not.toHaveBeenCalled()
|
|
366
|
+
})
|
|
367
|
+
})
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
function thirdPartyInstrumentation(object: { foo: number }) {
|
|
371
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
372
|
+
const originalSetter = Object.getOwnPropertyDescriptor(object, 'foo')!.set
|
|
373
|
+
const thirdPartyInstrumentationSpy = jasmine.createSpy().and.callFake(function (this: any, value) {
|
|
374
|
+
if (originalSetter) {
|
|
375
|
+
originalSetter.call(this, value)
|
|
376
|
+
}
|
|
377
|
+
})
|
|
378
|
+
Object.defineProperty(object, 'foo', { set: thirdPartyInstrumentationSpy })
|
|
379
|
+
return thirdPartyInstrumentationSpy
|
|
380
|
+
}
|
|
381
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { display } from './display'
|
|
2
|
+
import { matchList } from './matchOption'
|
|
3
|
+
|
|
4
|
+
describe('matchList', () => {
|
|
5
|
+
it('should match exact value', () => {
|
|
6
|
+
const list = ['foo', 'bar']
|
|
7
|
+
expect(matchList(list, 'foo')).toBe(true)
|
|
8
|
+
expect(matchList(list, 'bar')).toBe(true)
|
|
9
|
+
expect(matchList(list, 'qux')).toBe(false)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('should match regexp', () => {
|
|
13
|
+
const list = [/^foo/, /foo$/]
|
|
14
|
+
expect(matchList(list, 'foobar')).toBe(true)
|
|
15
|
+
expect(matchList(list, 'barfoo')).toBe(true)
|
|
16
|
+
expect(matchList(list, 'barqux')).toBe(false)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('should match function', () => {
|
|
20
|
+
const list = [(value: string) => value === 'foo', (value: string) => value === 'bar']
|
|
21
|
+
expect(matchList(list, 'foo')).toBe(true)
|
|
22
|
+
expect(matchList(list, 'bar')).toBe(true)
|
|
23
|
+
expect(matchList(list, 'qux')).toBe(false)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('should compare strings using startsWith when enabling the option', () => {
|
|
27
|
+
const list = ['http://my.domain.com']
|
|
28
|
+
expect(matchList(list, 'http://my.domain.com/action', true)).toBe(true)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('should catch error from provided function', () => {
|
|
32
|
+
spyOn(display, 'error')
|
|
33
|
+
const list = [
|
|
34
|
+
(_: string) => {
|
|
35
|
+
throw new Error('oops')
|
|
36
|
+
},
|
|
37
|
+
]
|
|
38
|
+
expect(matchList(list, 'foo')).toBe(false)
|
|
39
|
+
expect(display.error).toHaveBeenCalled()
|
|
40
|
+
})
|
|
41
|
+
})
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { deepClone, mergeInto, combine } from './mergeInto'
|
|
2
|
+
|
|
3
|
+
describe('mergeInto', () => {
|
|
4
|
+
describe('source is not an object or array', () => {
|
|
5
|
+
it('should ignore undefined sources', () => {
|
|
6
|
+
const destination = {}
|
|
7
|
+
expect(mergeInto(destination, undefined)).toBe(destination)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('should ignore undefined destination', () => {
|
|
11
|
+
expect(mergeInto(undefined, 1)).toBe(1)
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('should ignore destinations with a different type', () => {
|
|
15
|
+
expect(mergeInto({}, 1)).toBe(1)
|
|
16
|
+
})
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
describe('source is an array', () => {
|
|
20
|
+
it('should create a new array if destination is undefined', () => {
|
|
21
|
+
const source = [1]
|
|
22
|
+
const result = mergeInto(undefined, source)
|
|
23
|
+
expect(result).not.toBe(source)
|
|
24
|
+
expect(result).toEqual(source)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('should return the copy of source if the destination is not an array', () => {
|
|
28
|
+
const source = [1]
|
|
29
|
+
expect(mergeInto({}, source)).toEqual(source)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
it('should mutate and return destination if it is an array', () => {
|
|
33
|
+
const destination = ['destination']
|
|
34
|
+
const source = ['source']
|
|
35
|
+
const result = mergeInto(destination, source)
|
|
36
|
+
expect(result).toBe(destination)
|
|
37
|
+
expect(result).toEqual(source)
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
describe('source is an object', () => {
|
|
42
|
+
it('should create a new object if destination is undefined', () => {
|
|
43
|
+
const source = {}
|
|
44
|
+
const result = mergeInto(undefined, source)
|
|
45
|
+
expect(result).not.toBe(source)
|
|
46
|
+
expect(result).toEqual(source)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('should return the copy of source if the destination is not an object', () => {
|
|
50
|
+
const source = { a: 1 }
|
|
51
|
+
expect(mergeInto([], source)).toEqual(source)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('should mutate and return destination if it is an object', () => {
|
|
55
|
+
const destination = {}
|
|
56
|
+
const source = { a: 'b' }
|
|
57
|
+
const result = mergeInto(destination, source)
|
|
58
|
+
expect(result).toBe(destination as any)
|
|
59
|
+
expect(result).toEqual(source)
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
describe('combine', () => {
|
|
65
|
+
it('should deeply add and replace keys', () => {
|
|
66
|
+
const sourceA = { a: { b: 'toBeReplaced', c: 'source a' } }
|
|
67
|
+
const sourceB = { a: { b: 'replaced', d: 'source b' } }
|
|
68
|
+
expect(combine(sourceA, sourceB)).toEqual({ a: { b: 'replaced', c: 'source a', d: 'source b' } })
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('should not replace with undefined', () => {
|
|
72
|
+
expect(combine({ a: 1 }, { a: undefined as number | undefined })).toEqual({ a: 1 })
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('should replace a sub-value with null', () => {
|
|
76
|
+
expect(combine({ a: {} }, { a: null as any })).toEqual({ a: null })
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('should ignore null arguments', () => {
|
|
80
|
+
expect(combine({ a: 1 }, null)).toEqual({ a: 1 })
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('should merge arrays', () => {
|
|
84
|
+
const sourceA = [{ a: 'source a' }, 'extraString'] as any
|
|
85
|
+
const sourceB = [{ b: 'source b' }] as any
|
|
86
|
+
expect(combine(sourceA, sourceB)).toEqual([{ a: 'source a', b: 'source b' }, 'extraString'])
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('should merge multiple objects', () => {
|
|
90
|
+
expect(combine({ a: 1 }, { b: 2 }, { c: 3 })).toEqual({ a: 1, b: 2, c: 3 })
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('should not keep references on objects', () => {
|
|
94
|
+
const source = { a: { b: 1 } }
|
|
95
|
+
const result = combine({}, source)
|
|
96
|
+
expect(result.a).not.toBe(source.a)
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('should not keep references on arrays', () => {
|
|
100
|
+
const source = { a: [1] }
|
|
101
|
+
const result = combine({}, source)
|
|
102
|
+
expect(result.a).not.toBe(source.a)
|
|
103
|
+
})
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
describe('deepClone', () => {
|
|
107
|
+
it('should pass-through primitive values', () => {
|
|
108
|
+
expect(deepClone('test')).toBe('test')
|
|
109
|
+
expect(deepClone(true)).toBe(true)
|
|
110
|
+
expect(deepClone(false)).toBe(false)
|
|
111
|
+
expect(deepClone(null)).toBe(null)
|
|
112
|
+
expect(deepClone(undefined)).toBe(undefined)
|
|
113
|
+
expect(deepClone(1)).toBe(1)
|
|
114
|
+
expect(deepClone(NaN)).toBeNaN()
|
|
115
|
+
expect(deepClone(Infinity)).toBe(Infinity)
|
|
116
|
+
expect(deepClone(-Infinity)).toBe(-Infinity)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('should pass-through functions', () => {
|
|
120
|
+
const fn = () => null
|
|
121
|
+
expect(deepClone(fn)).toBe(fn)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('should pass-through classes', () => {
|
|
125
|
+
class Foo {}
|
|
126
|
+
// typeof class is 'function' so it will behave the same as for function case
|
|
127
|
+
expect(deepClone(Foo)).toBe(Foo)
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('should clone array recursively', () => {
|
|
131
|
+
const source = [1, undefined, null, [4, 5, 6]]
|
|
132
|
+
const clone = deepClone(source)
|
|
133
|
+
|
|
134
|
+
expect(clone).toEqual(source)
|
|
135
|
+
expect(clone).not.toBe(source)
|
|
136
|
+
source.push(7)
|
|
137
|
+
;(source[3] as any[]).push(8)
|
|
138
|
+
|
|
139
|
+
expect(clone[4]).toBeUndefined()
|
|
140
|
+
expect((clone[3] as any[])[3]).toBeUndefined()
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('should clone object recursively', () => {
|
|
144
|
+
const source = { foo: 'bar', baz: { arr: [1, 2], fn: () => undefined } }
|
|
145
|
+
const clone = deepClone(source)
|
|
146
|
+
|
|
147
|
+
expect(clone).toEqual(source)
|
|
148
|
+
expect(clone).not.toBe(source)
|
|
149
|
+
source.baz.arr.push(1)
|
|
150
|
+
;(source.baz as any).added = 'test'
|
|
151
|
+
|
|
152
|
+
expect(clone.baz.arr).toEqual([1, 2])
|
|
153
|
+
expect((clone.baz as any).added).toBeUndefined()
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it('should clone regexp', () => {
|
|
157
|
+
const source = { reg: /test/gi }
|
|
158
|
+
const clone = deepClone(source)
|
|
159
|
+
|
|
160
|
+
expect(clone).toEqual(source)
|
|
161
|
+
expect(clone).not.toBe(source)
|
|
162
|
+
expect(clone.reg).not.toBe(source.reg)
|
|
163
|
+
|
|
164
|
+
expect(clone.reg.ignoreCase).toBe(true)
|
|
165
|
+
expect(clone.reg.global).toBe(true)
|
|
166
|
+
expect(clone.reg.multiline).toBe(false)
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
it('should clone date', () => {
|
|
170
|
+
const source = [1, new Date('2012-12-12')] as const
|
|
171
|
+
const clone = deepClone(source)
|
|
172
|
+
|
|
173
|
+
expect(clone).toEqual(source)
|
|
174
|
+
expect(clone).not.toBe(source)
|
|
175
|
+
expect(clone[1]).not.toBe(source[1])
|
|
176
|
+
|
|
177
|
+
const originalTime = source[1].getTime()
|
|
178
|
+
source[1].setTime(originalTime + 100)
|
|
179
|
+
expect(clone[1].getTime()).toEqual(originalTime)
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
it('should remove circular references', () => {
|
|
183
|
+
const a: Record<string, any> = { foo: 'bar', ref: null }
|
|
184
|
+
const b: Record<string, any> = { baz: 'bar', ref: null }
|
|
185
|
+
// create circular reference
|
|
186
|
+
a.ref = b
|
|
187
|
+
b.ref = a
|
|
188
|
+
|
|
189
|
+
const clonedA = deepClone(a)
|
|
190
|
+
const clonedB = deepClone(b)
|
|
191
|
+
|
|
192
|
+
expect(clonedA).not.toEqual(a)
|
|
193
|
+
expect(clonedA.ref.ref).toBeUndefined()
|
|
194
|
+
|
|
195
|
+
expect(clonedB).not.toEqual(b)
|
|
196
|
+
expect(clonedB.ref.ref).toBeUndefined()
|
|
197
|
+
})
|
|
198
|
+
})
|