@newrelic/browser-agent 1.235.0 → 1.237.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 +41 -1
- package/dist/cjs/common/config/state/init.js +4 -0
- package/dist/cjs/common/config/state/runtime.js +6 -5
- 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/deny-list/deny-list.js +14 -10
- package/dist/cjs/common/event-listener/event-listener-opts.js +3 -3
- package/dist/cjs/common/harvest/harvest-scheduler.js +22 -19
- package/dist/cjs/common/harvest/harvest.js +154 -148
- 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 +2 -2
- package/dist/cjs/common/timer/interaction-timer.js +2 -2
- 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/submit-data.js +31 -81
- 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 +14 -8
- 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 +2 -2
- package/dist/cjs/common/wrap/wrap-timer.js +4 -4
- package/dist/cjs/common/wrap/wrap-xhr.js +3 -3
- package/dist/cjs/features/ajax/aggregate/index.js +25 -28
- 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/compute-stack-trace.js +1 -1
- package/dist/cjs/features/jserrors/aggregate/index.js +7 -4
- package/dist/cjs/features/jserrors/constants.js +2 -4
- package/dist/cjs/features/jserrors/instrument/index.js +80 -89
- package/dist/cjs/features/jserrors/instrument/uncaught-error.js +22 -0
- 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/aggregate/initialized-features.js +23 -19
- 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 +65 -34
- package/dist/cjs/features/session_replay/replay-mode.js +2 -2
- package/dist/cjs/features/session_trace/aggregate/index.js +3 -4
- package/dist/cjs/features/session_trace/instrument/index.js +2 -2
- package/dist/cjs/features/spa/aggregate/index.js +1 -1
- package/dist/cjs/features/spa/instrument/index.js +2 -2
- package/dist/cjs/features/utils/instrument-base.js +12 -15
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/loaders/agent-base.js +87 -0
- package/dist/cjs/loaders/agent.js +48 -1
- package/dist/cjs/loaders/api/api.js +3 -3
- package/dist/cjs/loaders/api/apiAsync.js +6 -4
- package/dist/cjs/loaders/api/interaction-types.js +87 -0
- package/dist/cjs/loaders/configure/configure.js +4 -3
- package/dist/cjs/loaders/micro-agent.js +32 -39
- package/dist/esm/common/config/state/init.js +4 -0
- package/dist/esm/common/config/state/runtime.js +3 -2
- 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/deny-list/deny-list.js +14 -10
- package/dist/esm/common/event-listener/event-listener-opts.js +1 -1
- package/dist/esm/common/harvest/harvest-scheduler.js +21 -20
- package/dist/esm/common/harvest/harvest.js +150 -146
- 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 +1 -1
- package/dist/esm/common/timer/interaction-timer.js +1 -1
- 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/submit-data.js +29 -78
- 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 +13 -7
- 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 +1 -1
- package/dist/esm/common/wrap/wrap-timer.js +1 -1
- package/dist/esm/common/wrap/wrap-xhr.js +1 -1
- package/dist/esm/features/ajax/aggregate/index.js +26 -29
- 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/compute-stack-trace.js +1 -1
- package/dist/esm/features/jserrors/aggregate/index.js +6 -3
- package/dist/esm/features/jserrors/constants.js +1 -2
- package/dist/esm/features/jserrors/instrument/index.js +79 -88
- package/dist/esm/features/jserrors/instrument/uncaught-error.js +15 -0
- 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/aggregate/initialized-features.js +23 -19
- 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 +65 -34
- package/dist/esm/features/session_replay/replay-mode.js +2 -2
- package/dist/esm/features/session_trace/aggregate/index.js +3 -4
- package/dist/esm/features/session_trace/instrument/index.js +1 -1
- package/dist/esm/features/spa/aggregate/index.js +1 -1
- package/dist/esm/features/spa/instrument/index.js +1 -1
- package/dist/esm/features/utils/instrument-base.js +11 -14
- package/dist/esm/index.js +1 -4
- package/dist/esm/loaders/agent-base.js +80 -0
- package/dist/esm/loaders/agent.js +48 -1
- package/dist/esm/loaders/api/api.js +2 -2
- package/dist/esm/loaders/api/apiAsync.js +3 -3
- package/dist/esm/loaders/api/interaction-types.js +80 -0
- package/dist/esm/loaders/configure/configure.js +4 -3
- package/dist/esm/loaders/micro-agent.js +32 -39
- package/dist/types/common/config/state/init.d.ts.map +1 -1
- package/dist/types/common/config/state/runtime.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/event-emitter/register-handler.d.ts +1 -1
- package/dist/types/common/harvest/harvest-scheduler.d.ts +1 -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 +6 -6
- package/dist/types/common/unload/eol.d.ts.map +1 -1
- package/dist/types/common/util/submit-data.d.ts +44 -64
- package/dist/types/common/util/submit-data.d.ts.map +1 -1
- package/dist/types/common/window/nreum.d.ts +2 -2
- package/dist/types/common/wrap/wrap-jsonp.d.ts.map +1 -1
- package/dist/types/features/ajax/aggregate/index.d.ts +5 -5
- package/dist/types/features/ajax/aggregate/index.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 +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/constants.d.ts +0 -1
- package/dist/types/features/jserrors/constants.d.ts.map +1 -1
- package/dist/types/features/jserrors/instrument/index.d.ts +0 -13
- package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/instrument/uncaught-error.d.ts +15 -0
- package/dist/types/features/jserrors/instrument/uncaught-error.d.ts.map +1 -0
- package/dist/types/features/metrics/aggregate/endpoint-map.d.ts +5 -5
- package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_event/aggregate/initialized-features.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 +16 -30
- package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -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-base.d.ts +59 -0
- package/dist/types/loaders/agent-base.d.ts.map +1 -0
- package/dist/types/loaders/agent.d.ts +39 -5
- package/dist/types/loaders/agent.d.ts.map +1 -1
- package/dist/types/loaders/api/interaction-types.d.ts +122 -0
- package/dist/types/loaders/api/interaction-types.d.ts.map +1 -0
- package/dist/types/loaders/configure/configure.d.ts.map +1 -1
- package/dist/types/loaders/features/features.d.ts +9 -9
- package/dist/types/loaders/micro-agent.d.ts +6 -6
- package/dist/types/loaders/micro-agent.d.ts.map +1 -1
- package/package.json +6 -1
- package/src/common/config/__mocks__/config.js +11 -0
- package/src/common/config/state/init.js +2 -1
- package/src/common/config/state/runtime.js +3 -2
- 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/context/__mocks__/shared-context.js +8 -0
- package/src/common/deny-list/deny-list.js +11 -11
- package/src/common/deny-list/deny-list.test.js +31 -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 +21 -20
- package/src/common/harvest/harvest-scheduler.test.js +496 -0
- package/src/common/harvest/harvest.js +142 -134
- package/src/common/harvest/harvest.test.js +798 -0
- 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.component-test.js +1 -1
- package/src/common/session/session-entity.js +1 -1
- package/src/common/timer/interaction-timer.js +1 -1
- 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 +2 -2
- 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 +5 -0
- package/src/common/util/__mocks__/traverse.js +1 -0
- package/src/common/util/submit-data.js +22 -58
- package/src/common/util/submit-data.test.js +30 -73
- 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 +12 -7
- 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 +1 -1
- package/src/common/wrap/wrap-timer.js +1 -1
- package/src/common/wrap/wrap-xhr.js +1 -1
- package/src/features/ajax/aggregate/index.js +26 -32
- 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.js +1 -1
- package/src/features/jserrors/aggregate/compute-stack-trace.test.js +1 -1
- package/src/features/jserrors/aggregate/index.js +7 -3
- package/src/features/jserrors/constants.js +0 -1
- package/src/features/jserrors/instrument/index.js +92 -88
- package/src/features/jserrors/instrument/uncaught-error.js +15 -0
- 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/aggregate/initialized-features.js +18 -14
- 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 +17 -56
- package/src/features/session_replay/aggregate/index.js +47 -28
- package/src/features/session_replay/replay-mode.js +2 -2
- package/src/features/session_trace/aggregate/index.js +3 -4
- package/src/features/session_trace/instrument/index.js +1 -1
- package/src/features/spa/aggregate/index.js +1 -1
- package/src/features/spa/instrument/index.js +1 -1
- package/src/features/utils/agent-session.test.js +2 -2
- package/src/features/utils/instrument-base.js +11 -14
- package/src/features/utils/instrument-base.test.js +29 -3
- package/src/index.js +1 -3
- package/src/loaders/agent-base.js +81 -0
- package/src/loaders/agent.js +50 -1
- package/src/loaders/api/api.js +2 -2
- package/src/loaders/api/apiAsync.js +3 -3
- package/src/loaders/api/interaction-types.js +80 -0
- package/src/loaders/configure/configure.js +5 -4
- package/src/loaders/micro-agent.js +30 -31
- 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.component-test.js +0 -39
- package/dist/cjs/common/harvest/harvest.component-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.component-test.js +0 -497
- package/dist/cjs/common/storage/local-storage.test.js +0 -14
- package/dist/cjs/common/timer/interaction-timer.component-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 -38
- package/dist/cjs/common/url/clean-url.test.js +0 -9
- package/dist/cjs/common/url/encode.component-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.component-test.js +0 -15
- package/dist/cjs/common/util/console.test.js +0 -30
- package/dist/cjs/common/util/data-size.test.js +0 -64
- package/dist/cjs/common/util/feature-flags.test.js +0 -84
- package/dist/cjs/common/util/get-or-set.test.js +0 -47
- package/dist/cjs/common/util/global-scope.js +0 -27
- package/dist/cjs/common/util/global-scope.test.js +0 -72
- 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/obfuscate.component-test.js +0 -129
- package/dist/cjs/common/util/stringify.test.js +0 -48
- package/dist/cjs/common/util/submit-data.test.js +0 -245
- 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/jserrors/instrument/debug.js +0 -40
- 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/session_replay/aggregate/index.component-test.js +0 -457
- package/dist/cjs/features/spa/aggregate/interaction-node.test.js +0 -16
- package/dist/cjs/features/utils/agent-session.test.js +0 -211
- package/dist/cjs/features/utils/aggregate-base.test.js +0 -110
- package/dist/cjs/features/utils/feature-base.test.js +0 -42
- package/dist/cjs/features/utils/handler-cache.test.js +0 -53
- package/dist/cjs/features/utils/instrument-base.test.js +0 -179
- package/dist/cjs/features/utils/lazy-feature-loader.test.js +0 -30
- 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.component-test.js +0 -37
- package/dist/esm/common/harvest/harvest.component-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.component-test.js +0 -495
- package/dist/esm/common/storage/local-storage.test.js +0 -12
- package/dist/esm/common/timer/interaction-timer.component-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 -34
- package/dist/esm/common/url/clean-url.test.js +0 -7
- package/dist/esm/common/url/encode.component-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.component-test.js +0 -13
- package/dist/esm/common/util/console.test.js +0 -28
- package/dist/esm/common/util/data-size.test.js +0 -60
- package/dist/esm/common/util/feature-flags.test.js +0 -80
- package/dist/esm/common/util/get-or-set.test.js +0 -45
- package/dist/esm/common/util/global-scope.js +0 -17
- package/dist/esm/common/util/global-scope.test.js +0 -70
- 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/obfuscate.component-test.js +0 -125
- package/dist/esm/common/util/stringify.test.js +0 -46
- package/dist/esm/common/util/submit-data.test.js +0 -241
- 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/jserrors/instrument/debug.js +0 -38
- 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/session_replay/aggregate/index.component-test.js +0 -453
- package/dist/esm/features/spa/aggregate/interaction-node.test.js +0 -14
- package/dist/esm/features/utils/agent-session.test.js +0 -207
- package/dist/esm/features/utils/aggregate-base.test.js +0 -108
- package/dist/esm/features/utils/feature-base.test.js +0 -40
- package/dist/esm/features/utils/handler-cache.test.js +0 -51
- package/dist/esm/features/utils/instrument-base.test.js +0 -175
- package/dist/esm/features/utils/lazy-feature-loader.test.js +0 -29
- 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/harvest/harvest-scheduler.component-test.d.ts +0 -2
- package/dist/types/common/harvest/harvest-scheduler.component-test.d.ts.map +0 -1
- package/dist/types/common/harvest/harvest.component-test.d.ts +0 -2
- package/dist/types/common/harvest/harvest.component-test.d.ts.map +0 -1
- package/dist/types/common/session/session-entity.component-test.d.ts +0 -2
- package/dist/types/common/session/session-entity.component-test.d.ts.map +0 -1
- package/dist/types/common/timer/interaction-timer.component-test.d.ts +0 -2
- package/dist/types/common/timer/interaction-timer.component-test.d.ts.map +0 -1
- package/dist/types/common/url/encode.component-test.d.ts +0 -2
- package/dist/types/common/url/encode.component-test.d.ts.map +0 -1
- package/dist/types/common/url/protocol.component-test.d.ts +0 -2
- package/dist/types/common/url/protocol.component-test.d.ts.map +0 -1
- package/dist/types/common/util/global-scope.d.ts +0 -5
- package/dist/types/common/util/global-scope.d.ts.map +0 -1
- package/dist/types/common/util/obfuscate.component-test.d.ts +0 -2
- package/dist/types/common/util/obfuscate.component-test.d.ts.map +0 -1
- package/dist/types/features/jserrors/instrument/debug.d.ts +0 -2
- package/dist/types/features/jserrors/instrument/debug.d.ts.map +0 -1
- package/dist/types/features/session_replay/aggregate/index.component-test.d.ts +0 -2
- package/dist/types/features/session_replay/aggregate/index.component-test.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/harvest/harvest-scheduler.component-test.js +0 -25
- package/src/common/harvest/harvest.component-test.js +0 -169
- package/src/common/util/global-scope.js +0 -23
- package/src/common/util/global-scope.test.js +0 -87
- package/src/features/jserrors/instrument/debug.js +0 -36
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
afterEach(() => {
|
|
2
|
-
jest.resetModules();
|
|
3
|
-
jest.clearAllMocks();
|
|
4
|
-
});
|
|
5
|
-
const urlTests = [{
|
|
6
|
-
input: 'http://example.com/path/name?qs=5&a=b',
|
|
7
|
-
expected: {
|
|
8
|
-
hostname: 'example.com',
|
|
9
|
-
pathname: '/path/name',
|
|
10
|
-
protocol: 'http',
|
|
11
|
-
port: '80',
|
|
12
|
-
sameOrigin: false
|
|
13
|
-
}
|
|
14
|
-
}, {
|
|
15
|
-
input: 'http://foo:bar@example.com:8080/path/@name?qs=5&a=b',
|
|
16
|
-
expected: {
|
|
17
|
-
hostname: 'example.com',
|
|
18
|
-
pathname: '/path/@name',
|
|
19
|
-
protocol: 'http',
|
|
20
|
-
port: '8080',
|
|
21
|
-
sameOrigin: false
|
|
22
|
-
}
|
|
23
|
-
}, {
|
|
24
|
-
input: 'https://foo:bar@example.com/path/name?qs=5&a=b',
|
|
25
|
-
expected: {
|
|
26
|
-
hostname: 'example.com',
|
|
27
|
-
pathname: '/path/name',
|
|
28
|
-
protocol: 'https',
|
|
29
|
-
port: '443',
|
|
30
|
-
sameOrigin: false
|
|
31
|
-
}
|
|
32
|
-
}, {
|
|
33
|
-
input: '/path/name?qs=5&a=b',
|
|
34
|
-
expected: {
|
|
35
|
-
hostname: location.hostname,
|
|
36
|
-
pathname: '/path/name',
|
|
37
|
-
protocol: location.protocol.split(':')[0],
|
|
38
|
-
port: '80',
|
|
39
|
-
sameOrigin: true
|
|
40
|
-
}
|
|
41
|
-
}, {
|
|
42
|
-
input: location.protocol + '//' + location.hostname + ':' + location.port + '/path/name?qs=5&a=b',
|
|
43
|
-
expected: {
|
|
44
|
-
hostname: location.hostname,
|
|
45
|
-
pathname: '/path/name',
|
|
46
|
-
protocol: location.protocol.split(':')[0],
|
|
47
|
-
port: '80',
|
|
48
|
-
sameOrigin: true
|
|
49
|
-
}
|
|
50
|
-
}, {
|
|
51
|
-
input: 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==',
|
|
52
|
-
expected: {
|
|
53
|
-
protocol: 'data'
|
|
54
|
-
}
|
|
55
|
-
}];
|
|
56
|
-
test.each(urlTests)('verify url parsing inside browser scope', async _ref => {
|
|
57
|
-
let {
|
|
58
|
-
input,
|
|
59
|
-
expected
|
|
60
|
-
} = _ref;
|
|
61
|
-
jest.doMock('../util/global-scope', () => ({
|
|
62
|
-
__esModule: true,
|
|
63
|
-
isBrowserScope: true,
|
|
64
|
-
globalScope: global
|
|
65
|
-
}));
|
|
66
|
-
const {
|
|
67
|
-
parseUrl
|
|
68
|
-
} = await import('./parse-url');
|
|
69
|
-
expect(parseUrl(input)).toEqual(expected);
|
|
70
|
-
});
|
|
71
|
-
test.each(urlTests)('verify url parsing outside browser scope', async _ref2 => {
|
|
72
|
-
let {
|
|
73
|
-
input,
|
|
74
|
-
expected
|
|
75
|
-
} = _ref2;
|
|
76
|
-
jest.doMock('../util/global-scope', () => ({
|
|
77
|
-
__esModule: true,
|
|
78
|
-
isBrowserScope: false,
|
|
79
|
-
globalScope: global
|
|
80
|
-
}));
|
|
81
|
-
const {
|
|
82
|
-
parseUrl
|
|
83
|
-
} = await import('./parse-url');
|
|
84
|
-
expect(parseUrl(input)).toEqual(expected);
|
|
85
|
-
});
|
|
86
|
-
test('should cache parsed urls', async () => {
|
|
87
|
-
jest.doMock('../util/global-scope', () => ({
|
|
88
|
-
__esModule: true,
|
|
89
|
-
isBrowserScope: true,
|
|
90
|
-
globalScope: global
|
|
91
|
-
}));
|
|
92
|
-
const input = 'http://example.com/';
|
|
93
|
-
const expected = {
|
|
94
|
-
hostname: 'example.com',
|
|
95
|
-
pathname: '/',
|
|
96
|
-
protocol: 'http',
|
|
97
|
-
port: '80',
|
|
98
|
-
sameOrigin: false
|
|
99
|
-
};
|
|
100
|
-
jest.spyOn(document, 'createElement');
|
|
101
|
-
const {
|
|
102
|
-
parseUrl
|
|
103
|
-
} = await import('./parse-url');
|
|
104
|
-
parseUrl(input);
|
|
105
|
-
expect(parseUrl(input)).toEqual(expected);
|
|
106
|
-
expect(document.createElement).toHaveBeenCalledTimes(1);
|
|
107
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { isFileProtocol } from './protocol';
|
|
2
|
-
test('should return true when location url contains file protocol', () => {
|
|
3
|
-
jest.spyOn(window, 'location', 'get').mockReturnValue({
|
|
4
|
-
protocol: 'file:'
|
|
5
|
-
});
|
|
6
|
-
expect(isFileProtocol()).toEqual(true);
|
|
7
|
-
});
|
|
8
|
-
test('should return false when location url does not contains file protocol', () => {
|
|
9
|
-
jest.spyOn(window, 'location', 'get').mockReturnValue({
|
|
10
|
-
protocol: 'http:'
|
|
11
|
-
});
|
|
12
|
-
expect(isFileProtocol()).toEqual(false);
|
|
13
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { warn } from './console';
|
|
2
|
-
beforeEach(() => {
|
|
3
|
-
console.warn = jest.fn();
|
|
4
|
-
});
|
|
5
|
-
afterEach(() => {
|
|
6
|
-
jest.restoreAllMocks();
|
|
7
|
-
});
|
|
8
|
-
describe('warn', () => {
|
|
9
|
-
test('should not call console.warn if it is not a function', () => {
|
|
10
|
-
const spy = jest.spyOn(console, 'warn');
|
|
11
|
-
console.warn = undefined;
|
|
12
|
-
warn('test message');
|
|
13
|
-
expect(spy).not.toHaveBeenCalled();
|
|
14
|
-
});
|
|
15
|
-
test('should call console.warn with a prefixed message', () => {
|
|
16
|
-
warn('test message');
|
|
17
|
-
expect(console.warn).toHaveBeenCalledWith('New Relic: test message');
|
|
18
|
-
});
|
|
19
|
-
test('should call console.warn with secondary argument if provided', () => {
|
|
20
|
-
const secondary = 'secondary value';
|
|
21
|
-
warn('test message', secondary);
|
|
22
|
-
expect(console.warn).toHaveBeenCalledWith(secondary);
|
|
23
|
-
});
|
|
24
|
-
test('should not call console.warn with secondary argument if not provided', () => {
|
|
25
|
-
warn('test message');
|
|
26
|
-
expect(console.warn).toHaveBeenCalledTimes(1);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { faker } from '@faker-js/faker';
|
|
2
|
-
import * as stringifyModule from './stringify';
|
|
3
|
-
import { dataSize } from './data-size';
|
|
4
|
-
jest.mock('./stringify');
|
|
5
|
-
describe('dataSize', () => {
|
|
6
|
-
test('returns length of string', () => {
|
|
7
|
-
const str = faker.lorem.sentence();
|
|
8
|
-
expect(dataSize(str)).toBe(str.length);
|
|
9
|
-
});
|
|
10
|
-
test('returns undefined for non-object, number, or empty string', () => {
|
|
11
|
-
expect(dataSize(Infinity)).toBeUndefined();
|
|
12
|
-
expect(dataSize(NaN)).toBeUndefined();
|
|
13
|
-
expect(dataSize(12345)).toBeUndefined();
|
|
14
|
-
expect(dataSize('')).toBeUndefined();
|
|
15
|
-
});
|
|
16
|
-
test('returns byte length of ArrayBuffer object', () => {
|
|
17
|
-
const buffer = new ArrayBuffer(faker.datatype.number({
|
|
18
|
-
min: 10,
|
|
19
|
-
max: 100
|
|
20
|
-
}));
|
|
21
|
-
expect(dataSize(buffer)).toBe(buffer.byteLength);
|
|
22
|
-
});
|
|
23
|
-
test('returns size of Blob object', () => {
|
|
24
|
-
const blob = new Blob([faker.lorem.sentence()], {
|
|
25
|
-
type: 'text/plain'
|
|
26
|
-
});
|
|
27
|
-
expect(dataSize(blob)).toBe(blob.size);
|
|
28
|
-
});
|
|
29
|
-
test('returns undefined for FormData object', () => {
|
|
30
|
-
const formData = new FormData();
|
|
31
|
-
expect(dataSize(formData)).toBeUndefined();
|
|
32
|
-
});
|
|
33
|
-
test('uses stringify to get the length of an object', () => {
|
|
34
|
-
const input = {
|
|
35
|
-
[faker.datatype.uuid()]: faker.lorem.sentence()
|
|
36
|
-
};
|
|
37
|
-
const expectedSize = faker.datatype.number({
|
|
38
|
-
min: 1000,
|
|
39
|
-
max: 10000
|
|
40
|
-
});
|
|
41
|
-
jest.spyOn(stringifyModule, 'stringify').mockReturnValue({
|
|
42
|
-
length: expectedSize
|
|
43
|
-
});
|
|
44
|
-
expect(dataSize(input)).toBe(expectedSize);
|
|
45
|
-
});
|
|
46
|
-
test('should not throw an exception if stringify throws an exception', () => {
|
|
47
|
-
const input = {
|
|
48
|
-
[faker.datatype.uuid()]: faker.lorem.sentence()
|
|
49
|
-
};
|
|
50
|
-
const expectedSize = faker.datatype.number({
|
|
51
|
-
min: 1000,
|
|
52
|
-
max: 10000
|
|
53
|
-
});
|
|
54
|
-
jest.spyOn(stringifyModule, 'stringify').mockImplementation(() => {
|
|
55
|
-
throw new Error(faker.lorem.sentence());
|
|
56
|
-
});
|
|
57
|
-
expect(() => dataSize(input)).not.toThrow();
|
|
58
|
-
expect(dataSize(input)).toBeUndefined();
|
|
59
|
-
});
|
|
60
|
-
});
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { faker } from '@faker-js/faker';
|
|
2
|
-
import * as eventEmitterModule from '../event-emitter/contextual-ee';
|
|
3
|
-
import * as handleModule from '../event-emitter/handle';
|
|
4
|
-
import * as drainModule from '../drain/drain';
|
|
5
|
-
import { activateFeatures, activatedFeatures } from './feature-flags';
|
|
6
|
-
import { FEATURE_NAMES } from '../../loaders/features/features';
|
|
7
|
-
jest.mock('../event-emitter/handle');
|
|
8
|
-
jest.mock('../drain/drain');
|
|
9
|
-
jest.mock('../event-emitter/contextual-ee', () => ({
|
|
10
|
-
__esModule: true,
|
|
11
|
-
ee: {
|
|
12
|
-
get: jest.fn(() => ({
|
|
13
|
-
foo: "bar_".concat(Math.random())
|
|
14
|
-
}))
|
|
15
|
-
}
|
|
16
|
-
}));
|
|
17
|
-
let agentIdentifier;
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
agentIdentifier = faker.datatype.uuid();
|
|
20
|
-
});
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
Object.keys(activatedFeatures).forEach(key => delete activatedFeatures[key]);
|
|
23
|
-
});
|
|
24
|
-
test.each([null, undefined])('should not do anything when flags is %s', input => {
|
|
25
|
-
activateFeatures(input, agentIdentifier);
|
|
26
|
-
expect(handleModule.handle).not.toHaveBeenCalled();
|
|
27
|
-
expect(drainModule.drain).not.toHaveBeenCalled();
|
|
28
|
-
expect(activatedFeatures).toEqual({});
|
|
29
|
-
});
|
|
30
|
-
const bucketMap = {
|
|
31
|
-
stn: [FEATURE_NAMES.sessionTrace],
|
|
32
|
-
err: [FEATURE_NAMES.jserrors, FEATURE_NAMES.metrics],
|
|
33
|
-
ins: [FEATURE_NAMES.pageAction],
|
|
34
|
-
spa: [FEATURE_NAMES.spa],
|
|
35
|
-
sr: [FEATURE_NAMES.sessionReplay, FEATURE_NAMES.sessionTrace]
|
|
36
|
-
};
|
|
37
|
-
test('emits the right events when feature flag = 1', () => {
|
|
38
|
-
const flags = {};
|
|
39
|
-
Object.keys(bucketMap).forEach(flag => flags[flag] = 1);
|
|
40
|
-
activateFeatures(flags, agentIdentifier);
|
|
41
|
-
const sharedEE = jest.mocked(eventEmitterModule.ee.get).mock.results[0].value;
|
|
42
|
-
|
|
43
|
-
// each flag gets emitted to each of its mapped features, and a feat- AND a rumresp- for every emit, so (1+2+1+1+2)*2 = 14
|
|
44
|
-
expect(handleModule.handle).toHaveBeenCalledTimes(14);
|
|
45
|
-
expect(handleModule.handle).toHaveBeenNthCalledWith(1, 'feat-stn', [], undefined, FEATURE_NAMES.sessionTrace, sharedEE);
|
|
46
|
-
expect(handleModule.handle).toHaveBeenLastCalledWith('rumresp-sr', [true], undefined, FEATURE_NAMES.sessionTrace, sharedEE);
|
|
47
|
-
expect(drainModule.drain).toHaveBeenCalledWith(agentIdentifier, 'page_view_event');
|
|
48
|
-
Object.keys(flags).forEach(flag => flags[flag] = true);
|
|
49
|
-
expect(activatedFeatures).toEqual(flags);
|
|
50
|
-
});
|
|
51
|
-
test('emits the right events when feature flag = 0', () => {
|
|
52
|
-
const flags = {};
|
|
53
|
-
Object.keys(bucketMap).forEach(flag => flags[flag] = 0);
|
|
54
|
-
activateFeatures(flags, agentIdentifier);
|
|
55
|
-
const sharedEE = jest.mocked(eventEmitterModule.ee.get).mock.results[0].value;
|
|
56
|
-
|
|
57
|
-
// each flag gets emitted to each of its mapped features, and a block- AND a rumresp- for every emit, so (1+2+1+1+2)*2 = 14
|
|
58
|
-
expect(handleModule.handle).toHaveBeenCalledTimes(14);
|
|
59
|
-
expect(handleModule.handle).toHaveBeenNthCalledWith(1, 'block-stn', [], undefined, FEATURE_NAMES.sessionTrace, sharedEE);
|
|
60
|
-
expect(handleModule.handle).toHaveBeenLastCalledWith('rumresp-sr', [false], undefined, FEATURE_NAMES.sessionTrace, sharedEE);
|
|
61
|
-
expect(drainModule.drain).toHaveBeenCalledWith(agentIdentifier, 'page_view_event');
|
|
62
|
-
Object.keys(flags).forEach(flag => flags[flag] = false);
|
|
63
|
-
expect(activatedFeatures).toEqual(flags);
|
|
64
|
-
});
|
|
65
|
-
test('only the first activate of the same feature is respected', () => {
|
|
66
|
-
const flags = {
|
|
67
|
-
stn: 1
|
|
68
|
-
};
|
|
69
|
-
activateFeatures(flags, agentIdentifier);
|
|
70
|
-
flags.stn = 0;
|
|
71
|
-
activateFeatures(flags, agentIdentifier);
|
|
72
|
-
const sharedEE1 = jest.mocked(eventEmitterModule.ee.get).mock.results[0].value;
|
|
73
|
-
const sharedEE2 = jest.mocked(eventEmitterModule.ee.get).mock.results[1].value;
|
|
74
|
-
expect(handleModule.handle).toHaveBeenNthCalledWith(1, 'feat-stn', [], undefined, 'session_trace', sharedEE1);
|
|
75
|
-
expect(handleModule.handle).toHaveBeenNthCalledWith(2, 'rumresp-stn', [true], undefined, 'session_trace', sharedEE1);
|
|
76
|
-
expect(handleModule.handle).not.toHaveBeenNthCalledWith(1, 'feat-stn', [], undefined, 'session_trace', sharedEE2);
|
|
77
|
-
expect(drainModule.drain).toHaveBeenCalledWith(agentIdentifier, 'page_view_event');
|
|
78
|
-
expect(drainModule.drain).toHaveBeenCalledTimes(2);
|
|
79
|
-
expect(activatedFeatures.stn).toBeTruthy();
|
|
80
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { getOrSet } from './get-or-set';
|
|
2
|
-
test('should return the current value of an existing property', () => {
|
|
3
|
-
const obj = {
|
|
4
|
-
foo: 'bar'
|
|
5
|
-
};
|
|
6
|
-
const prop = 'foo';
|
|
7
|
-
const getVal = jest.fn();
|
|
8
|
-
const result = getOrSet(obj, prop, getVal);
|
|
9
|
-
expect(result).toBe('bar');
|
|
10
|
-
expect(getVal).not.toHaveBeenCalled();
|
|
11
|
-
});
|
|
12
|
-
test('should set and return the value from getVal if the property does not exist', () => {
|
|
13
|
-
const obj = {};
|
|
14
|
-
const prop = 'foo';
|
|
15
|
-
const getVal = jest.fn().mockReturnValue('baz');
|
|
16
|
-
const result = getOrSet(obj, prop, getVal);
|
|
17
|
-
expect(result).toBe('baz');
|
|
18
|
-
expect(getVal).toHaveBeenCalled();
|
|
19
|
-
expect(obj.foo).toBe('baz');
|
|
20
|
-
});
|
|
21
|
-
test('should set the property as non-enumerable if Object.defineProperty is supported', () => {
|
|
22
|
-
const obj = {};
|
|
23
|
-
const prop = 'foo';
|
|
24
|
-
const getVal = jest.fn().mockReturnValue('baz');
|
|
25
|
-
jest.spyOn(Object, 'defineProperty');
|
|
26
|
-
const result = getOrSet(obj, prop, getVal);
|
|
27
|
-
expect(result).toBe('baz');
|
|
28
|
-
expect(Object.defineProperty).toHaveBeenCalledWith(obj, prop, {
|
|
29
|
-
value: 'baz',
|
|
30
|
-
writable: true,
|
|
31
|
-
enumerable: false
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
test('should set the property from getVal if Object.defineProperty and Object.keys are not supported', () => {
|
|
35
|
-
const obj = {};
|
|
36
|
-
const prop = 'foo';
|
|
37
|
-
const getVal = jest.fn(() => 'baz');
|
|
38
|
-
const originalFn = Object.defineProperty;
|
|
39
|
-
Object.defineProperty = null;
|
|
40
|
-
const result = getOrSet(obj, prop, getVal);
|
|
41
|
-
expect(result).toBe('baz');
|
|
42
|
-
expect(obj.foo).toBe('baz');
|
|
43
|
-
expect(Object.prototype.propertyIsEnumerable.call(obj, 'foo')).toBe(true);
|
|
44
|
-
Object.defineProperty = originalFn;
|
|
45
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/* global globalThis, WorkerGlobalScope, WorkerNavigator */
|
|
2
|
-
|
|
3
|
-
export const isBrowserScope = Boolean(typeof window !== 'undefined' && window.document);
|
|
4
|
-
export const isWorkerScope = Boolean(typeof WorkerGlobalScope !== 'undefined' && self.navigator instanceof WorkerNavigator);
|
|
5
|
-
export let globalScope = (() => {
|
|
6
|
-
if (isBrowserScope) {
|
|
7
|
-
return window;
|
|
8
|
-
} else if (isWorkerScope) {
|
|
9
|
-
if (typeof globalThis !== 'undefined' && globalThis instanceof WorkerGlobalScope) {
|
|
10
|
-
return globalThis;
|
|
11
|
-
} else if (self instanceof WorkerGlobalScope) {
|
|
12
|
-
return self;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
throw new Error('New Relic browser agent shutting down due to error: Unable to locate global scope. This is possibly due to code redefining browser global variables like "self" and "window".');
|
|
16
|
-
})();
|
|
17
|
-
export const initialLocation = '' + globalScope.location;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
The global-scope module contains exports that are defined once at the time
|
|
3
|
-
of importing the module. For this reason, the module must be dynamically
|
|
4
|
-
imported in each test case.
|
|
5
|
-
|
|
6
|
-
A scope must always exist or importing the module will throw an error. Use
|
|
7
|
-
`enableWorkerScope` to enable the worker scope. Be sure to call `disableWorkerScope`
|
|
8
|
-
before any calls to `expect` or the test will fail with an error from Jest.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { faker } from '@faker-js/faker';
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
jest.restoreAllMocks();
|
|
14
|
-
jest.resetModules();
|
|
15
|
-
});
|
|
16
|
-
test('should indicate a browser scope', async () => {
|
|
17
|
-
jest.spyOn(global, 'window', 'get').mockReturnValue({
|
|
18
|
-
document: {}
|
|
19
|
-
});
|
|
20
|
-
const globalScopeModule = await import('./global-scope');
|
|
21
|
-
expect(globalScopeModule.isBrowserScope).toBe(true);
|
|
22
|
-
expect(globalScopeModule.isWorkerScope).toBe(false);
|
|
23
|
-
expect(globalScopeModule.globalScope).toBe(global.window);
|
|
24
|
-
});
|
|
25
|
-
test('should indicate a worker scope', async () => {
|
|
26
|
-
enableWorkerScope();
|
|
27
|
-
const globalScopeModule = await import('./global-scope');
|
|
28
|
-
const mockedGlobalThis = global.globalThis;
|
|
29
|
-
disableWorkerScope();
|
|
30
|
-
expect(globalScopeModule.isBrowserScope).toBe(false);
|
|
31
|
-
expect(globalScopeModule.isWorkerScope).toBe(true);
|
|
32
|
-
expect(globalScopeModule.globalScope).toBe(mockedGlobalThis);
|
|
33
|
-
});
|
|
34
|
-
test('should return the self global', async () => {
|
|
35
|
-
enableWorkerScope();
|
|
36
|
-
jest.replaceProperty(global, 'globalThis', null);
|
|
37
|
-
jest.spyOn(global, 'self', 'get').mockReturnValue(new global.WorkerGlobalScope());
|
|
38
|
-
const globalScopeModule = await import('./global-scope');
|
|
39
|
-
const mockedGlobalSelf = global.self;
|
|
40
|
-
disableWorkerScope();
|
|
41
|
-
expect(globalScopeModule.isBrowserScope).toBe(false);
|
|
42
|
-
expect(globalScopeModule.isWorkerScope).toBe(true);
|
|
43
|
-
expect(globalScopeModule.globalScope).toBe(mockedGlobalSelf);
|
|
44
|
-
});
|
|
45
|
-
test('should throw an error when a scope cannot be defined', async () => {
|
|
46
|
-
jest.spyOn(global, 'window', 'get').mockReturnValue(undefined);
|
|
47
|
-
await expect(() => import('./global-scope')).rejects.toThrow();
|
|
48
|
-
});
|
|
49
|
-
test('should immediately store the current location', async () => {
|
|
50
|
-
const url = faker.internet.url();
|
|
51
|
-
jest.spyOn(window, 'location', 'get').mockReturnValue(url);
|
|
52
|
-
const globalScopeModule = await import('./global-scope');
|
|
53
|
-
expect(globalScopeModule.initialLocation).toBe(url);
|
|
54
|
-
});
|
|
55
|
-
function enableWorkerScope() {
|
|
56
|
-
jest.spyOn(global, 'window', 'get').mockReturnValue(undefined);
|
|
57
|
-
class WorkerNavigator {}
|
|
58
|
-
class WorkerGlobalScope {
|
|
59
|
-
navigator = new WorkerNavigator();
|
|
60
|
-
}
|
|
61
|
-
global.WorkerGlobalScope = WorkerGlobalScope;
|
|
62
|
-
global.WorkerNavigator = WorkerNavigator;
|
|
63
|
-
jest.spyOn(global, 'navigator', 'get').mockReturnValue(new global.WorkerNavigator());
|
|
64
|
-
jest.replaceProperty(global, 'globalThis', new WorkerGlobalScope());
|
|
65
|
-
}
|
|
66
|
-
function disableWorkerScope() {
|
|
67
|
-
delete global.WorkerGlobalScope;
|
|
68
|
-
delete global.WorkerNavigator;
|
|
69
|
-
jest.restoreAllMocks();
|
|
70
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { debounce, single } from './invoke';
|
|
2
|
-
jest.useFakeTimers();
|
|
3
|
-
describe('debounce', () => {
|
|
4
|
-
test('should run the supplied function after 100ms', () => {
|
|
5
|
-
let mockCallback = jest.fn();
|
|
6
|
-
let debouncedMethod = debounce(mockCallback, 100);
|
|
7
|
-
execFnTimes(debouncedMethod, 100);
|
|
8
|
-
expect(mockCallback).not.toHaveBeenCalled();
|
|
9
|
-
jest.advanceTimersByTime(1000);
|
|
10
|
-
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
11
|
-
});
|
|
12
|
-
test('should rerun the supplied function when called again after 100ms', () => {
|
|
13
|
-
let mockCallback = jest.fn();
|
|
14
|
-
let debouncedMethod = debounce(mockCallback, 100);
|
|
15
|
-
execFnTimes(debouncedMethod, 100);
|
|
16
|
-
jest.advanceTimersByTime(200);
|
|
17
|
-
execFnTimes(debouncedMethod, 100);
|
|
18
|
-
jest.advanceTimersByTime(2000);
|
|
19
|
-
expect(mockCallback).toHaveBeenCalledTimes(2);
|
|
20
|
-
});
|
|
21
|
-
test('should run the supplied function on the first event and debounce subsequent events', () => {
|
|
22
|
-
let mockCallback = jest.fn();
|
|
23
|
-
let debouncedMethod = debounce(mockCallback, 100, {
|
|
24
|
-
leading: true
|
|
25
|
-
});
|
|
26
|
-
execFnTimes(debouncedMethod, 100);
|
|
27
|
-
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
28
|
-
jest.advanceTimersByTime(200);
|
|
29
|
-
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
30
|
-
execFnTimes(debouncedMethod, 100);
|
|
31
|
-
jest.advanceTimersByTime(200);
|
|
32
|
-
expect(mockCallback).toHaveBeenCalledTimes(2);
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
describe('single', () => {
|
|
36
|
-
test('should run the supplied function only once', () => {
|
|
37
|
-
let mockCallback = jest.fn();
|
|
38
|
-
let singleMethod = single(mockCallback, 100);
|
|
39
|
-
execFnTimes(singleMethod, 100);
|
|
40
|
-
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
function execFnTimes(fn, count) {
|
|
44
|
-
for (let i = 0; i < count; i++) {
|
|
45
|
-
fn();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { mapOwn } from './map-own';
|
|
2
|
-
test('enumerates the object properties', () => {
|
|
3
|
-
const callback = jest.fn();
|
|
4
|
-
const input = {
|
|
5
|
-
foo: 'bar'
|
|
6
|
-
};
|
|
7
|
-
mapOwn(input, callback);
|
|
8
|
-
expect(callback).toHaveBeenCalledWith('foo', 'bar');
|
|
9
|
-
});
|
|
10
|
-
test('return array of results from callback invocation', () => {
|
|
11
|
-
const callback = jest.fn((key, value) => "".concat(key, ":").concat(value));
|
|
12
|
-
const input = {
|
|
13
|
-
foo: 'bar',
|
|
14
|
-
biz: 'baz'
|
|
15
|
-
};
|
|
16
|
-
const result = mapOwn(input, callback);
|
|
17
|
-
expect(result.length).toEqual(2);
|
|
18
|
-
expect(result).toContain('foo:bar');
|
|
19
|
-
expect(result).toContain('biz:baz');
|
|
20
|
-
});
|
|
21
|
-
test('does not iterate symbol properties', () => {
|
|
22
|
-
const callback = jest.fn((key, value) => "".concat(key, ":").concat(value));
|
|
23
|
-
const input = {
|
|
24
|
-
foo: 'bar',
|
|
25
|
-
[Symbol.for('biz')]: 'baz'
|
|
26
|
-
};
|
|
27
|
-
const result = mapOwn(input, callback);
|
|
28
|
-
expect(result.length).toEqual(1);
|
|
29
|
-
});
|
|
30
|
-
test('does not iterate inherited properties', () => {
|
|
31
|
-
function F() {}
|
|
32
|
-
F.prototype = {
|
|
33
|
-
biz: 'baz'
|
|
34
|
-
};
|
|
35
|
-
const callback = jest.fn((key, value) => "".concat(key, ":").concat(value));
|
|
36
|
-
const input = new F();
|
|
37
|
-
input.foo = 'bar';
|
|
38
|
-
const result = mapOwn(input, callback);
|
|
39
|
-
expect(result.length).toEqual(1);
|
|
40
|
-
});
|
|
41
|
-
test.each([null, undefined])('returns empty array when passed object is null or undefined', input => {
|
|
42
|
-
const callback = jest.fn();
|
|
43
|
-
const result = mapOwn(input, callback);
|
|
44
|
-
expect(Array.isArray(result)).toEqual(true);
|
|
45
|
-
expect(result.length).toEqual(0);
|
|
46
|
-
expect(callback).toHaveBeenCalledTimes(0);
|
|
47
|
-
});
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import { faker } from '@faker-js/faker';
|
|
2
|
-
import * as configModule from '../config/config';
|
|
3
|
-
import * as urlProtocolModule from '../url/protocol';
|
|
4
|
-
import * as consolModule from './console';
|
|
5
|
-
import * as obfuscateModule from './obfuscate';
|
|
6
|
-
jest.mock('../config/config');
|
|
7
|
-
jest.mock('../context/shared-context');
|
|
8
|
-
jest.mock('../url/protocol');
|
|
9
|
-
jest.mock('./console');
|
|
10
|
-
let agentIdentifier;
|
|
11
|
-
const rules = [{
|
|
12
|
-
regex: /pii/g,
|
|
13
|
-
replacement: 'OBFUSCATED'
|
|
14
|
-
}];
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
agentIdentifier = faker.datatype.uuid();
|
|
17
|
-
});
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
jest.resetAllMocks();
|
|
20
|
-
});
|
|
21
|
-
describe('Obfuscator', () => {
|
|
22
|
-
test('shouldObfuscate returns true when there are rules', () => {
|
|
23
|
-
jest.spyOn(configModule, 'getConfigurationValue').mockReturnValue(rules);
|
|
24
|
-
const obfuscator = new obfuscateModule.Obfuscator();
|
|
25
|
-
obfuscator.sharedContext = {
|
|
26
|
-
agentIdentifier
|
|
27
|
-
};
|
|
28
|
-
expect(obfuscator.shouldObfuscate()).toEqual(true);
|
|
29
|
-
});
|
|
30
|
-
test('shouldObfuscate returns false when there are no rules', () => {
|
|
31
|
-
jest.spyOn(configModule, 'getConfigurationValue').mockReturnValue([]);
|
|
32
|
-
const obfuscator = new obfuscateModule.Obfuscator();
|
|
33
|
-
obfuscator.sharedContext = {
|
|
34
|
-
agentIdentifier
|
|
35
|
-
};
|
|
36
|
-
expect(obfuscator.shouldObfuscate()).toEqual(false);
|
|
37
|
-
});
|
|
38
|
-
test('obfuscateString returns the input when there are no rules', () => {
|
|
39
|
-
jest.spyOn(configModule, 'getConfigurationValue').mockReturnValue([]);
|
|
40
|
-
const input = faker.lorem.sentence();
|
|
41
|
-
const obfuscator = new obfuscateModule.Obfuscator();
|
|
42
|
-
obfuscator.sharedContext = {
|
|
43
|
-
agentIdentifier
|
|
44
|
-
};
|
|
45
|
-
expect(obfuscator.obfuscateString(input)).toEqual(input);
|
|
46
|
-
});
|
|
47
|
-
test('obfuscateString applies obfuscation rules to input', () => {
|
|
48
|
-
jest.spyOn(configModule, 'getConfigurationValue').mockReturnValue(rules);
|
|
49
|
-
const input = 'pii';
|
|
50
|
-
const obfuscator = new obfuscateModule.Obfuscator();
|
|
51
|
-
obfuscator.sharedContext = {
|
|
52
|
-
agentIdentifier
|
|
53
|
-
};
|
|
54
|
-
expect(obfuscator.obfuscateString(input)).toEqual(rules[0].replacement);
|
|
55
|
-
});
|
|
56
|
-
test('obfuscateString replaces input with * when replacement is not set', () => {
|
|
57
|
-
const newRules = [{
|
|
58
|
-
regex: rules[0].regex
|
|
59
|
-
}];
|
|
60
|
-
jest.spyOn(configModule, 'getConfigurationValue').mockReturnValue(newRules);
|
|
61
|
-
const input = 'pii';
|
|
62
|
-
const obfuscator = new obfuscateModule.Obfuscator();
|
|
63
|
-
obfuscator.sharedContext = {
|
|
64
|
-
agentIdentifier
|
|
65
|
-
};
|
|
66
|
-
expect(obfuscator.obfuscateString(input)).toEqual('*');
|
|
67
|
-
});
|
|
68
|
-
test.each([null, undefined, '', 123])('obfuscateString returns the input it is %s', input => {
|
|
69
|
-
jest.spyOn(configModule, 'getConfigurationValue').mockReturnValue(rules);
|
|
70
|
-
const obfuscator = new obfuscateModule.Obfuscator();
|
|
71
|
-
obfuscator.sharedContext = {
|
|
72
|
-
agentIdentifier
|
|
73
|
-
};
|
|
74
|
-
expect(obfuscator.obfuscateString(input)).toEqual(input);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
describe('getRules', () => {
|
|
78
|
-
test('should return configured rules', () => {
|
|
79
|
-
jest.spyOn(configModule, 'getConfigurationValue').mockReturnValue(rules);
|
|
80
|
-
expect(obfuscateModule.getRules()).toEqual(rules);
|
|
81
|
-
});
|
|
82
|
-
test('should include the file protocol obfuscation', () => {
|
|
83
|
-
jest.spyOn(configModule, 'getConfigurationValue').mockReturnValue(rules);
|
|
84
|
-
jest.spyOn(urlProtocolModule, 'isFileProtocol').mockReturnValue(rules);
|
|
85
|
-
expect(obfuscateModule.getRules()).toEqual(expect.arrayContaining([{
|
|
86
|
-
regex: /^file:\/\/(.*)/,
|
|
87
|
-
replacement: 'file://OBFUSCATED'
|
|
88
|
-
}]));
|
|
89
|
-
});
|
|
90
|
-
test.each([null, undefined])('should return an empty array when obfuscation rules are %s', input => {
|
|
91
|
-
jest.spyOn(configModule, 'getConfigurationValue').mockReturnValue(input);
|
|
92
|
-
expect(obfuscateModule.getRules()).toEqual([]);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
describe('validateRules', () => {
|
|
96
|
-
test('should return true for empty array', () => {
|
|
97
|
-
expect(obfuscateModule.validateRules([])).toEqual(true);
|
|
98
|
-
});
|
|
99
|
-
test('should return true for valid rules', () => {
|
|
100
|
-
expect(obfuscateModule.validateRules(rules)).toEqual(true);
|
|
101
|
-
});
|
|
102
|
-
test.each([null, 123, {}, []])('should warn about an invalid regex type %s', input => {
|
|
103
|
-
const newRules = [{
|
|
104
|
-
regex: input,
|
|
105
|
-
replacement: rules[0].replacement
|
|
106
|
-
}];
|
|
107
|
-
expect(obfuscateModule.validateRules(newRules)).toEqual(false);
|
|
108
|
-
expect(consolModule.warn).toHaveBeenCalledWith(expect.stringContaining('contains a "regex" value with an invalid type'));
|
|
109
|
-
});
|
|
110
|
-
test('should warn about a missing regex with value', () => {
|
|
111
|
-
const newRules = [{
|
|
112
|
-
replacement: rules[0].replacement
|
|
113
|
-
}];
|
|
114
|
-
expect(obfuscateModule.validateRules(newRules)).toEqual(false);
|
|
115
|
-
expect(consolModule.warn).toHaveBeenCalledWith(expect.stringContaining('missing a "regex" value'));
|
|
116
|
-
});
|
|
117
|
-
test.each([123, {}, []])('should warn about an invalid replacement type %s', input => {
|
|
118
|
-
const newRules = [{
|
|
119
|
-
regex: rules[0].regex,
|
|
120
|
-
replacement: input
|
|
121
|
-
}];
|
|
122
|
-
expect(obfuscateModule.validateRules(newRules)).toEqual(false);
|
|
123
|
-
expect(consolModule.warn).toHaveBeenCalledWith(expect.stringContaining('contains a "replacement" value with an invalid type'));
|
|
124
|
-
});
|
|
125
|
-
});
|