@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,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
4
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
5
|
-
afterEach(() => {
|
|
6
|
-
jest.resetModules();
|
|
7
|
-
jest.clearAllMocks();
|
|
8
|
-
});
|
|
9
|
-
const urlTests = [{
|
|
10
|
-
input: 'http://example.com/path/name?qs=5&a=b',
|
|
11
|
-
expected: {
|
|
12
|
-
hostname: 'example.com',
|
|
13
|
-
pathname: '/path/name',
|
|
14
|
-
protocol: 'http',
|
|
15
|
-
port: '80',
|
|
16
|
-
sameOrigin: false
|
|
17
|
-
}
|
|
18
|
-
}, {
|
|
19
|
-
input: 'http://foo:bar@example.com:8080/path/@name?qs=5&a=b',
|
|
20
|
-
expected: {
|
|
21
|
-
hostname: 'example.com',
|
|
22
|
-
pathname: '/path/@name',
|
|
23
|
-
protocol: 'http',
|
|
24
|
-
port: '8080',
|
|
25
|
-
sameOrigin: false
|
|
26
|
-
}
|
|
27
|
-
}, {
|
|
28
|
-
input: 'https://foo:bar@example.com/path/name?qs=5&a=b',
|
|
29
|
-
expected: {
|
|
30
|
-
hostname: 'example.com',
|
|
31
|
-
pathname: '/path/name',
|
|
32
|
-
protocol: 'https',
|
|
33
|
-
port: '443',
|
|
34
|
-
sameOrigin: false
|
|
35
|
-
}
|
|
36
|
-
}, {
|
|
37
|
-
input: '/path/name?qs=5&a=b',
|
|
38
|
-
expected: {
|
|
39
|
-
hostname: location.hostname,
|
|
40
|
-
pathname: '/path/name',
|
|
41
|
-
protocol: location.protocol.split(':')[0],
|
|
42
|
-
port: '80',
|
|
43
|
-
sameOrigin: true
|
|
44
|
-
}
|
|
45
|
-
}, {
|
|
46
|
-
input: location.protocol + '//' + location.hostname + ':' + location.port + '/path/name?qs=5&a=b',
|
|
47
|
-
expected: {
|
|
48
|
-
hostname: location.hostname,
|
|
49
|
-
pathname: '/path/name',
|
|
50
|
-
protocol: location.protocol.split(':')[0],
|
|
51
|
-
port: '80',
|
|
52
|
-
sameOrigin: true
|
|
53
|
-
}
|
|
54
|
-
}, {
|
|
55
|
-
input: 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==',
|
|
56
|
-
expected: {
|
|
57
|
-
protocol: 'data'
|
|
58
|
-
}
|
|
59
|
-
}];
|
|
60
|
-
test.each(urlTests)('verify url parsing inside browser scope', async _ref => {
|
|
61
|
-
let {
|
|
62
|
-
input,
|
|
63
|
-
expected
|
|
64
|
-
} = _ref;
|
|
65
|
-
jest.doMock('../util/global-scope', () => ({
|
|
66
|
-
__esModule: true,
|
|
67
|
-
isBrowserScope: true,
|
|
68
|
-
globalScope: global
|
|
69
|
-
}));
|
|
70
|
-
const {
|
|
71
|
-
parseUrl
|
|
72
|
-
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./parse-url')));
|
|
73
|
-
expect(parseUrl(input)).toEqual(expected);
|
|
74
|
-
});
|
|
75
|
-
test.each(urlTests)('verify url parsing outside browser scope', async _ref2 => {
|
|
76
|
-
let {
|
|
77
|
-
input,
|
|
78
|
-
expected
|
|
79
|
-
} = _ref2;
|
|
80
|
-
jest.doMock('../util/global-scope', () => ({
|
|
81
|
-
__esModule: true,
|
|
82
|
-
isBrowserScope: false,
|
|
83
|
-
globalScope: global
|
|
84
|
-
}));
|
|
85
|
-
const {
|
|
86
|
-
parseUrl
|
|
87
|
-
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./parse-url')));
|
|
88
|
-
expect(parseUrl(input)).toEqual(expected);
|
|
89
|
-
});
|
|
90
|
-
test('should cache parsed urls', async () => {
|
|
91
|
-
jest.doMock('../util/global-scope', () => ({
|
|
92
|
-
__esModule: true,
|
|
93
|
-
isBrowserScope: true,
|
|
94
|
-
globalScope: global
|
|
95
|
-
}));
|
|
96
|
-
const input = 'http://example.com/';
|
|
97
|
-
const expected = {
|
|
98
|
-
hostname: 'example.com',
|
|
99
|
-
pathname: '/',
|
|
100
|
-
protocol: 'http',
|
|
101
|
-
port: '80',
|
|
102
|
-
sameOrigin: false
|
|
103
|
-
};
|
|
104
|
-
jest.spyOn(document, 'createElement');
|
|
105
|
-
const {
|
|
106
|
-
parseUrl
|
|
107
|
-
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./parse-url')));
|
|
108
|
-
parseUrl(input);
|
|
109
|
-
expect(parseUrl(input)).toEqual(expected);
|
|
110
|
-
expect(document.createElement).toHaveBeenCalledTimes(1);
|
|
111
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _protocol = require("./protocol");
|
|
4
|
-
test('should return true when location url contains file protocol', () => {
|
|
5
|
-
jest.spyOn(window, 'location', 'get').mockReturnValue({
|
|
6
|
-
protocol: 'file:'
|
|
7
|
-
});
|
|
8
|
-
expect((0, _protocol.isFileProtocol)()).toEqual(true);
|
|
9
|
-
});
|
|
10
|
-
test('should return false when location url does not contains file protocol', () => {
|
|
11
|
-
jest.spyOn(window, 'location', 'get').mockReturnValue({
|
|
12
|
-
protocol: 'http:'
|
|
13
|
-
});
|
|
14
|
-
expect((0, _protocol.isFileProtocol)()).toEqual(false);
|
|
15
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _console = require("./console");
|
|
4
|
-
beforeEach(() => {
|
|
5
|
-
console.warn = jest.fn();
|
|
6
|
-
});
|
|
7
|
-
afterEach(() => {
|
|
8
|
-
jest.restoreAllMocks();
|
|
9
|
-
});
|
|
10
|
-
describe('warn', () => {
|
|
11
|
-
test('should not call console.warn if it is not a function', () => {
|
|
12
|
-
const spy = jest.spyOn(console, 'warn');
|
|
13
|
-
console.warn = undefined;
|
|
14
|
-
(0, _console.warn)('test message');
|
|
15
|
-
expect(spy).not.toHaveBeenCalled();
|
|
16
|
-
});
|
|
17
|
-
test('should call console.warn with a prefixed message', () => {
|
|
18
|
-
(0, _console.warn)('test message');
|
|
19
|
-
expect(console.warn).toHaveBeenCalledWith('New Relic: test message');
|
|
20
|
-
});
|
|
21
|
-
test('should call console.warn with secondary argument if provided', () => {
|
|
22
|
-
const secondary = 'secondary value';
|
|
23
|
-
(0, _console.warn)('test message', secondary);
|
|
24
|
-
expect(console.warn).toHaveBeenCalledWith(secondary);
|
|
25
|
-
});
|
|
26
|
-
test('should not call console.warn with secondary argument if not provided', () => {
|
|
27
|
-
(0, _console.warn)('test message');
|
|
28
|
-
expect(console.warn).toHaveBeenCalledTimes(1);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _dataSize = require("./data-size");
|
|
4
|
-
describe('dataSize', () => {
|
|
5
|
-
test('returns length of string', () => {
|
|
6
|
-
const str = 'Hello, world!';
|
|
7
|
-
expect((0, _dataSize.dataSize)(str)).toBe(str.length);
|
|
8
|
-
});
|
|
9
|
-
test('returns undefined for non-object, number, or empty string', () => {
|
|
10
|
-
expect((0, _dataSize.dataSize)(Infinity)).toBeUndefined();
|
|
11
|
-
expect((0, _dataSize.dataSize)(12345)).toBeUndefined(); // might not actually be by design, but this is how it works today
|
|
12
|
-
expect((0, _dataSize.dataSize)('')).toBeUndefined();
|
|
13
|
-
});
|
|
14
|
-
test('returns byte length of ArrayBuffer object', () => {
|
|
15
|
-
const buffer = new ArrayBuffer(8);
|
|
16
|
-
expect((0, _dataSize.dataSize)(buffer)).toBe(8);
|
|
17
|
-
});
|
|
18
|
-
test('returns size of Blob object', () => {
|
|
19
|
-
const blob = new Blob(['Hello, world!'], {
|
|
20
|
-
type: 'text/plain'
|
|
21
|
-
});
|
|
22
|
-
expect((0, _dataSize.dataSize)(blob)).toBe(blob.size);
|
|
23
|
-
});
|
|
24
|
-
test('returns undefined for FormData object', () => {
|
|
25
|
-
const formData = new FormData();
|
|
26
|
-
expect((0, _dataSize.dataSize)(formData)).toBeUndefined();
|
|
27
|
-
});
|
|
28
|
-
test('returns length of JSON string representation of object', () => {
|
|
29
|
-
const obj = {
|
|
30
|
-
str: 'Hello, world!',
|
|
31
|
-
num: 12345,
|
|
32
|
-
nestedObj: {
|
|
33
|
-
arr: [1, 2, 3]
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
const expectedSize = JSON.stringify(obj).length;
|
|
37
|
-
expect((0, _dataSize.dataSize)(obj)).toBe(expectedSize);
|
|
38
|
-
});
|
|
39
|
-
test('returns undefined for object with toJSON method that throws an error', () => {
|
|
40
|
-
const obj = {
|
|
41
|
-
toJSON: () => {
|
|
42
|
-
throw new Error('Error in toJSON');
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
expect((0, _dataSize.dataSize)(obj)).toBeUndefined();
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _getOrSet = require("./get-or-set");
|
|
4
|
-
test('should return the current value of an existing property', () => {
|
|
5
|
-
const obj = {
|
|
6
|
-
foo: 'bar'
|
|
7
|
-
};
|
|
8
|
-
const prop = 'foo';
|
|
9
|
-
const getVal = jest.fn();
|
|
10
|
-
const result = (0, _getOrSet.getOrSet)(obj, prop, getVal);
|
|
11
|
-
expect(result).toBe('bar');
|
|
12
|
-
expect(getVal).not.toHaveBeenCalled();
|
|
13
|
-
});
|
|
14
|
-
test('should set and return the value from getVal if the property does not exist', () => {
|
|
15
|
-
const obj = {};
|
|
16
|
-
const prop = 'foo';
|
|
17
|
-
const getVal = jest.fn().mockReturnValue('baz');
|
|
18
|
-
const result = (0, _getOrSet.getOrSet)(obj, prop, getVal);
|
|
19
|
-
expect(result).toBe('baz');
|
|
20
|
-
expect(getVal).toHaveBeenCalled();
|
|
21
|
-
expect(obj.foo).toBe('baz');
|
|
22
|
-
});
|
|
23
|
-
test('should set the property as non-enumerable if Object.defineProperty is supported', () => {
|
|
24
|
-
const obj = {};
|
|
25
|
-
const prop = 'foo';
|
|
26
|
-
const getVal = jest.fn().mockReturnValue('baz');
|
|
27
|
-
jest.spyOn(Object, 'defineProperty');
|
|
28
|
-
const result = (0, _getOrSet.getOrSet)(obj, prop, getVal);
|
|
29
|
-
expect(result).toBe('baz');
|
|
30
|
-
expect(Object.defineProperty).toHaveBeenCalledWith(obj, prop, {
|
|
31
|
-
value: 'baz',
|
|
32
|
-
writable: true,
|
|
33
|
-
enumerable: false
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
test('should set the property from getVal if Object.defineProperty and Object.keys are not supported', () => {
|
|
37
|
-
const obj = {};
|
|
38
|
-
const prop = 'foo';
|
|
39
|
-
const getVal = jest.fn(() => 'baz');
|
|
40
|
-
const originalFn = Object.defineProperty;
|
|
41
|
-
Object.defineProperty = null;
|
|
42
|
-
const result = (0, _getOrSet.getOrSet)(obj, prop, getVal);
|
|
43
|
-
expect(result).toBe('baz');
|
|
44
|
-
expect(obj.foo).toBe('baz');
|
|
45
|
-
expect(Object.prototype.propertyIsEnumerable.call(obj, 'foo')).toBe(true);
|
|
46
|
-
Object.defineProperty = originalFn;
|
|
47
|
-
});
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getGlobalScope = getGlobalScope;
|
|
7
|
-
exports.isWorkerScope = exports.isBrowserScope = exports.initialLocation = exports.globalScope = void 0;
|
|
8
|
-
exports.resetScope = resetScope;
|
|
9
|
-
exports.setScope = setScope;
|
|
10
|
-
/* global globalThis, WorkerGlobalScope, WorkerNavigator */
|
|
11
|
-
|
|
12
|
-
const isBrowserScope = Boolean(typeof window !== 'undefined' && window.document);
|
|
13
|
-
exports.isBrowserScope = isBrowserScope;
|
|
14
|
-
const isWorkerScope = Boolean(typeof WorkerGlobalScope !== 'undefined' && self.navigator instanceof WorkerNavigator);
|
|
15
|
-
exports.isWorkerScope = isWorkerScope;
|
|
16
|
-
let globalScope = (() => {
|
|
17
|
-
if (isBrowserScope) {
|
|
18
|
-
return window;
|
|
19
|
-
} else if (isWorkerScope) {
|
|
20
|
-
if (typeof globalThis !== 'undefined' && globalThis instanceof WorkerGlobalScope) {
|
|
21
|
-
return globalThis;
|
|
22
|
-
} else if (self instanceof WorkerGlobalScope) {
|
|
23
|
-
return self;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
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".');
|
|
27
|
-
})();
|
|
28
|
-
exports.globalScope = globalScope;
|
|
29
|
-
const initialLocation = '' + globalScope.location;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The below methods are only used for testing and should be removed once the
|
|
33
|
-
* reliant tests are moved to Jest.
|
|
34
|
-
* tests/browser/protocol.browser.js
|
|
35
|
-
* tests/browser/obfuscate.browser.js
|
|
36
|
-
*/
|
|
37
|
-
exports.initialLocation = initialLocation;
|
|
38
|
-
function setScope(obj) {
|
|
39
|
-
exports.globalScope = globalScope = {
|
|
40
|
-
...obj
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function resetScope() {
|
|
44
|
-
if (isBrowserScope) {
|
|
45
|
-
exports.globalScope = globalScope = window;
|
|
46
|
-
} else if (isWorkerScope) {
|
|
47
|
-
if (typeof globalThis !== 'undefined' && globalThis instanceof WorkerGlobalScope) {
|
|
48
|
-
exports.globalScope = globalScope = globalThis;
|
|
49
|
-
} else if (self instanceof WorkerGlobalScope) {
|
|
50
|
-
exports.globalScope = globalScope = self;
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
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".');
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function getGlobalScope() {
|
|
57
|
-
return globalScope;
|
|
58
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _invoke = require("./invoke");
|
|
4
|
-
jest.useFakeTimers();
|
|
5
|
-
describe('debounce', () => {
|
|
6
|
-
test('should run the supplied function after 100ms', () => {
|
|
7
|
-
let mockCallback = jest.fn();
|
|
8
|
-
let debouncedMethod = (0, _invoke.debounce)(mockCallback, 100);
|
|
9
|
-
execFnTimes(debouncedMethod, 100);
|
|
10
|
-
expect(mockCallback).not.toHaveBeenCalled();
|
|
11
|
-
jest.advanceTimersByTime(1000);
|
|
12
|
-
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
13
|
-
});
|
|
14
|
-
test('should rerun the supplied function when called again after 100ms', () => {
|
|
15
|
-
let mockCallback = jest.fn();
|
|
16
|
-
let debouncedMethod = (0, _invoke.debounce)(mockCallback, 100);
|
|
17
|
-
execFnTimes(debouncedMethod, 100);
|
|
18
|
-
jest.advanceTimersByTime(200);
|
|
19
|
-
execFnTimes(debouncedMethod, 100);
|
|
20
|
-
jest.advanceTimersByTime(2000);
|
|
21
|
-
expect(mockCallback).toHaveBeenCalledTimes(2);
|
|
22
|
-
});
|
|
23
|
-
test('should run the supplied function on the first event and debounce subsequent events', () => {
|
|
24
|
-
let mockCallback = jest.fn();
|
|
25
|
-
let debouncedMethod = (0, _invoke.debounce)(mockCallback, 100, {
|
|
26
|
-
leading: true
|
|
27
|
-
});
|
|
28
|
-
execFnTimes(debouncedMethod, 100);
|
|
29
|
-
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
30
|
-
jest.advanceTimersByTime(200);
|
|
31
|
-
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
32
|
-
execFnTimes(debouncedMethod, 100);
|
|
33
|
-
jest.advanceTimersByTime(200);
|
|
34
|
-
expect(mockCallback).toHaveBeenCalledTimes(2);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
describe('single', () => {
|
|
38
|
-
test('should run the supplied function only once', () => {
|
|
39
|
-
let mockCallback = jest.fn();
|
|
40
|
-
let singleMethod = (0, _invoke.single)(mockCallback, 100);
|
|
41
|
-
execFnTimes(singleMethod, 100);
|
|
42
|
-
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
function execFnTimes(fn, count) {
|
|
46
|
-
for (let i = 0; i < count; i++) {
|
|
47
|
-
fn();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _mapOwn = require("./map-own");
|
|
4
|
-
test('enumerates the object properties', () => {
|
|
5
|
-
const callback = jest.fn();
|
|
6
|
-
const input = {
|
|
7
|
-
foo: 'bar'
|
|
8
|
-
};
|
|
9
|
-
(0, _mapOwn.mapOwn)(input, callback);
|
|
10
|
-
expect(callback).toHaveBeenCalledWith('foo', 'bar');
|
|
11
|
-
});
|
|
12
|
-
test('return array of results from callback invocation', () => {
|
|
13
|
-
const callback = jest.fn((key, value) => "".concat(key, ":").concat(value));
|
|
14
|
-
const input = {
|
|
15
|
-
foo: 'bar',
|
|
16
|
-
biz: 'baz'
|
|
17
|
-
};
|
|
18
|
-
const result = (0, _mapOwn.mapOwn)(input, callback);
|
|
19
|
-
expect(result.length).toEqual(2);
|
|
20
|
-
expect(result).toContain('foo:bar');
|
|
21
|
-
expect(result).toContain('biz:baz');
|
|
22
|
-
});
|
|
23
|
-
test('does not iterate symbol properties', () => {
|
|
24
|
-
const callback = jest.fn((key, value) => "".concat(key, ":").concat(value));
|
|
25
|
-
const input = {
|
|
26
|
-
foo: 'bar',
|
|
27
|
-
[Symbol.for('biz')]: 'baz'
|
|
28
|
-
};
|
|
29
|
-
const result = (0, _mapOwn.mapOwn)(input, callback);
|
|
30
|
-
expect(result.length).toEqual(1);
|
|
31
|
-
});
|
|
32
|
-
test('does not iterate inherited properties', () => {
|
|
33
|
-
function F() {}
|
|
34
|
-
F.prototype = {
|
|
35
|
-
biz: 'baz'
|
|
36
|
-
};
|
|
37
|
-
const callback = jest.fn((key, value) => "".concat(key, ":").concat(value));
|
|
38
|
-
const input = new F();
|
|
39
|
-
input.foo = 'bar';
|
|
40
|
-
const result = (0, _mapOwn.mapOwn)(input, callback);
|
|
41
|
-
expect(result.length).toEqual(1);
|
|
42
|
-
});
|
|
43
|
-
test.each([null, undefined])('returns empty array when passed object is null or undefined', input => {
|
|
44
|
-
const callback = jest.fn();
|
|
45
|
-
const result = (0, _mapOwn.mapOwn)(input, callback);
|
|
46
|
-
expect(Array.isArray(result)).toEqual(true);
|
|
47
|
-
expect(result.length).toEqual(0);
|
|
48
|
-
expect(callback).toHaveBeenCalledTimes(0);
|
|
49
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _stringify = require("./stringify");
|
|
4
|
-
var mockEmit = jest.fn();
|
|
5
|
-
jest.mock('../event-emitter/contextual-ee', () => ({
|
|
6
|
-
__esModule: true,
|
|
7
|
-
get ee() {
|
|
8
|
-
return {
|
|
9
|
-
emit: mockEmit
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
}));
|
|
13
|
-
test('should return a JSON string representation of the value', () => {
|
|
14
|
-
const obj = {
|
|
15
|
-
a: 1,
|
|
16
|
-
b: {
|
|
17
|
-
nested: true
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const expected = '{"a":1,"b":{"nested":true}}';
|
|
21
|
-
const result = (0, _stringify.stringify)(obj);
|
|
22
|
-
expect(result).toBe(expected);
|
|
23
|
-
});
|
|
24
|
-
test('should handle circular references and exclude them from the JSON output', () => {
|
|
25
|
-
const obj = {
|
|
26
|
-
a: 1
|
|
27
|
-
};
|
|
28
|
-
obj.b = obj; // Create a circular reference
|
|
29
|
-
const expected = '{"a":1}';
|
|
30
|
-
const result = (0, _stringify.stringify)(obj);
|
|
31
|
-
expect(result).toBe(expected);
|
|
32
|
-
});
|
|
33
|
-
test('should handle non-object values and return their string representation', () => {
|
|
34
|
-
const value = 42;
|
|
35
|
-
const expected = '42';
|
|
36
|
-
const result = (0, _stringify.stringify)(value);
|
|
37
|
-
expect(result).toBe(expected);
|
|
38
|
-
});
|
|
39
|
-
test('should emit an "internal-error" event if an error occurs during JSON.stringify', () => {
|
|
40
|
-
const obj = {
|
|
41
|
-
a: 1
|
|
42
|
-
};
|
|
43
|
-
jest.spyOn(JSON, 'stringify').mockImplementation(() => {
|
|
44
|
-
throw new Error('message');
|
|
45
|
-
});
|
|
46
|
-
(0, _stringify.stringify)(obj);
|
|
47
|
-
expect(mockEmit).toHaveBeenCalledWith('internal-error', expect.any(Array));
|
|
48
|
-
});
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _submitData = require("./submit-data");
|
|
4
|
-
/**
|
|
5
|
-
* @jest-environment jsdom
|
|
6
|
-
* @jest-environment-options {"html": "<html><head><script></script></head><body></body></html>", "url": "https://example.com/"}
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const mockWorkerScope = jest.fn().mockImplementation(() => false);
|
|
10
|
-
jest.mock('./global-scope', () => ({
|
|
11
|
-
__esModule: true,
|
|
12
|
-
get isWorkerScope() {
|
|
13
|
-
return mockWorkerScope();
|
|
14
|
-
}
|
|
15
|
-
}));
|
|
16
|
-
const url = 'https://example.com/api';
|
|
17
|
-
beforeEach(() => {
|
|
18
|
-
jest.restoreAllMocks();
|
|
19
|
-
mockWorkerScope.mockReturnValue(false);
|
|
20
|
-
});
|
|
21
|
-
describe('submitData.jsonp', () => {
|
|
22
|
-
// This test requires a script tag to exist in the html set by this file's jest-environment-options header block.
|
|
23
|
-
test('should return an HTMLScriptElement when called from a web window environment', () => {
|
|
24
|
-
mockWorkerScope.mockReturnValue(false);
|
|
25
|
-
const jsonp = 'callback';
|
|
26
|
-
const result = _submitData.submitData.jsonp({
|
|
27
|
-
url,
|
|
28
|
-
jsonp
|
|
29
|
-
});
|
|
30
|
-
expect(result).toBeInstanceOf(HTMLScriptElement);
|
|
31
|
-
expect(result.type).toBe('text/javascript');
|
|
32
|
-
expect(result.src).toBe(url + '&jsonp=' + jsonp);
|
|
33
|
-
});
|
|
34
|
-
test('should try to use importScripts when called from a worker scope', () => {
|
|
35
|
-
mockWorkerScope.mockReturnValueOnce(true);
|
|
36
|
-
const jsonp = 'callback';
|
|
37
|
-
global.importScripts = jest.fn();
|
|
38
|
-
_submitData.submitData.jsonp({
|
|
39
|
-
url,
|
|
40
|
-
jsonp
|
|
41
|
-
});
|
|
42
|
-
expect(importScripts).toHaveBeenCalledWith(url + '&jsonp=' + jsonp);
|
|
43
|
-
delete global.importScripts;
|
|
44
|
-
});
|
|
45
|
-
test('should fall back to an xhrGet call and return false when called from a worker scope', () => {
|
|
46
|
-
mockWorkerScope.mockReturnValueOnce(true);
|
|
47
|
-
const jsonp = 'callback';
|
|
48
|
-
jest.spyOn(_submitData.submitData, 'xhrGet').mockImplementation(jest.fn());
|
|
49
|
-
const result = _submitData.submitData.jsonp({
|
|
50
|
-
url,
|
|
51
|
-
jsonp
|
|
52
|
-
});
|
|
53
|
-
expect(result).toBe(false);
|
|
54
|
-
expect(_submitData.submitData.xhrGet).toHaveBeenCalledTimes(1);
|
|
55
|
-
});
|
|
56
|
-
test('should not throw an error if any error occurs during execution', () => {
|
|
57
|
-
jest.spyOn(document, 'createElement').mockImplementation(() => {
|
|
58
|
-
throw new Error('message');
|
|
59
|
-
});
|
|
60
|
-
const jsonp = 'callback';
|
|
61
|
-
expect(() => {
|
|
62
|
-
_submitData.submitData.jsonp({
|
|
63
|
-
url,
|
|
64
|
-
jsonp
|
|
65
|
-
});
|
|
66
|
-
}).not.toThrow();
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
describe('submitData.xhrGet', () => {
|
|
70
|
-
test('should return an XMLHttpRequest object', () => {
|
|
71
|
-
const result = _submitData.submitData.xhrGet({
|
|
72
|
-
url
|
|
73
|
-
});
|
|
74
|
-
expect(result).toBeInstanceOf(XMLHttpRequest);
|
|
75
|
-
});
|
|
76
|
-
test('should not throw an error if URL is not provided', () => {
|
|
77
|
-
expect(() => {
|
|
78
|
-
_submitData.submitData.xhrGet({});
|
|
79
|
-
}).not.toThrow();
|
|
80
|
-
});
|
|
81
|
-
test('should not throw an error if an invalid URL is provided', () => {
|
|
82
|
-
expect(() => {
|
|
83
|
-
_submitData.submitData.xhrGet({
|
|
84
|
-
url: 'invalid url'
|
|
85
|
-
});
|
|
86
|
-
}).not.toThrow();
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
describe('submitData.xhr', () => {
|
|
90
|
-
test('should return an XMLHttpRequest object', () => {
|
|
91
|
-
const result = _submitData.submitData.xhrGet({
|
|
92
|
-
url
|
|
93
|
-
});
|
|
94
|
-
expect(result).toBeInstanceOf(XMLHttpRequest);
|
|
95
|
-
});
|
|
96
|
-
test('should not throw an error if URL is not provided', () => {
|
|
97
|
-
expect(() => {
|
|
98
|
-
_submitData.submitData.xhr({});
|
|
99
|
-
}).not.toThrow();
|
|
100
|
-
});
|
|
101
|
-
test('should not throw an error if an invalid URL is provided', () => {
|
|
102
|
-
expect(() => {
|
|
103
|
-
_submitData.submitData.xhr({
|
|
104
|
-
url: 'invalid url'
|
|
105
|
-
});
|
|
106
|
-
}).not.toThrow();
|
|
107
|
-
});
|
|
108
|
-
test('should send a POST request by default', () => {
|
|
109
|
-
jest.spyOn(XMLHttpRequest.prototype, 'open');
|
|
110
|
-
_submitData.submitData.xhr({
|
|
111
|
-
url
|
|
112
|
-
});
|
|
113
|
-
expect(XMLHttpRequest.prototype.open).toHaveBeenCalledWith('POST', url, true);
|
|
114
|
-
});
|
|
115
|
-
test('should send a GET request if specified', () => {
|
|
116
|
-
jest.spyOn(XMLHttpRequest.prototype, 'open');
|
|
117
|
-
_submitData.submitData.xhr({
|
|
118
|
-
url,
|
|
119
|
-
method: 'GET'
|
|
120
|
-
});
|
|
121
|
-
expect(XMLHttpRequest.prototype.open).toHaveBeenCalledWith('GET', url, true);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
// This test requires a same-origin url to be set by this file's jest-environment-options header block.
|
|
125
|
-
test('should send a request synchronously if specified', () => {
|
|
126
|
-
jest.spyOn(XMLHttpRequest.prototype, 'open');
|
|
127
|
-
_submitData.submitData.xhr({
|
|
128
|
-
url,
|
|
129
|
-
sync: true
|
|
130
|
-
});
|
|
131
|
-
expect(XMLHttpRequest.prototype.open).toHaveBeenCalledWith('POST', url, false);
|
|
132
|
-
});
|
|
133
|
-
test('should set custom headers if provided', () => {
|
|
134
|
-
const headers = [{
|
|
135
|
-
key: 'Content-Type',
|
|
136
|
-
value: 'application/json'
|
|
137
|
-
}];
|
|
138
|
-
jest.spyOn(XMLHttpRequest.prototype, 'setRequestHeader');
|
|
139
|
-
_submitData.submitData.xhr({
|
|
140
|
-
url,
|
|
141
|
-
headers
|
|
142
|
-
});
|
|
143
|
-
headers.forEach(header => {
|
|
144
|
-
expect(XMLHttpRequest.prototype.setRequestHeader).toHaveBeenCalledWith(header.key, header.value);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
test('should send a request with the specified body', () => {
|
|
148
|
-
const body = JSON.stringify({
|
|
149
|
-
key: 'value'
|
|
150
|
-
});
|
|
151
|
-
jest.spyOn(XMLHttpRequest.prototype, 'send');
|
|
152
|
-
_submitData.submitData.xhr({
|
|
153
|
-
url,
|
|
154
|
-
body
|
|
155
|
-
});
|
|
156
|
-
expect(XMLHttpRequest.prototype.send).toHaveBeenCalledWith(body);
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
describe('submitData.img', () => {
|
|
160
|
-
test('should return an HTMLImageElement', () => {
|
|
161
|
-
const imageUrl = 'https://example.com/image.png';
|
|
162
|
-
const result = _submitData.submitData.img({
|
|
163
|
-
url: imageUrl
|
|
164
|
-
});
|
|
165
|
-
expect(result).toBeInstanceOf(HTMLImageElement);
|
|
166
|
-
});
|
|
167
|
-
test('should not throw an error if URL is not provided', () => {
|
|
168
|
-
expect(() => {
|
|
169
|
-
_submitData.submitData.img({});
|
|
170
|
-
}).not.toThrow();
|
|
171
|
-
});
|
|
172
|
-
test('should set the src attribute of the image element to the provided URL', () => {
|
|
173
|
-
const imageUrl = 'https://example.com/image.png';
|
|
174
|
-
const result = _submitData.submitData.img({
|
|
175
|
-
url: imageUrl
|
|
176
|
-
});
|
|
177
|
-
expect(result.src).toBe(imageUrl);
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
describe('submitData.beacon', () => {
|
|
181
|
-
test('should return true when beacon request succeeds', () => {
|
|
182
|
-
const body = JSON.stringify({
|
|
183
|
-
key: 'value'
|
|
184
|
-
});
|
|
185
|
-
window.navigator.sendBeacon = {
|
|
186
|
-
bind: jest.fn(() => () => true)
|
|
187
|
-
};
|
|
188
|
-
const result = _submitData.submitData.beacon({
|
|
189
|
-
url,
|
|
190
|
-
body
|
|
191
|
-
});
|
|
192
|
-
expect(result).toBe(true);
|
|
193
|
-
});
|
|
194
|
-
test('should return false when beacon request fails', () => {
|
|
195
|
-
const body = JSON.stringify({
|
|
196
|
-
key: 'value'
|
|
197
|
-
});
|
|
198
|
-
window.navigator.sendBeacon = {
|
|
199
|
-
bind: jest.fn(() => () => {
|
|
200
|
-
throw new Error('message');
|
|
201
|
-
})
|
|
202
|
-
};
|
|
203
|
-
const result = _submitData.submitData.beacon({
|
|
204
|
-
url,
|
|
205
|
-
body
|
|
206
|
-
});
|
|
207
|
-
expect(result).toBe(false);
|
|
208
|
-
});
|
|
209
|
-
test('should error if sendBeacon is not supported', () => {
|
|
210
|
-
const body = JSON.stringify({
|
|
211
|
-
key: 'value'
|
|
212
|
-
});
|
|
213
|
-
window.navigator.sendBeacon = undefined;
|
|
214
|
-
expect(() => {
|
|
215
|
-
_submitData.submitData.beacon({
|
|
216
|
-
url,
|
|
217
|
-
body
|
|
218
|
-
});
|
|
219
|
-
}).toThrow();
|
|
220
|
-
});
|
|
221
|
-
});
|