@newrelic/browser-agent 1.235.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 +41 -1
- 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/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 +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 +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 +58 -76
- 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 +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 +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 +7 -4
- package/dist/cjs/features/jserrors/instrument/index.js +4 -4
- 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/replay-mode.js +2 -2
- 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 +6 -7
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/loaders/agent.js +7 -0
- 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/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/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 +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 +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 +55 -73
- 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 +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 +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 +6 -3
- package/dist/esm/features/jserrors/instrument/index.js +1 -1
- 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/replay-mode.js +2 -2
- 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 +4 -5
- package/dist/esm/index.js +1 -4
- package/dist/esm/loaders/agent.js +7 -0
- package/dist/esm/loaders/api/api.js +1 -1
- package/dist/esm/loaders/api/apiAsync.js +3 -3
- package/dist/esm/loaders/configure/configure.js +1 -1
- 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/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/unload/eol.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 +1 -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/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/micro-agent.d.ts +3 -4
- 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 +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/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 +21 -20
- package/src/common/harvest/harvest-scheduler.test.js +496 -0
- package/src/common/harvest/harvest.js +147 -130
- package/src/common/harvest/harvest.test.js +818 -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 +6 -0
- package/src/common/util/__mocks__/traverse.js +1 -0
- package/src/common/util/submit-data.js +39 -53
- package/src/common/util/submit-data.test.js +81 -68
- 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 +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 +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 +7 -3
- package/src/features/jserrors/instrument/index.js +1 -1
- 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/replay-mode.js +2 -2
- 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 +5 -5
- package/src/features/utils/instrument-base.test.js +22 -3
- package/src/index.js +1 -3
- package/src/loaders/agent.js +8 -0
- package/src/loaders/api/api.js +1 -1
- package/src/loaders/api/apiAsync.js +3 -3
- package/src/loaders/configure/configure.js +1 -1
- 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.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/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/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/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
|
@@ -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,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _faker = require("@faker-js/faker");
|
|
4
|
-
var stringifyModule = _interopRequireWildcard(require("./stringify"));
|
|
5
|
-
var _dataSize = require("./data-size");
|
|
6
|
-
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); }
|
|
7
|
-
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; }
|
|
8
|
-
jest.mock('./stringify');
|
|
9
|
-
describe('dataSize', () => {
|
|
10
|
-
test('returns length of string', () => {
|
|
11
|
-
const str = _faker.faker.lorem.sentence();
|
|
12
|
-
expect((0, _dataSize.dataSize)(str)).toBe(str.length);
|
|
13
|
-
});
|
|
14
|
-
test('returns undefined for non-object, number, or empty string', () => {
|
|
15
|
-
expect((0, _dataSize.dataSize)(Infinity)).toBeUndefined();
|
|
16
|
-
expect((0, _dataSize.dataSize)(NaN)).toBeUndefined();
|
|
17
|
-
expect((0, _dataSize.dataSize)(12345)).toBeUndefined();
|
|
18
|
-
expect((0, _dataSize.dataSize)('')).toBeUndefined();
|
|
19
|
-
});
|
|
20
|
-
test('returns byte length of ArrayBuffer object', () => {
|
|
21
|
-
const buffer = new ArrayBuffer(_faker.faker.datatype.number({
|
|
22
|
-
min: 10,
|
|
23
|
-
max: 100
|
|
24
|
-
}));
|
|
25
|
-
expect((0, _dataSize.dataSize)(buffer)).toBe(buffer.byteLength);
|
|
26
|
-
});
|
|
27
|
-
test('returns size of Blob object', () => {
|
|
28
|
-
const blob = new Blob([_faker.faker.lorem.sentence()], {
|
|
29
|
-
type: 'text/plain'
|
|
30
|
-
});
|
|
31
|
-
expect((0, _dataSize.dataSize)(blob)).toBe(blob.size);
|
|
32
|
-
});
|
|
33
|
-
test('returns undefined for FormData object', () => {
|
|
34
|
-
const formData = new FormData();
|
|
35
|
-
expect((0, _dataSize.dataSize)(formData)).toBeUndefined();
|
|
36
|
-
});
|
|
37
|
-
test('uses stringify to get the length of an object', () => {
|
|
38
|
-
const input = {
|
|
39
|
-
[_faker.faker.datatype.uuid()]: _faker.faker.lorem.sentence()
|
|
40
|
-
};
|
|
41
|
-
const expectedSize = _faker.faker.datatype.number({
|
|
42
|
-
min: 1000,
|
|
43
|
-
max: 10000
|
|
44
|
-
});
|
|
45
|
-
jest.spyOn(stringifyModule, 'stringify').mockReturnValue({
|
|
46
|
-
length: expectedSize
|
|
47
|
-
});
|
|
48
|
-
expect((0, _dataSize.dataSize)(input)).toBe(expectedSize);
|
|
49
|
-
});
|
|
50
|
-
test('should not throw an exception if stringify throws an exception', () => {
|
|
51
|
-
const input = {
|
|
52
|
-
[_faker.faker.datatype.uuid()]: _faker.faker.lorem.sentence()
|
|
53
|
-
};
|
|
54
|
-
const expectedSize = _faker.faker.datatype.number({
|
|
55
|
-
min: 1000,
|
|
56
|
-
max: 10000
|
|
57
|
-
});
|
|
58
|
-
jest.spyOn(stringifyModule, 'stringify').mockImplementation(() => {
|
|
59
|
-
throw new Error(_faker.faker.lorem.sentence());
|
|
60
|
-
});
|
|
61
|
-
expect(() => (0, _dataSize.dataSize)(input)).not.toThrow();
|
|
62
|
-
expect((0, _dataSize.dataSize)(input)).toBeUndefined();
|
|
63
|
-
});
|
|
64
|
-
});
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _faker = require("@faker-js/faker");
|
|
4
|
-
var eventEmitterModule = _interopRequireWildcard(require("../event-emitter/contextual-ee"));
|
|
5
|
-
var handleModule = _interopRequireWildcard(require("../event-emitter/handle"));
|
|
6
|
-
var drainModule = _interopRequireWildcard(require("../drain/drain"));
|
|
7
|
-
var _featureFlags = require("./feature-flags");
|
|
8
|
-
var _features = require("../../loaders/features/features");
|
|
9
|
-
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); }
|
|
10
|
-
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; }
|
|
11
|
-
jest.mock('../event-emitter/handle');
|
|
12
|
-
jest.mock('../drain/drain');
|
|
13
|
-
jest.mock('../event-emitter/contextual-ee', () => ({
|
|
14
|
-
__esModule: true,
|
|
15
|
-
ee: {
|
|
16
|
-
get: jest.fn(() => ({
|
|
17
|
-
foo: "bar_".concat(Math.random())
|
|
18
|
-
}))
|
|
19
|
-
}
|
|
20
|
-
}));
|
|
21
|
-
let agentIdentifier;
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
agentIdentifier = _faker.faker.datatype.uuid();
|
|
24
|
-
});
|
|
25
|
-
afterEach(() => {
|
|
26
|
-
Object.keys(_featureFlags.activatedFeatures).forEach(key => delete _featureFlags.activatedFeatures[key]);
|
|
27
|
-
});
|
|
28
|
-
test.each([null, undefined])('should not do anything when flags is %s', input => {
|
|
29
|
-
(0, _featureFlags.activateFeatures)(input, agentIdentifier);
|
|
30
|
-
expect(handleModule.handle).not.toHaveBeenCalled();
|
|
31
|
-
expect(drainModule.drain).not.toHaveBeenCalled();
|
|
32
|
-
expect(_featureFlags.activatedFeatures).toEqual({});
|
|
33
|
-
});
|
|
34
|
-
const bucketMap = {
|
|
35
|
-
stn: [_features.FEATURE_NAMES.sessionTrace],
|
|
36
|
-
err: [_features.FEATURE_NAMES.jserrors, _features.FEATURE_NAMES.metrics],
|
|
37
|
-
ins: [_features.FEATURE_NAMES.pageAction],
|
|
38
|
-
spa: [_features.FEATURE_NAMES.spa],
|
|
39
|
-
sr: [_features.FEATURE_NAMES.sessionReplay, _features.FEATURE_NAMES.sessionTrace]
|
|
40
|
-
};
|
|
41
|
-
test('emits the right events when feature flag = 1', () => {
|
|
42
|
-
const flags = {};
|
|
43
|
-
Object.keys(bucketMap).forEach(flag => flags[flag] = 1);
|
|
44
|
-
(0, _featureFlags.activateFeatures)(flags, agentIdentifier);
|
|
45
|
-
const sharedEE = jest.mocked(eventEmitterModule.ee.get).mock.results[0].value;
|
|
46
|
-
|
|
47
|
-
// 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
|
|
48
|
-
expect(handleModule.handle).toHaveBeenCalledTimes(14);
|
|
49
|
-
expect(handleModule.handle).toHaveBeenNthCalledWith(1, 'feat-stn', [], undefined, _features.FEATURE_NAMES.sessionTrace, sharedEE);
|
|
50
|
-
expect(handleModule.handle).toHaveBeenLastCalledWith('rumresp-sr', [true], undefined, _features.FEATURE_NAMES.sessionTrace, sharedEE);
|
|
51
|
-
expect(drainModule.drain).toHaveBeenCalledWith(agentIdentifier, 'page_view_event');
|
|
52
|
-
Object.keys(flags).forEach(flag => flags[flag] = true);
|
|
53
|
-
expect(_featureFlags.activatedFeatures).toEqual(flags);
|
|
54
|
-
});
|
|
55
|
-
test('emits the right events when feature flag = 0', () => {
|
|
56
|
-
const flags = {};
|
|
57
|
-
Object.keys(bucketMap).forEach(flag => flags[flag] = 0);
|
|
58
|
-
(0, _featureFlags.activateFeatures)(flags, agentIdentifier);
|
|
59
|
-
const sharedEE = jest.mocked(eventEmitterModule.ee.get).mock.results[0].value;
|
|
60
|
-
|
|
61
|
-
// 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
|
|
62
|
-
expect(handleModule.handle).toHaveBeenCalledTimes(14);
|
|
63
|
-
expect(handleModule.handle).toHaveBeenNthCalledWith(1, 'block-stn', [], undefined, _features.FEATURE_NAMES.sessionTrace, sharedEE);
|
|
64
|
-
expect(handleModule.handle).toHaveBeenLastCalledWith('rumresp-sr', [false], undefined, _features.FEATURE_NAMES.sessionTrace, sharedEE);
|
|
65
|
-
expect(drainModule.drain).toHaveBeenCalledWith(agentIdentifier, 'page_view_event');
|
|
66
|
-
Object.keys(flags).forEach(flag => flags[flag] = false);
|
|
67
|
-
expect(_featureFlags.activatedFeatures).toEqual(flags);
|
|
68
|
-
});
|
|
69
|
-
test('only the first activate of the same feature is respected', () => {
|
|
70
|
-
const flags = {
|
|
71
|
-
stn: 1
|
|
72
|
-
};
|
|
73
|
-
(0, _featureFlags.activateFeatures)(flags, agentIdentifier);
|
|
74
|
-
flags.stn = 0;
|
|
75
|
-
(0, _featureFlags.activateFeatures)(flags, agentIdentifier);
|
|
76
|
-
const sharedEE1 = jest.mocked(eventEmitterModule.ee.get).mock.results[0].value;
|
|
77
|
-
const sharedEE2 = jest.mocked(eventEmitterModule.ee.get).mock.results[1].value;
|
|
78
|
-
expect(handleModule.handle).toHaveBeenNthCalledWith(1, 'feat-stn', [], undefined, 'session_trace', sharedEE1);
|
|
79
|
-
expect(handleModule.handle).toHaveBeenNthCalledWith(2, 'rumresp-stn', [true], undefined, 'session_trace', sharedEE1);
|
|
80
|
-
expect(handleModule.handle).not.toHaveBeenNthCalledWith(1, 'feat-stn', [], undefined, 'session_trace', sharedEE2);
|
|
81
|
-
expect(drainModule.drain).toHaveBeenCalledWith(agentIdentifier, 'page_view_event');
|
|
82
|
-
expect(drainModule.drain).toHaveBeenCalledTimes(2);
|
|
83
|
-
expect(_featureFlags.activatedFeatures.stn).toBeTruthy();
|
|
84
|
-
});
|
|
@@ -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,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isWorkerScope = exports.isBrowserScope = exports.initialLocation = exports.globalScope = void 0;
|
|
7
|
-
/* global globalThis, WorkerGlobalScope, WorkerNavigator */
|
|
8
|
-
|
|
9
|
-
const isBrowserScope = Boolean(typeof window !== 'undefined' && window.document);
|
|
10
|
-
exports.isBrowserScope = isBrowserScope;
|
|
11
|
-
const isWorkerScope = Boolean(typeof WorkerGlobalScope !== 'undefined' && self.navigator instanceof WorkerNavigator);
|
|
12
|
-
exports.isWorkerScope = isWorkerScope;
|
|
13
|
-
let globalScope = (() => {
|
|
14
|
-
if (isBrowserScope) {
|
|
15
|
-
return window;
|
|
16
|
-
} else if (isWorkerScope) {
|
|
17
|
-
if (typeof globalThis !== 'undefined' && globalThis instanceof WorkerGlobalScope) {
|
|
18
|
-
return globalThis;
|
|
19
|
-
} else if (self instanceof WorkerGlobalScope) {
|
|
20
|
-
return self;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
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".');
|
|
24
|
-
})();
|
|
25
|
-
exports.globalScope = globalScope;
|
|
26
|
-
const initialLocation = '' + globalScope.location;
|
|
27
|
-
exports.initialLocation = initialLocation;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _faker = require("@faker-js/faker");
|
|
4
|
-
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); }
|
|
5
|
-
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; } /*
|
|
6
|
-
The global-scope module contains exports that are defined once at the time
|
|
7
|
-
of importing the module. For this reason, the module must be dynamically
|
|
8
|
-
imported in each test case.
|
|
9
|
-
|
|
10
|
-
A scope must always exist or importing the module will throw an error. Use
|
|
11
|
-
`enableWorkerScope` to enable the worker scope. Be sure to call `disableWorkerScope`
|
|
12
|
-
before any calls to `expect` or the test will fail with an error from Jest.
|
|
13
|
-
*/
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
jest.restoreAllMocks();
|
|
16
|
-
jest.resetModules();
|
|
17
|
-
});
|
|
18
|
-
test('should indicate a browser scope', async () => {
|
|
19
|
-
jest.spyOn(global, 'window', 'get').mockReturnValue({
|
|
20
|
-
document: {}
|
|
21
|
-
});
|
|
22
|
-
const globalScopeModule = await Promise.resolve().then(() => _interopRequireWildcard(require('./global-scope')));
|
|
23
|
-
expect(globalScopeModule.isBrowserScope).toBe(true);
|
|
24
|
-
expect(globalScopeModule.isWorkerScope).toBe(false);
|
|
25
|
-
expect(globalScopeModule.globalScope).toBe(global.window);
|
|
26
|
-
});
|
|
27
|
-
test('should indicate a worker scope', async () => {
|
|
28
|
-
enableWorkerScope();
|
|
29
|
-
const globalScopeModule = await Promise.resolve().then(() => _interopRequireWildcard(require('./global-scope')));
|
|
30
|
-
const mockedGlobalThis = global.globalThis;
|
|
31
|
-
disableWorkerScope();
|
|
32
|
-
expect(globalScopeModule.isBrowserScope).toBe(false);
|
|
33
|
-
expect(globalScopeModule.isWorkerScope).toBe(true);
|
|
34
|
-
expect(globalScopeModule.globalScope).toBe(mockedGlobalThis);
|
|
35
|
-
});
|
|
36
|
-
test('should return the self global', async () => {
|
|
37
|
-
enableWorkerScope();
|
|
38
|
-
jest.replaceProperty(global, 'globalThis', null);
|
|
39
|
-
jest.spyOn(global, 'self', 'get').mockReturnValue(new global.WorkerGlobalScope());
|
|
40
|
-
const globalScopeModule = await Promise.resolve().then(() => _interopRequireWildcard(require('./global-scope')));
|
|
41
|
-
const mockedGlobalSelf = global.self;
|
|
42
|
-
disableWorkerScope();
|
|
43
|
-
expect(globalScopeModule.isBrowserScope).toBe(false);
|
|
44
|
-
expect(globalScopeModule.isWorkerScope).toBe(true);
|
|
45
|
-
expect(globalScopeModule.globalScope).toBe(mockedGlobalSelf);
|
|
46
|
-
});
|
|
47
|
-
test('should throw an error when a scope cannot be defined', async () => {
|
|
48
|
-
jest.spyOn(global, 'window', 'get').mockReturnValue(undefined);
|
|
49
|
-
await expect(() => Promise.resolve().then(() => _interopRequireWildcard(require('./global-scope')))).rejects.toThrow();
|
|
50
|
-
});
|
|
51
|
-
test('should immediately store the current location', async () => {
|
|
52
|
-
const url = _faker.faker.internet.url();
|
|
53
|
-
jest.spyOn(window, 'location', 'get').mockReturnValue(url);
|
|
54
|
-
const globalScopeModule = await Promise.resolve().then(() => _interopRequireWildcard(require('./global-scope')));
|
|
55
|
-
expect(globalScopeModule.initialLocation).toBe(url);
|
|
56
|
-
});
|
|
57
|
-
function enableWorkerScope() {
|
|
58
|
-
jest.spyOn(global, 'window', 'get').mockReturnValue(undefined);
|
|
59
|
-
class WorkerNavigator {}
|
|
60
|
-
class WorkerGlobalScope {
|
|
61
|
-
navigator = new WorkerNavigator();
|
|
62
|
-
}
|
|
63
|
-
global.WorkerGlobalScope = WorkerGlobalScope;
|
|
64
|
-
global.WorkerNavigator = WorkerNavigator;
|
|
65
|
-
jest.spyOn(global, 'navigator', 'get').mockReturnValue(new global.WorkerNavigator());
|
|
66
|
-
jest.replaceProperty(global, 'globalThis', new WorkerGlobalScope());
|
|
67
|
-
}
|
|
68
|
-
function disableWorkerScope() {
|
|
69
|
-
delete global.WorkerGlobalScope;
|
|
70
|
-
delete global.WorkerNavigator;
|
|
71
|
-
jest.restoreAllMocks();
|
|
72
|
-
}
|
|
@@ -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
|
-
});
|