@newrelic/browser-agent 1.234.0 → 1.236.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -2
- package/dist/cjs/common/config/state/init.js +3 -0
- package/dist/cjs/common/config/state/runtime.js +4 -4
- package/dist/cjs/common/constants/env.cdn.js +2 -2
- package/dist/cjs/common/constants/env.npm.js +1 -1
- package/dist/cjs/common/constants/runtime.js +52 -0
- package/dist/cjs/common/constants/shared-channel.js +19 -0
- package/dist/cjs/common/event-listener/event-listener-opts.js +3 -3
- package/dist/cjs/common/harvest/harvest-scheduler.js +35 -16
- package/dist/cjs/common/harvest/harvest.js +163 -144
- package/dist/cjs/common/harvest/types.js +54 -0
- package/dist/cjs/common/ids/id.js +2 -2
- package/dist/cjs/common/ids/unique-id.js +3 -3
- package/dist/cjs/common/session/session-entity.js +21 -13
- package/dist/cjs/common/timer/interaction-timer.js +3 -3
- package/dist/cjs/common/unload/eol.js +10 -11
- package/dist/cjs/common/url/canonicalize-url.js +2 -2
- package/dist/cjs/common/url/parse-url.js +3 -3
- package/dist/cjs/common/url/protocol.js +2 -2
- package/dist/cjs/common/util/feature-flags.js +23 -12
- package/dist/cjs/common/util/obfuscate.js +2 -2
- package/dist/cjs/common/util/submit-data.js +61 -79
- package/dist/cjs/common/window/nreum.js +14 -14
- package/dist/cjs/common/wrap/wrap-events.js +3 -3
- package/dist/cjs/common/wrap/wrap-fetch.js +5 -5
- package/dist/cjs/common/wrap/wrap-history.js +2 -2
- package/dist/cjs/common/wrap/wrap-jsonp.js +2 -2
- package/dist/cjs/common/wrap/wrap-mutation.js +2 -2
- package/dist/cjs/common/wrap/wrap-promise.js +2 -2
- package/dist/cjs/common/wrap/wrap-raf.js +3 -3
- package/dist/cjs/common/wrap/wrap-timer.js +5 -5
- package/dist/cjs/common/wrap/wrap-xhr.js +3 -3
- package/dist/cjs/features/ajax/aggregate/index.js +1 -1
- package/dist/cjs/features/ajax/instrument/distributed-tracing.js +2 -2
- package/dist/cjs/features/ajax/instrument/index.js +6 -7
- package/dist/cjs/features/jserrors/aggregate/index.js +11 -4
- package/dist/cjs/features/jserrors/instrument/index.js +6 -19
- package/dist/cjs/features/metrics/aggregate/framework-detection.js +2 -2
- package/dist/cjs/features/metrics/aggregate/index.js +3 -3
- package/dist/cjs/features/page_action/aggregate/index.js +3 -3
- package/dist/cjs/features/page_view_event/aggregate/index.js +10 -11
- package/dist/cjs/features/page_view_event/instrument/index.js +2 -2
- package/dist/cjs/features/page_view_timing/aggregate/index.js +3 -5
- package/dist/cjs/features/page_view_timing/instrument/index.js +2 -2
- package/dist/cjs/features/session_replay/aggregate/index.js +99 -82
- package/dist/cjs/features/session_replay/replay-mode.js +28 -0
- package/dist/cjs/features/session_trace/aggregate/index.js +222 -99
- package/dist/cjs/features/session_trace/constants.js +1 -3
- package/dist/cjs/features/session_trace/instrument/index.js +2 -18
- package/dist/cjs/features/spa/aggregate/index.js +1 -1
- package/dist/cjs/features/spa/constants.js +0 -1
- package/dist/cjs/features/spa/instrument/index.js +2 -2
- package/dist/cjs/features/utils/agent-session.js +20 -36
- package/dist/cjs/features/utils/aggregate-base.js +7 -12
- package/dist/cjs/features/utils/handler-cache.js +28 -23
- package/dist/cjs/features/utils/instrument-base.js +58 -40
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/loaders/agent.js +7 -1
- package/dist/cjs/loaders/api/api.js +2 -2
- package/dist/cjs/loaders/api/apiAsync.js +6 -4
- package/dist/cjs/loaders/configure/configure.js +2 -2
- package/dist/cjs/loaders/features/featureDependencies.js +2 -0
- package/dist/cjs/loaders/micro-agent.js +29 -38
- package/dist/esm/common/config/state/init.js +3 -0
- package/dist/esm/common/config/state/runtime.js +1 -1
- package/dist/esm/common/constants/env.cdn.js +2 -2
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/common/constants/runtime.js +38 -0
- package/dist/esm/common/constants/shared-channel.js +12 -0
- package/dist/esm/common/event-listener/event-listener-opts.js +1 -1
- package/dist/esm/common/harvest/harvest-scheduler.js +34 -17
- package/dist/esm/common/harvest/harvest.js +160 -142
- package/dist/esm/common/harvest/types.js +47 -0
- package/dist/esm/common/ids/id.js +1 -1
- package/dist/esm/common/ids/unique-id.js +1 -1
- package/dist/esm/common/session/session-entity.js +18 -12
- package/dist/esm/common/timer/interaction-timer.js +2 -2
- package/dist/esm/common/unload/eol.js +1 -2
- package/dist/esm/common/url/canonicalize-url.js +1 -1
- package/dist/esm/common/url/parse-url.js +1 -1
- package/dist/esm/common/url/protocol.js +1 -1
- package/dist/esm/common/util/feature-flags.js +23 -12
- package/dist/esm/common/util/obfuscate.js +2 -2
- package/dist/esm/common/util/submit-data.js +58 -76
- package/dist/esm/common/window/nreum.js +1 -1
- package/dist/esm/common/wrap/wrap-events.js +1 -1
- package/dist/esm/common/wrap/wrap-fetch.js +1 -1
- package/dist/esm/common/wrap/wrap-history.js +1 -1
- package/dist/esm/common/wrap/wrap-jsonp.js +1 -1
- package/dist/esm/common/wrap/wrap-mutation.js +1 -1
- package/dist/esm/common/wrap/wrap-promise.js +1 -1
- package/dist/esm/common/wrap/wrap-raf.js +2 -2
- package/dist/esm/common/wrap/wrap-timer.js +2 -2
- package/dist/esm/common/wrap/wrap-xhr.js +1 -1
- package/dist/esm/features/ajax/aggregate/index.js +1 -1
- package/dist/esm/features/ajax/instrument/distributed-tracing.js +1 -1
- package/dist/esm/features/ajax/instrument/index.js +1 -2
- package/dist/esm/features/jserrors/aggregate/index.js +10 -3
- package/dist/esm/features/jserrors/instrument/index.js +3 -16
- package/dist/esm/features/metrics/aggregate/framework-detection.js +1 -1
- package/dist/esm/features/metrics/aggregate/index.js +1 -1
- package/dist/esm/features/page_action/aggregate/index.js +1 -1
- package/dist/esm/features/page_view_event/aggregate/index.js +1 -2
- package/dist/esm/features/page_view_event/instrument/index.js +1 -1
- package/dist/esm/features/page_view_timing/aggregate/index.js +2 -4
- package/dist/esm/features/page_view_timing/instrument/index.js +1 -1
- package/dist/esm/features/session_replay/aggregate/index.js +92 -78
- package/dist/esm/features/session_replay/replay-mode.js +23 -0
- package/dist/esm/features/session_trace/aggregate/index.js +223 -100
- package/dist/esm/features/session_trace/constants.js +0 -1
- package/dist/esm/features/session_trace/instrument/index.js +2 -18
- package/dist/esm/features/spa/aggregate/index.js +1 -1
- package/dist/esm/features/spa/constants.js +0 -1
- package/dist/esm/features/spa/instrument/index.js +1 -1
- package/dist/esm/features/utils/agent-session.js +21 -37
- package/dist/esm/features/utils/aggregate-base.js +7 -12
- package/dist/esm/features/utils/handler-cache.js +28 -23
- package/dist/esm/features/utils/instrument-base.js +57 -39
- package/dist/esm/index.js +1 -4
- package/dist/esm/loaders/agent.js +7 -1
- package/dist/esm/loaders/api/api.js +2 -2
- package/dist/esm/loaders/api/apiAsync.js +3 -3
- package/dist/esm/loaders/configure/configure.js +1 -1
- package/dist/esm/loaders/features/featureDependencies.js +2 -0
- package/dist/esm/loaders/micro-agent.js +29 -38
- package/dist/types/common/config/state/init.d.ts.map +1 -1
- package/dist/types/common/constants/runtime.d.ts +29 -0
- package/dist/types/common/constants/runtime.d.ts.map +1 -0
- package/dist/types/common/constants/shared-channel.d.ts +5 -0
- package/dist/types/common/constants/shared-channel.d.ts.map +1 -0
- package/dist/types/common/harvest/harvest-scheduler.d.ts +5 -1
- package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
- package/dist/types/common/harvest/harvest.d.ts +49 -38
- package/dist/types/common/harvest/harvest.d.ts.map +1 -1
- package/dist/types/common/harvest/types.d.ts +100 -0
- package/dist/types/common/harvest/types.d.ts.map +1 -0
- package/dist/types/common/session/session-entity.d.ts +9 -5
- package/dist/types/common/session/session-entity.d.ts.map +1 -1
- package/dist/types/common/unload/eol.d.ts.map +1 -1
- package/dist/types/common/util/feature-flags.d.ts +1 -0
- package/dist/types/common/util/feature-flags.d.ts.map +1 -1
- package/dist/types/common/util/submit-data.d.ts +62 -64
- package/dist/types/common/util/submit-data.d.ts.map +1 -1
- package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts +2 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/instrument/index.d.ts +1 -1
- package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
- package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_replay/aggregate/index.d.ts +14 -5
- package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
- package/dist/types/features/session_replay/replay-mode.d.ts +9 -0
- package/dist/types/features/session_replay/replay-mode.d.ts.map +1 -0
- package/dist/types/features/session_trace/aggregate/index.d.ts +21 -3
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/constants.d.ts +0 -1
- package/dist/types/features/session_trace/constants.d.ts.map +1 -1
- package/dist/types/features/session_trace/instrument/index.d.ts +0 -2
- package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
- package/dist/types/features/spa/constants.d.ts.map +1 -1
- package/dist/types/features/utils/agent-session.d.ts.map +1 -1
- package/dist/types/features/utils/aggregate-base.d.ts +6 -1
- package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
- package/dist/types/features/utils/handler-cache.d.ts +12 -11
- package/dist/types/features/utils/handler-cache.d.ts.map +1 -1
- package/dist/types/features/utils/instrument-base.d.ts +17 -1
- package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/loaders/agent.d.ts +4 -4
- package/dist/types/loaders/agent.d.ts.map +1 -1
- package/dist/types/loaders/features/featureDependencies.d.ts.map +1 -1
- package/dist/types/loaders/micro-agent.d.ts +3 -4
- package/dist/types/loaders/micro-agent.d.ts.map +1 -1
- package/package.json +14 -7
- package/src/common/config/__mocks__/config.js +11 -0
- package/src/common/config/state/init.js +1 -0
- package/src/common/config/state/runtime.js +1 -1
- package/src/common/constants/__mocks__/env.js +3 -0
- package/src/common/constants/__mocks__/runtime.js +8 -0
- package/src/common/constants/env.cdn.test.js +7 -0
- package/src/common/constants/env.npm.test.js +7 -0
- package/src/common/constants/env.test.js +7 -0
- package/src/common/constants/runtime.js +71 -0
- package/src/common/constants/runtime.test.js +168 -0
- package/src/common/constants/shared-channel.js +13 -0
- package/src/common/context/__mocks__/shared-context.js +8 -0
- package/src/common/event-listener/__mocks__/event-listener-opts.js +7 -0
- package/src/common/event-listener/event-listener-opts.js +1 -1
- package/src/common/harvest/__mocks__/harvest.js +13 -0
- package/src/common/harvest/harvest-scheduler.js +31 -19
- package/src/common/harvest/harvest-scheduler.test.js +491 -20
- package/src/common/harvest/harvest.js +147 -130
- package/src/common/harvest/harvest.test.js +788 -139
- package/src/common/harvest/types.js +47 -0
- package/src/common/ids/id.js +1 -1
- package/src/common/ids/unique-id.js +1 -1
- package/src/common/session/__mocks__/session-entity.js +25 -0
- package/src/common/session/{session-entity.test.js → session-entity.component-test.js} +71 -48
- package/src/common/session/session-entity.js +16 -13
- package/src/common/timer/interaction-timer.js +2 -2
- package/src/common/timing/__mocks__/now.js +1 -0
- package/src/common/unload/__mocks__/eol.js +1 -0
- package/src/common/unload/eol.js +1 -2
- package/src/common/url/__mocks__/clean-url.js +1 -0
- package/src/common/url/__mocks__/encode.js +7 -0
- package/src/common/url/__mocks__/location.js +1 -0
- package/src/common/url/canonicalize-url.js +1 -1
- package/src/common/url/canonicalize-url.test.js +32 -21
- package/src/common/url/parse-url.js +1 -1
- package/src/common/url/parse-url.test.js +3 -3
- package/src/common/url/protocol.js +1 -1
- package/src/common/util/__mocks__/obfuscate.js +10 -0
- package/src/common/util/__mocks__/stringify.js +1 -0
- package/src/common/util/__mocks__/submit-data.js +6 -0
- package/src/common/util/__mocks__/traverse.js +1 -0
- package/src/common/util/data-size.test.js +27 -20
- package/src/common/util/feature-flags.js +24 -12
- package/src/common/util/feature-flags.test.js +98 -0
- package/src/common/util/obfuscate.component-test.js +173 -0
- package/src/common/util/obfuscate.js +2 -2
- package/src/common/util/submit-data.js +42 -56
- package/src/common/util/submit-data.test.js +158 -137
- package/src/common/window/nreum.js +1 -1
- package/src/common/wrap/wrap-events.js +1 -1
- package/src/common/wrap/wrap-fetch.js +1 -1
- package/src/common/wrap/wrap-history.js +1 -1
- package/src/common/wrap/wrap-jsonp.js +1 -1
- package/src/common/wrap/wrap-mutation.js +1 -1
- package/src/common/wrap/wrap-promise.js +1 -1
- package/src/common/wrap/wrap-promise.test.js +2 -2
- package/src/common/wrap/wrap-raf.js +2 -2
- package/src/common/wrap/wrap-timer.js +2 -2
- package/src/common/wrap/wrap-xhr.js +1 -1
- package/src/features/ajax/aggregate/index.js +1 -1
- package/src/features/ajax/instrument/distributed-tracing.js +1 -1
- package/src/features/ajax/instrument/index.js +1 -2
- package/src/features/jserrors/aggregate/compute-stack-trace.test.js +1 -1
- package/src/features/jserrors/aggregate/index.js +12 -3
- package/src/features/jserrors/instrument/index.js +3 -16
- package/src/features/metrics/aggregate/framework-detection.js +1 -1
- package/src/features/metrics/aggregate/framework-detection.test.js +2 -2
- package/src/features/metrics/aggregate/index.js +1 -1
- package/src/features/page_action/aggregate/index.js +1 -1
- package/src/features/page_view_event/aggregate/index.js +1 -2
- package/src/features/page_view_event/instrument/index.js +1 -1
- package/src/features/page_view_timing/aggregate/index.js +2 -4
- package/src/features/page_view_timing/instrument/index.js +1 -1
- package/src/features/session_replay/aggregate/index.component-test.js +368 -0
- package/src/features/session_replay/aggregate/index.js +96 -71
- package/src/features/session_replay/instrument/index.js +0 -1
- package/src/features/session_replay/replay-mode.js +23 -0
- package/src/features/session_trace/aggregate/index.js +198 -79
- package/src/features/session_trace/constants.js +0 -1
- package/src/features/session_trace/instrument/index.js +3 -20
- package/src/features/spa/aggregate/index.js +1 -1
- package/src/features/spa/constants.js +0 -1
- package/src/features/spa/instrument/index.js +1 -1
- package/src/features/utils/agent-session.js +22 -34
- package/src/features/utils/agent-session.test.js +194 -0
- package/src/features/utils/aggregate-base.js +12 -9
- package/src/features/utils/aggregate-base.test.js +122 -0
- package/src/features/utils/feature-base.test.js +45 -0
- package/src/features/utils/handler-cache.js +29 -23
- package/src/features/utils/handler-cache.test.js +72 -0
- package/src/features/utils/instrument-base.js +45 -29
- package/src/features/utils/instrument-base.test.js +209 -0
- package/src/features/utils/lazy-feature-loader.test.js +37 -0
- package/src/index.js +1 -3
- package/src/loaders/agent.js +8 -1
- package/src/loaders/api/api.js +2 -2
- package/src/loaders/api/apiAsync.js +3 -3
- package/src/loaders/configure/configure.js +1 -1
- package/src/loaders/features/featureDependencies.js +2 -0
- package/src/loaders/micro-agent.js +26 -30
- package/dist/cjs/common/browser-version/firefox-version.js +0 -17
- package/dist/cjs/common/browser-version/ios-version.js +0 -19
- package/dist/cjs/common/event-emitter/contextual-ee.test.js +0 -282
- package/dist/cjs/common/event-emitter/handle.test.js +0 -58
- package/dist/cjs/common/event-emitter/register-handler.test.js +0 -55
- package/dist/cjs/common/harvest/harvest-scheduler.test.js +0 -39
- package/dist/cjs/common/harvest/harvest.test.js +0 -224
- package/dist/cjs/common/ids/id.test.js +0 -85
- package/dist/cjs/common/ids/unique-id.test.js +0 -49
- package/dist/cjs/common/session/session-entity.test.js +0 -460
- package/dist/cjs/common/storage/local-memory.js +0 -35
- package/dist/cjs/common/storage/local-memory.test.js +0 -20
- package/dist/cjs/common/storage/local-storage.test.js +0 -14
- package/dist/cjs/common/timer/interaction-timer.test.js +0 -216
- package/dist/cjs/common/timer/timer.test.js +0 -105
- package/dist/cjs/common/timing/nav-timing.test.js +0 -192
- package/dist/cjs/common/url/canonicalize-url.test.js +0 -42
- package/dist/cjs/common/url/clean-url.test.js +0 -9
- package/dist/cjs/common/url/encode.test.js +0 -74
- package/dist/cjs/common/url/location.test.js +0 -13
- package/dist/cjs/common/url/parse-url.test.js +0 -111
- package/dist/cjs/common/url/protocol.test.js +0 -15
- package/dist/cjs/common/util/console.test.js +0 -30
- package/dist/cjs/common/util/data-size.test.js +0 -47
- package/dist/cjs/common/util/get-or-set.test.js +0 -47
- package/dist/cjs/common/util/global-scope.js +0 -58
- package/dist/cjs/common/util/invoke.test.js +0 -49
- package/dist/cjs/common/util/map-own.test.js +0 -49
- package/dist/cjs/common/util/stringify.test.js +0 -48
- package/dist/cjs/common/util/submit-data.test.js +0 -221
- package/dist/cjs/common/util/traverse.test.js +0 -44
- package/dist/cjs/common/wrap/wrap-promise.test.js +0 -119
- package/dist/cjs/features/jserrors/aggregate/canonical-function-name.test.js +0 -31
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +0 -383
- package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +0 -40
- package/dist/cjs/features/jserrors/aggregate/string-hash-code.test.js +0 -27
- package/dist/cjs/features/metrics/aggregate/framework-detection.test.js +0 -137
- package/dist/cjs/features/metrics/aggregate/polyfill-detection.es5.test.js +0 -17
- package/dist/cjs/features/metrics/aggregate/polyfill-detection.test.js +0 -165
- package/dist/cjs/features/spa/aggregate/interaction-node.test.js +0 -16
- package/dist/esm/common/browser-version/firefox-version.js +0 -10
- package/dist/esm/common/browser-version/ios-version.js +0 -11
- package/dist/esm/common/event-emitter/contextual-ee.test.js +0 -278
- package/dist/esm/common/event-emitter/handle.test.js +0 -54
- package/dist/esm/common/event-emitter/register-handler.test.js +0 -51
- package/dist/esm/common/harvest/harvest-scheduler.test.js +0 -37
- package/dist/esm/common/harvest/harvest.test.js +0 -222
- package/dist/esm/common/ids/id.test.js +0 -81
- package/dist/esm/common/ids/unique-id.test.js +0 -44
- package/dist/esm/common/session/session-entity.test.js +0 -458
- package/dist/esm/common/storage/local-memory.js +0 -28
- package/dist/esm/common/storage/local-memory.test.js +0 -18
- package/dist/esm/common/storage/local-storage.test.js +0 -12
- package/dist/esm/common/timer/interaction-timer.test.js +0 -214
- package/dist/esm/common/timer/timer.test.js +0 -103
- package/dist/esm/common/timing/nav-timing.test.js +0 -190
- package/dist/esm/common/url/canonicalize-url.test.js +0 -38
- package/dist/esm/common/url/clean-url.test.js +0 -7
- package/dist/esm/common/url/encode.test.js +0 -70
- package/dist/esm/common/url/location.test.js +0 -11
- package/dist/esm/common/url/parse-url.test.js +0 -107
- package/dist/esm/common/url/protocol.test.js +0 -13
- package/dist/esm/common/util/console.test.js +0 -28
- package/dist/esm/common/util/data-size.test.js +0 -45
- package/dist/esm/common/util/get-or-set.test.js +0 -45
- package/dist/esm/common/util/global-scope.js +0 -45
- package/dist/esm/common/util/invoke.test.js +0 -47
- package/dist/esm/common/util/map-own.test.js +0 -47
- package/dist/esm/common/util/stringify.test.js +0 -46
- package/dist/esm/common/util/submit-data.test.js +0 -219
- package/dist/esm/common/util/traverse.test.js +0 -42
- package/dist/esm/common/wrap/wrap-promise.test.js +0 -115
- package/dist/esm/features/jserrors/aggregate/canonical-function-name.test.js +0 -29
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +0 -379
- package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +0 -38
- package/dist/esm/features/jserrors/aggregate/string-hash-code.test.js +0 -25
- package/dist/esm/features/metrics/aggregate/framework-detection.test.js +0 -133
- package/dist/esm/features/metrics/aggregate/polyfill-detection.es5.test.js +0 -15
- package/dist/esm/features/metrics/aggregate/polyfill-detection.test.js +0 -163
- package/dist/esm/features/spa/aggregate/interaction-node.test.js +0 -14
- package/dist/types/common/browser-version/firefox-version.d.ts +0 -2
- package/dist/types/common/browser-version/firefox-version.d.ts.map +0 -1
- package/dist/types/common/browser-version/ios-version.d.ts +0 -3
- package/dist/types/common/browser-version/ios-version.d.ts.map +0 -1
- package/dist/types/common/storage/local-memory.d.ts +0 -8
- package/dist/types/common/storage/local-memory.d.ts.map +0 -1
- package/dist/types/common/util/global-scope.d.ts +0 -14
- package/dist/types/common/util/global-scope.d.ts.map +0 -1
- package/src/common/browser-version/firefox-version.js +0 -10
- package/src/common/browser-version/ios-version.js +0 -11
- package/src/common/storage/local-memory.js +0 -30
- package/src/common/storage/local-memory.test.js +0 -19
- package/src/common/util/global-scope.js +0 -49
- /package/src/common/timer/{interaction-timer.test.js → interaction-timer.component-test.js} +0 -0
- /package/src/common/url/{encode.test.js → encode.component-test.js} +0 -0
- /package/src/common/url/{protocol.test.js → protocol.component-test.js} +0 -0
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { faker } from '@faker-js/faker';
|
|
2
|
-
jest.mock('./contextual-ee', () => ({
|
|
3
|
-
__esModule: true,
|
|
4
|
-
ee: {
|
|
5
|
-
buffer: jest.fn(),
|
|
6
|
-
emit: jest.fn(),
|
|
7
|
-
get: jest.fn(() => ({
|
|
8
|
-
buffer: jest.fn(),
|
|
9
|
-
emit: jest.fn()
|
|
10
|
-
}))
|
|
11
|
-
}
|
|
12
|
-
}));
|
|
13
|
-
afterEach(() => {
|
|
14
|
-
jest.resetModules();
|
|
15
|
-
jest.resetAllMocks();
|
|
16
|
-
});
|
|
17
|
-
test('it should create and use a default event-emitter', async () => {
|
|
18
|
-
const {
|
|
19
|
-
ee
|
|
20
|
-
} = await import('./contextual-ee');
|
|
21
|
-
const {
|
|
22
|
-
handle
|
|
23
|
-
} = await import('./handle');
|
|
24
|
-
const handleEE = jest.mocked(ee.get).mock.results[0].value;
|
|
25
|
-
const eventType = faker.datatype.uuid();
|
|
26
|
-
const eventArgs = ['a', 'b', 'c'];
|
|
27
|
-
const eventContext = {};
|
|
28
|
-
const eventGroup = faker.datatype.uuid();
|
|
29
|
-
handle(eventType, eventArgs, eventContext, eventGroup);
|
|
30
|
-
expect(handleEE.buffer).toHaveBeenCalledWith([eventType], eventGroup);
|
|
31
|
-
expect(handleEE.emit).toHaveBeenCalledWith(eventType, eventArgs, eventContext);
|
|
32
|
-
});
|
|
33
|
-
test('it should use the provided scoped event-emitter', async () => {
|
|
34
|
-
const {
|
|
35
|
-
ee
|
|
36
|
-
} = await import('./contextual-ee');
|
|
37
|
-
const {
|
|
38
|
-
handle
|
|
39
|
-
} = await import('./handle');
|
|
40
|
-
const scopedEE = {
|
|
41
|
-
buffer: jest.fn(),
|
|
42
|
-
emit: jest.fn()
|
|
43
|
-
};
|
|
44
|
-
const handleEE = jest.mocked(ee.get).mock.results[0].value;
|
|
45
|
-
const eventType = faker.datatype.uuid();
|
|
46
|
-
const eventArgs = ['a', 'b', 'c'];
|
|
47
|
-
const eventContext = {};
|
|
48
|
-
const eventGroup = faker.datatype.uuid();
|
|
49
|
-
handle(eventType, eventArgs, eventContext, eventGroup, scopedEE);
|
|
50
|
-
expect(handleEE.buffer).not.toHaveBeenCalled();
|
|
51
|
-
expect(handleEE.emit).not.toHaveBeenCalled();
|
|
52
|
-
expect(scopedEE.buffer).toHaveBeenCalledWith([eventType], eventGroup);
|
|
53
|
-
expect(scopedEE.emit).toHaveBeenCalledWith(eventType, eventArgs, eventContext);
|
|
54
|
-
});
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { faker } from '@faker-js/faker';
|
|
2
|
-
jest.mock('./handle', () => ({
|
|
3
|
-
__esModule: true,
|
|
4
|
-
handleEE: {}
|
|
5
|
-
}));
|
|
6
|
-
afterEach(() => {
|
|
7
|
-
jest.resetModules();
|
|
8
|
-
jest.resetAllMocks();
|
|
9
|
-
});
|
|
10
|
-
test('should default group to "feature"', async () => {
|
|
11
|
-
const {
|
|
12
|
-
handleEE
|
|
13
|
-
} = await import('./handle');
|
|
14
|
-
const {
|
|
15
|
-
registerHandler
|
|
16
|
-
} = await import('./register-handler');
|
|
17
|
-
const eventType = faker.datatype.uuid();
|
|
18
|
-
const eventHandler = jest.fn();
|
|
19
|
-
registerHandler(eventType, eventHandler);
|
|
20
|
-
expect(registerHandler.handlers.feature).toEqual(expect.objectContaining({
|
|
21
|
-
[eventType]: [expect.arrayContaining([handleEE, eventHandler])]
|
|
22
|
-
}));
|
|
23
|
-
});
|
|
24
|
-
test('should use the provided group', async () => {
|
|
25
|
-
const {
|
|
26
|
-
handleEE
|
|
27
|
-
} = await import('./handle');
|
|
28
|
-
const {
|
|
29
|
-
registerHandler
|
|
30
|
-
} = await import('./register-handler');
|
|
31
|
-
const eventType = faker.datatype.uuid();
|
|
32
|
-
const eventGroup = faker.datatype.uuid();
|
|
33
|
-
const eventHandler = jest.fn();
|
|
34
|
-
registerHandler(eventType, eventHandler, eventGroup);
|
|
35
|
-
expect(registerHandler.handlers[eventGroup]).toEqual(expect.objectContaining({
|
|
36
|
-
[eventType]: [expect.arrayContaining([handleEE, eventHandler])]
|
|
37
|
-
}));
|
|
38
|
-
});
|
|
39
|
-
test('should use the provided event-emitter', async () => {
|
|
40
|
-
const {
|
|
41
|
-
registerHandler
|
|
42
|
-
} = await import('./register-handler');
|
|
43
|
-
const scopedEE = {};
|
|
44
|
-
const eventType = faker.datatype.uuid();
|
|
45
|
-
const eventGroup = faker.datatype.uuid();
|
|
46
|
-
const eventHandler = jest.fn();
|
|
47
|
-
registerHandler(eventType, eventHandler, eventGroup, scopedEE);
|
|
48
|
-
expect(registerHandler.handlers[eventGroup]).toEqual(expect.objectContaining({
|
|
49
|
-
[eventType]: [expect.arrayContaining([scopedEE, eventHandler])]
|
|
50
|
-
}));
|
|
51
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { setConfiguration } from '../config/state/init';
|
|
2
|
-
import { HarvestScheduler } from './harvest-scheduler';
|
|
3
|
-
describe('runHarvest', () => {
|
|
4
|
-
test('should re-schedule harvest even if there is no accumulated data', () => {
|
|
5
|
-
setConfiguration('asdf', {});
|
|
6
|
-
const scheduler = new HarvestScheduler('events', {
|
|
7
|
-
getPayload: jest.fn()
|
|
8
|
-
}, {
|
|
9
|
-
agentIdentifier: 'asdf',
|
|
10
|
-
ee: {
|
|
11
|
-
on: jest.fn()
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
scheduler.started = true;
|
|
15
|
-
jest.spyOn(scheduler, 'scheduleHarvest');
|
|
16
|
-
scheduler.runHarvest();
|
|
17
|
-
expect(scheduler.opts.getPayload()).toBeFalsy();
|
|
18
|
-
expect(scheduler.scheduleHarvest).toHaveBeenCalledTimes(1);
|
|
19
|
-
});
|
|
20
|
-
test('should also re-schedule harvest if there is accumulated data', () => {
|
|
21
|
-
setConfiguration('asdf', {});
|
|
22
|
-
const scheduler = new HarvestScheduler('events', {
|
|
23
|
-
getPayload: jest.fn().mockImplementation(() => 'payload')
|
|
24
|
-
}, {
|
|
25
|
-
agentIdentifier: 'asdf',
|
|
26
|
-
ee: {
|
|
27
|
-
on: jest.fn()
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
scheduler.started = true;
|
|
31
|
-
scheduler.harvest._send = () => {};
|
|
32
|
-
jest.spyOn(scheduler, 'scheduleHarvest');
|
|
33
|
-
scheduler.runHarvest();
|
|
34
|
-
expect(scheduler.opts.getPayload()).toBeTruthy();
|
|
35
|
-
expect(scheduler.scheduleHarvest).toHaveBeenCalledTimes(1);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
import { submitData } from '../util/submit-data';
|
|
2
|
-
import { Harvest } from './harvest';
|
|
3
|
-
jest.mock('../context/shared-context', () => ({
|
|
4
|
-
__esModule: true,
|
|
5
|
-
SharedContext: function () {
|
|
6
|
-
this.sharedContext = {
|
|
7
|
-
agentIdentifier: 'abcd'
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
}));
|
|
11
|
-
jest.mock('../config/config', () => ({
|
|
12
|
-
__esModule: true,
|
|
13
|
-
getConfigurationValue: jest.fn(),
|
|
14
|
-
getInfo: jest.fn().mockReturnValue({
|
|
15
|
-
errorBeacon: 'example.com',
|
|
16
|
-
licenseKey: 'abcd'
|
|
17
|
-
}),
|
|
18
|
-
getRuntime: jest.fn().mockReturnValue({
|
|
19
|
-
bytesSent: {},
|
|
20
|
-
queryBytesSent: {}
|
|
21
|
-
})
|
|
22
|
-
}));
|
|
23
|
-
jest.mock('../util/submit-data', () => ({
|
|
24
|
-
__esModule: true,
|
|
25
|
-
submitData: {
|
|
26
|
-
xhr: jest.fn(() => ({
|
|
27
|
-
addEventListener: jest.fn()
|
|
28
|
-
})),
|
|
29
|
-
beacon: jest.fn(),
|
|
30
|
-
img: jest.fn()
|
|
31
|
-
}
|
|
32
|
-
}));
|
|
33
|
-
describe('sendX', () => {
|
|
34
|
-
test.each([null, undefined, false])('should not send request when body is empty and sendEmptyBody is %s', sendEmptyBody => {
|
|
35
|
-
const sendCallback = jest.fn();
|
|
36
|
-
const harvester = new Harvest();
|
|
37
|
-
harvester.on('jserrors', () => ({
|
|
38
|
-
body: {},
|
|
39
|
-
qs: {}
|
|
40
|
-
}));
|
|
41
|
-
harvester.sendX({
|
|
42
|
-
endpoint: 'jserrors',
|
|
43
|
-
cbFinished: sendCallback
|
|
44
|
-
});
|
|
45
|
-
expect(sendCallback).toHaveBeenCalledWith({
|
|
46
|
-
sent: false
|
|
47
|
-
});
|
|
48
|
-
expect(submitData.xhr).not.toHaveBeenCalled();
|
|
49
|
-
expect(submitData.img).not.toHaveBeenCalled();
|
|
50
|
-
expect(submitData.beacon).not.toHaveBeenCalled();
|
|
51
|
-
});
|
|
52
|
-
test('should send request when body is empty and sendEmptyBody is true', () => {
|
|
53
|
-
const harvester = new Harvest();
|
|
54
|
-
harvester.on('jserrors', () => ({
|
|
55
|
-
body: {},
|
|
56
|
-
qs: {}
|
|
57
|
-
}));
|
|
58
|
-
harvester.sendX({
|
|
59
|
-
endpoint: 'jserrors',
|
|
60
|
-
opts: {
|
|
61
|
-
sendEmptyBody: true
|
|
62
|
-
},
|
|
63
|
-
cbFinished: jest.fn()
|
|
64
|
-
});
|
|
65
|
-
expect(submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
66
|
-
url: expect.stringContaining('https://example.com/jserrors/1/abcd?'),
|
|
67
|
-
body: undefined
|
|
68
|
-
}));
|
|
69
|
-
expect(submitData.img).not.toHaveBeenCalled();
|
|
70
|
-
expect(submitData.beacon).not.toHaveBeenCalled();
|
|
71
|
-
});
|
|
72
|
-
test.each([null, undefined, []])('should remove %s values from the body and query string when sending', emptyValue => {
|
|
73
|
-
const harvester = new Harvest();
|
|
74
|
-
harvester.on('jserrors', () => ({
|
|
75
|
-
body: {
|
|
76
|
-
bar: 'foo',
|
|
77
|
-
empty: emptyValue
|
|
78
|
-
},
|
|
79
|
-
qs: {
|
|
80
|
-
foo: 'bar',
|
|
81
|
-
empty: emptyValue
|
|
82
|
-
}
|
|
83
|
-
}));
|
|
84
|
-
harvester.sendX({
|
|
85
|
-
endpoint: 'jserrors',
|
|
86
|
-
cbFinished: jest.fn()
|
|
87
|
-
});
|
|
88
|
-
expect(submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
89
|
-
url: expect.stringContaining('&foo=bar'),
|
|
90
|
-
body: JSON.stringify({
|
|
91
|
-
bar: 'foo'
|
|
92
|
-
})
|
|
93
|
-
}));
|
|
94
|
-
expect(submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
95
|
-
url: expect.not.stringContaining('&empty'),
|
|
96
|
-
body: expect.not.stringContaining('empty')
|
|
97
|
-
}));
|
|
98
|
-
expect(submitData.img).not.toHaveBeenCalled();
|
|
99
|
-
expect(submitData.beacon).not.toHaveBeenCalled();
|
|
100
|
-
});
|
|
101
|
-
test.each([1, false, true])('should not remove value %s (when it doesn\'t have a length) from the body and query string when sending', nonStringValue => {
|
|
102
|
-
const harvester = new Harvest();
|
|
103
|
-
harvester.on('jserrors', () => ({
|
|
104
|
-
body: {
|
|
105
|
-
bar: 'foo',
|
|
106
|
-
nonString: nonStringValue
|
|
107
|
-
},
|
|
108
|
-
qs: {
|
|
109
|
-
foo: 'bar',
|
|
110
|
-
nonString: nonStringValue
|
|
111
|
-
}
|
|
112
|
-
}));
|
|
113
|
-
harvester.sendX({
|
|
114
|
-
endpoint: 'jserrors',
|
|
115
|
-
cbFinished: jest.fn()
|
|
116
|
-
});
|
|
117
|
-
expect(submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
118
|
-
url: expect.stringContaining("&nonString=".concat(nonStringValue)),
|
|
119
|
-
body: JSON.stringify({
|
|
120
|
-
bar: 'foo',
|
|
121
|
-
nonString: nonStringValue
|
|
122
|
-
})
|
|
123
|
-
}));
|
|
124
|
-
expect(submitData.img).not.toHaveBeenCalled();
|
|
125
|
-
expect(submitData.beacon).not.toHaveBeenCalled();
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
describe('send', () => {
|
|
129
|
-
test.each([null, undefined, false])('should not send request when body is empty and sendEmptyBody is %s', sendEmptyBody => {
|
|
130
|
-
const sendCallback = jest.fn();
|
|
131
|
-
const harvester = new Harvest();
|
|
132
|
-
harvester.send({
|
|
133
|
-
endpoint: 'rum',
|
|
134
|
-
payload: {
|
|
135
|
-
qs: {},
|
|
136
|
-
body: {}
|
|
137
|
-
},
|
|
138
|
-
opts: {
|
|
139
|
-
sendEmptyBody
|
|
140
|
-
},
|
|
141
|
-
cbFinished: sendCallback
|
|
142
|
-
});
|
|
143
|
-
expect(sendCallback).toHaveBeenCalledWith({
|
|
144
|
-
sent: false
|
|
145
|
-
});
|
|
146
|
-
expect(submitData.xhr).not.toHaveBeenCalled();
|
|
147
|
-
expect(submitData.img).not.toHaveBeenCalled();
|
|
148
|
-
expect(submitData.beacon).not.toHaveBeenCalled();
|
|
149
|
-
});
|
|
150
|
-
test('should send request when body is empty and sendEmptyBody is true', () => {
|
|
151
|
-
const harvester = new Harvest();
|
|
152
|
-
harvester.send({
|
|
153
|
-
endpoint: 'rum',
|
|
154
|
-
payload: {
|
|
155
|
-
qs: {},
|
|
156
|
-
body: {}
|
|
157
|
-
},
|
|
158
|
-
opts: {
|
|
159
|
-
sendEmptyBody: true
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
expect(submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
163
|
-
url: expect.stringContaining('https://example.com/1/abcd?'),
|
|
164
|
-
body: undefined
|
|
165
|
-
}));
|
|
166
|
-
expect(submitData.img).not.toHaveBeenCalled();
|
|
167
|
-
expect(submitData.beacon).not.toHaveBeenCalled();
|
|
168
|
-
});
|
|
169
|
-
test.each([null, undefined, []])('should remove %s values from the body and query string when sending', emptyValue => {
|
|
170
|
-
const harvester = new Harvest();
|
|
171
|
-
harvester.send({
|
|
172
|
-
endpoint: 'rum',
|
|
173
|
-
payload: {
|
|
174
|
-
qs: {
|
|
175
|
-
foo: 'bar',
|
|
176
|
-
empty: emptyValue
|
|
177
|
-
},
|
|
178
|
-
body: {
|
|
179
|
-
bar: 'foo',
|
|
180
|
-
empty: emptyValue
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
expect(submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
185
|
-
url: expect.stringContaining('&foo=bar'),
|
|
186
|
-
body: JSON.stringify({
|
|
187
|
-
bar: 'foo'
|
|
188
|
-
})
|
|
189
|
-
}));
|
|
190
|
-
expect(submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
191
|
-
url: expect.not.stringContaining('&empty'),
|
|
192
|
-
body: expect.not.stringContaining('empty')
|
|
193
|
-
}));
|
|
194
|
-
expect(submitData.img).not.toHaveBeenCalled();
|
|
195
|
-
expect(submitData.beacon).not.toHaveBeenCalled();
|
|
196
|
-
});
|
|
197
|
-
test.each([1, false, true])('should not remove value %s (when it doesn\'t have a length) from the body and query string when sending', nonStringValue => {
|
|
198
|
-
const harvester = new Harvest();
|
|
199
|
-
harvester.send({
|
|
200
|
-
endpoint: 'rum',
|
|
201
|
-
payload: {
|
|
202
|
-
qs: {
|
|
203
|
-
foo: 'bar',
|
|
204
|
-
nonString: nonStringValue
|
|
205
|
-
},
|
|
206
|
-
body: {
|
|
207
|
-
bar: 'foo',
|
|
208
|
-
nonString: nonStringValue
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
expect(submitData.xhr).toHaveBeenCalledWith(expect.objectContaining({
|
|
213
|
-
url: expect.stringContaining("&nonString=".concat(nonStringValue)),
|
|
214
|
-
body: JSON.stringify({
|
|
215
|
-
bar: 'foo',
|
|
216
|
-
nonString: nonStringValue
|
|
217
|
-
})
|
|
218
|
-
}));
|
|
219
|
-
expect(submitData.img).not.toHaveBeenCalled();
|
|
220
|
-
expect(submitData.beacon).not.toHaveBeenCalled();
|
|
221
|
-
});
|
|
222
|
-
});
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
let idFn;
|
|
2
|
-
beforeEach(async () => {
|
|
3
|
-
idFn = (await import('./id')).id;
|
|
4
|
-
});
|
|
5
|
-
afterEach(() => {
|
|
6
|
-
jest.resetModules();
|
|
7
|
-
jest.clearAllMocks();
|
|
8
|
-
});
|
|
9
|
-
test.each([{
|
|
10
|
-
input: undefined,
|
|
11
|
-
expected: -1,
|
|
12
|
-
title: 'id of undefined is -1'
|
|
13
|
-
}, {
|
|
14
|
-
input: null,
|
|
15
|
-
expected: -1,
|
|
16
|
-
title: 'id of null is -1'
|
|
17
|
-
}, {
|
|
18
|
-
input: 2,
|
|
19
|
-
expected: -1,
|
|
20
|
-
title: 'id of number is -1'
|
|
21
|
-
}, {
|
|
22
|
-
input: 'foo',
|
|
23
|
-
expected: -1,
|
|
24
|
-
title: 'id of string is -1'
|
|
25
|
-
}])('$title', _ref => {
|
|
26
|
-
let {
|
|
27
|
-
input,
|
|
28
|
-
expected
|
|
29
|
-
} = _ref;
|
|
30
|
-
const result = idFn(input);
|
|
31
|
-
expect(typeof result).toEqual('number');
|
|
32
|
-
expect(result).toEqual(expected);
|
|
33
|
-
});
|
|
34
|
-
test('id values increment sequentially', () => {
|
|
35
|
-
const inputA = {};
|
|
36
|
-
const inputB = {};
|
|
37
|
-
const resultA = idFn(inputA);
|
|
38
|
-
const resultB = idFn(inputB);
|
|
39
|
-
expect(resultA - resultB).toEqual(-1);
|
|
40
|
-
});
|
|
41
|
-
test('id is correctly assigned to function type', () => {
|
|
42
|
-
const input = jest.fn();
|
|
43
|
-
const result = idFn(input);
|
|
44
|
-
expect(result).toEqual(1);
|
|
45
|
-
expect(input['nr@id']).toEqual(1);
|
|
46
|
-
});
|
|
47
|
-
test('id is correctly assigned to object type', () => {
|
|
48
|
-
const input = {};
|
|
49
|
-
const result = idFn(input);
|
|
50
|
-
expect(result).toEqual(1);
|
|
51
|
-
expect(input['nr@id']).toEqual(1);
|
|
52
|
-
});
|
|
53
|
-
test('id is the same when called twice on the same input', () => {
|
|
54
|
-
const input = {};
|
|
55
|
-
const result1 = idFn(input);
|
|
56
|
-
const result2 = idFn(input);
|
|
57
|
-
expect(result1).toEqual(1);
|
|
58
|
-
expect(result2).toEqual(1);
|
|
59
|
-
expect(input['nr@id']).toEqual(1);
|
|
60
|
-
});
|
|
61
|
-
test('id is zero on global scope', async () => {
|
|
62
|
-
const result = idFn(global);
|
|
63
|
-
expect(result).toEqual(0);
|
|
64
|
-
});
|
|
65
|
-
test('id on prototype is correctly inherited', () => {
|
|
66
|
-
const fn = jest.fn();
|
|
67
|
-
const a = {};
|
|
68
|
-
idFn(a);
|
|
69
|
-
fn.prototype = a;
|
|
70
|
-
const b = new fn();
|
|
71
|
-
expect(b['nr@id']).toEqual(a['nr@id']);
|
|
72
|
-
});
|
|
73
|
-
test('id on prototype is different from instance', () => {
|
|
74
|
-
const fn = jest.fn();
|
|
75
|
-
const a = {};
|
|
76
|
-
idFn(a);
|
|
77
|
-
fn.prototype = a;
|
|
78
|
-
const b = new fn();
|
|
79
|
-
const result = idFn(b);
|
|
80
|
-
expect(b['nr@id']).toEqual(result);
|
|
81
|
-
});
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import crypto from 'crypto';
|
|
2
|
-
import * as uniqueId from './unique-id';
|
|
3
|
-
const getRandomValues = jest.fn(arr => crypto.randomBytes(arr.length));
|
|
4
|
-
afterEach(() => {
|
|
5
|
-
delete global.crypto;
|
|
6
|
-
});
|
|
7
|
-
describe('generateUuid', () => {
|
|
8
|
-
const uuidv4Regex = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
|
|
9
|
-
test('should generate a uuidv4 that matches the expected format', () => {
|
|
10
|
-
const id = uniqueId.generateUuid();
|
|
11
|
-
expect(uuidv4Regex.test(id)).toEqual(true);
|
|
12
|
-
});
|
|
13
|
-
test('should support using native crypto library', () => {
|
|
14
|
-
global.crypto = {
|
|
15
|
-
getRandomValues
|
|
16
|
-
};
|
|
17
|
-
const id = uniqueId.generateUuid();
|
|
18
|
-
expect(uuidv4Regex.test(id)).toEqual(true);
|
|
19
|
-
expect(getRandomValues).toHaveBeenCalledTimes(1);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
describe('generateRandomHexString', () => {
|
|
23
|
-
const hexRegex = /^[0-9a-f]{8}$/;
|
|
24
|
-
test('should generate a valid hex string', () => {
|
|
25
|
-
const id = uniqueId.generateRandomHexString(8);
|
|
26
|
-
expect(hexRegex.test(id)).toEqual(true);
|
|
27
|
-
});
|
|
28
|
-
test('should support using native crypto library', () => {
|
|
29
|
-
global.crypto = {
|
|
30
|
-
getRandomValues
|
|
31
|
-
};
|
|
32
|
-
const id = uniqueId.generateRandomHexString(8);
|
|
33
|
-
expect(hexRegex.test(id)).toEqual(true);
|
|
34
|
-
expect(getRandomValues).toHaveBeenCalledTimes(1);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
test('generateSpanId should generate a 16 character hex string', () => {
|
|
38
|
-
const id = uniqueId.generateSpanId();
|
|
39
|
-
expect(/^[0-9a-f]{16}$/.test(id)).toEqual(true);
|
|
40
|
-
});
|
|
41
|
-
test('generateTraceId should generate a 32 character hex string', () => {
|
|
42
|
-
const id = uniqueId.generateTraceId();
|
|
43
|
-
expect(/^[0-9a-f]{32}$/.test(id)).toEqual(true);
|
|
44
|
-
});
|