@newrelic/browser-agent 0.1.230 → 1.232.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 +27 -3
- package/dist/cjs/common/browser-version/ios-version.js +4 -3
- package/dist/cjs/common/config/state/configurable.js +27 -21
- package/dist/cjs/common/config/state/info.js +1 -1
- package/dist/cjs/common/config/state/init.js +9 -1
- package/dist/cjs/common/config/state/loader-config.js +1 -1
- package/dist/cjs/common/config/state/runtime.js +26 -28
- package/dist/cjs/common/constants/env.cdn.js +29 -0
- package/dist/cjs/common/constants/env.js +32 -0
- package/dist/cjs/common/constants/env.npm.js +30 -0
- package/dist/cjs/common/context/shared-context.js +2 -1
- package/dist/cjs/common/event-emitter/contextual-ee.test.js +282 -0
- package/dist/cjs/common/event-emitter/handle.test.js +58 -0
- package/dist/cjs/common/event-emitter/register-handler.test.js +55 -0
- package/dist/cjs/common/event-listener/event-listener-opts.js +4 -2
- package/dist/cjs/common/harvest/harvest-scheduler.js +14 -11
- package/dist/cjs/common/harvest/harvest.js +5 -3
- package/dist/cjs/common/ids/id.js +14 -6
- package/dist/cjs/common/ids/id.test.js +85 -0
- package/dist/cjs/common/ids/unique-id.js +75 -51
- package/dist/cjs/common/ids/unique-id.test.js +49 -0
- package/dist/cjs/common/session/constants.js +12 -0
- package/dist/cjs/common/session/session-entity.js +278 -0
- package/dist/cjs/common/session/session-entity.test.js +436 -0
- package/dist/cjs/common/storage/first-party-cookies.js +35 -0
- package/dist/cjs/common/storage/local-memory.js +35 -0
- package/dist/cjs/common/storage/local-memory.test.js +20 -0
- package/dist/cjs/common/storage/local-storage.js +33 -0
- package/dist/cjs/common/storage/local-storage.test.js +14 -0
- package/dist/cjs/common/timer/interaction-timer.js +78 -0
- package/dist/cjs/common/timer/interaction-timer.test.js +216 -0
- package/dist/cjs/common/timer/timer.js +32 -0
- package/dist/cjs/common/timer/timer.test.js +105 -0
- package/dist/cjs/common/timing/nav-timing.js +51 -30
- package/dist/cjs/common/timing/nav-timing.test.js +192 -0
- package/dist/cjs/common/unload/eol.js +2 -2
- package/dist/cjs/common/url/clean-url.test.js +9 -0
- package/dist/cjs/common/url/encode.test.js +74 -0
- package/dist/cjs/common/url/location.js +4 -0
- package/dist/cjs/common/url/location.test.js +13 -0
- package/dist/cjs/common/url/parse-url.test.js +111 -0
- package/dist/cjs/common/url/protocol.js +2 -12
- package/dist/cjs/common/url/protocol.test.js +16 -0
- package/dist/cjs/common/util/console.js +1 -1
- package/dist/cjs/common/util/data-size.js +6 -0
- package/dist/cjs/common/util/data-size.test.js +47 -0
- package/dist/cjs/common/util/invoke.js +73 -0
- package/dist/cjs/common/util/invoke.test.js +49 -0
- package/dist/cjs/common/util/map-own.test.js +3 -3
- package/dist/cjs/common/util/obfuscate.js +1 -5
- package/dist/cjs/common/window/page-visibility.js +5 -2
- package/dist/cjs/common/wrap/index.js +0 -7
- package/dist/cjs/common/wrap/wrap-events.js +6 -9
- package/dist/cjs/common/wrap/wrap-fetch.js +6 -6
- package/dist/cjs/common/wrap/wrap-history.js +7 -6
- package/dist/cjs/common/wrap/wrap-jsonp.js +7 -6
- package/dist/cjs/common/wrap/wrap-mutation.js +7 -6
- package/dist/cjs/common/wrap/wrap-promise.js +7 -6
- package/dist/cjs/common/wrap/wrap-promise.test.js +119 -0
- package/dist/cjs/common/wrap/wrap-raf.js +6 -6
- package/dist/cjs/common/wrap/wrap-timer.js +7 -7
- package/dist/cjs/common/wrap/wrap-xhr.js +5 -6
- package/dist/cjs/features/ajax/aggregate/index.js +3 -3
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
- package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +1 -1
- package/dist/cjs/features/jserrors/aggregate/index.js +6 -6
- package/dist/cjs/features/jserrors/instrument/index.js +2 -2
- package/dist/cjs/features/metrics/aggregate/index.js +19 -9
- package/dist/cjs/features/metrics/instrument/index.js +0 -25
- package/dist/cjs/features/metrics/instrument/workers-helper.js +5 -5
- package/dist/cjs/features/page_action/aggregate/index.js +3 -3
- package/dist/cjs/features/page_view_event/aggregate/index.js +23 -9
- package/dist/cjs/features/page_view_timing/aggregate/index.js +40 -30
- package/dist/cjs/features/session_trace/aggregate/index.js +18 -15
- package/dist/cjs/features/spa/aggregate/index.js +6 -5
- package/dist/cjs/features/utils/agent-session.js +73 -0
- package/dist/cjs/features/utils/feature-base.js +1 -1
- package/dist/cjs/features/utils/instrument-base.js +12 -3
- package/dist/cjs/features/utils/lazy-loader.js +2 -2
- package/dist/cjs/loaders/agent.js +2 -2
- package/dist/cjs/loaders/api/api.js +9 -9
- package/dist/cjs/loaders/api/apiAsync.js +3 -2
- package/dist/cjs/loaders/configure/configure.js +0 -6
- package/dist/cjs/loaders/features/enabled-features.js +1 -1
- package/dist/cjs/loaders/micro-agent.js +2 -1
- package/dist/esm/common/browser-version/ios-version.js +4 -3
- package/dist/esm/common/config/state/configurable.js +26 -20
- package/dist/esm/common/config/state/info.js +1 -1
- package/dist/esm/common/config/state/init.js +9 -1
- package/dist/esm/common/config/state/loader-config.js +1 -1
- package/dist/esm/common/config/state/runtime.js +26 -28
- package/dist/esm/common/constants/env.cdn.js +20 -0
- package/dist/esm/common/constants/env.js +23 -0
- package/dist/esm/common/constants/env.npm.js +21 -0
- package/dist/esm/common/context/shared-context.js +2 -1
- package/dist/esm/common/event-emitter/contextual-ee.test.js +278 -0
- package/dist/esm/common/event-emitter/handle.test.js +54 -0
- package/dist/esm/common/event-emitter/register-handler.test.js +51 -0
- package/dist/esm/common/event-listener/event-listener-opts.js +4 -2
- package/dist/esm/common/harvest/harvest-scheduler.js +14 -11
- package/dist/esm/common/harvest/harvest.js +4 -2
- package/dist/esm/common/ids/id.js +16 -6
- package/dist/esm/common/ids/id.test.js +81 -0
- package/dist/esm/common/ids/unique-id.js +75 -51
- package/dist/esm/common/ids/unique-id.test.js +44 -0
- package/dist/esm/common/session/constants.js +3 -0
- package/dist/esm/common/session/session-entity.js +271 -0
- package/dist/esm/common/session/session-entity.test.js +434 -0
- package/dist/esm/common/storage/first-party-cookies.js +28 -0
- package/dist/esm/common/storage/local-memory.js +28 -0
- package/dist/esm/common/storage/local-memory.test.js +18 -0
- package/dist/esm/common/storage/local-storage.js +26 -0
- package/dist/esm/common/storage/local-storage.test.js +12 -0
- package/dist/esm/common/timer/interaction-timer.js +71 -0
- package/dist/esm/common/timer/interaction-timer.test.js +214 -0
- package/dist/esm/common/timer/timer.js +25 -0
- package/dist/esm/common/timer/timer.test.js +103 -0
- package/dist/esm/common/timing/nav-timing.js +51 -29
- package/dist/esm/common/timing/nav-timing.test.js +190 -0
- package/dist/esm/common/unload/eol.js +1 -1
- package/dist/esm/common/url/clean-url.test.js +7 -0
- package/dist/esm/common/url/encode.test.js +70 -0
- package/dist/esm/common/url/location.js +4 -0
- package/dist/esm/common/url/location.test.js +11 -0
- package/dist/esm/common/url/parse-url.test.js +107 -0
- package/dist/esm/common/url/protocol.js +3 -12
- package/dist/esm/common/url/protocol.test.js +14 -0
- package/dist/esm/common/util/console.js +1 -1
- package/dist/esm/common/util/data-size.js +7 -0
- package/dist/esm/common/util/data-size.test.js +45 -0
- package/dist/esm/common/util/invoke.js +66 -0
- package/dist/esm/common/util/invoke.test.js +47 -0
- package/dist/esm/common/util/map-own.test.js +3 -3
- package/dist/esm/common/util/obfuscate.js +2 -6
- package/dist/esm/common/window/page-visibility.js +5 -2
- package/dist/esm/common/wrap/index.js +1 -2
- package/dist/esm/common/wrap/wrap-events.js +6 -9
- package/dist/esm/common/wrap/wrap-fetch.js +6 -6
- package/dist/esm/common/wrap/wrap-history.js +7 -6
- package/dist/esm/common/wrap/wrap-jsonp.js +7 -6
- package/dist/esm/common/wrap/wrap-mutation.js +7 -6
- package/dist/esm/common/wrap/wrap-promise.js +7 -6
- package/dist/esm/common/wrap/wrap-promise.test.js +115 -0
- package/dist/esm/common/wrap/wrap-raf.js +6 -6
- package/dist/esm/common/wrap/wrap-timer.js +7 -7
- package/dist/esm/common/wrap/wrap-xhr.js +5 -6
- package/dist/esm/features/ajax/aggregate/index.js +3 -3
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
- package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +1 -1
- package/dist/esm/features/jserrors/aggregate/index.js +6 -6
- package/dist/esm/features/jserrors/instrument/index.js +2 -2
- package/dist/esm/features/metrics/aggregate/index.js +21 -11
- package/dist/esm/features/metrics/instrument/index.js +0 -25
- package/dist/esm/features/metrics/instrument/workers-helper.js +5 -5
- package/dist/esm/features/page_action/aggregate/index.js +3 -3
- package/dist/esm/features/page_view_event/aggregate/index.js +23 -9
- package/dist/esm/features/page_view_timing/aggregate/index.js +40 -30
- package/dist/esm/features/session_trace/aggregate/index.js +18 -15
- package/dist/esm/features/spa/aggregate/index.js +6 -5
- package/dist/esm/features/utils/agent-session.js +67 -0
- package/dist/esm/features/utils/feature-base.js +1 -1
- package/dist/esm/features/utils/instrument-base.js +7 -2
- package/dist/esm/features/utils/lazy-loader.js +2 -2
- package/dist/esm/loaders/agent.js +2 -2
- package/dist/esm/loaders/api/api.js +6 -9
- package/dist/esm/loaders/api/apiAsync.js +2 -1
- package/dist/esm/loaders/configure/configure.js +2 -8
- package/dist/esm/loaders/features/enabled-features.js +1 -1
- package/dist/types/common/config/state/configurable.d.ts.map +1 -1
- package/dist/types/common/config/state/init.d.ts.map +1 -1
- package/dist/types/common/config/state/runtime.d.ts.map +1 -1
- package/dist/types/common/constants/env.cdn.d.ts +18 -0
- package/dist/types/common/constants/env.cdn.d.ts.map +1 -0
- package/dist/types/common/constants/env.d.ts +13 -0
- package/dist/types/common/constants/env.d.ts.map +1 -0
- package/dist/types/common/constants/env.npm.d.ts +19 -0
- package/dist/types/common/constants/env.npm.d.ts.map +1 -0
- package/dist/types/common/context/shared-context.d.ts.map +1 -1
- package/dist/types/common/event-listener/event-listener-opts.d.ts +2 -2
- package/dist/types/common/event-listener/event-listener-opts.d.ts.map +1 -1
- package/dist/types/common/harvest/harvest-scheduler.d.ts +1 -0
- package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
- package/dist/types/common/harvest/harvest.d.ts.map +1 -1
- package/dist/types/common/ids/id.d.ts +11 -1
- package/dist/types/common/ids/id.d.ts.map +1 -1
- package/dist/types/common/ids/unique-id.d.ts +24 -1
- package/dist/types/common/ids/unique-id.d.ts.map +1 -1
- package/dist/types/common/session/constants.d.ts +4 -0
- package/dist/types/common/session/constants.d.ts.map +1 -0
- package/dist/types/common/session/session-entity.d.ts +72 -0
- package/dist/types/common/session/session-entity.d.ts.map +1 -0
- package/dist/types/common/storage/first-party-cookies.d.ts +8 -0
- package/dist/types/common/storage/first-party-cookies.d.ts.map +1 -0
- package/dist/types/common/storage/local-memory.d.ts +8 -0
- package/dist/types/common/storage/local-memory.d.ts.map +1 -0
- package/dist/types/common/storage/local-storage.d.ts +6 -0
- package/dist/types/common/storage/local-storage.d.ts.map +1 -0
- package/dist/types/common/timer/interaction-timer.d.ts +11 -0
- package/dist/types/common/timer/interaction-timer.d.ts.map +1 -0
- package/dist/types/common/timer/timer.d.ts +12 -0
- package/dist/types/common/timer/timer.d.ts.map +1 -0
- package/dist/types/common/timing/nav-timing.d.ts +1 -2
- package/dist/types/common/timing/nav-timing.d.ts.map +1 -1
- package/dist/types/common/unload/eol.d.ts.map +1 -1
- package/dist/types/common/url/location.d.ts +4 -0
- package/dist/types/common/url/location.d.ts.map +1 -1
- package/dist/types/common/url/parse-url.d.ts.map +1 -1
- package/dist/types/common/url/protocol.d.ts +1 -6
- package/dist/types/common/url/protocol.d.ts.map +1 -1
- package/dist/types/common/util/data-size.d.ts +7 -1
- package/dist/types/common/util/data-size.d.ts.map +1 -1
- package/dist/types/common/util/global-scope.d.ts.map +1 -1
- package/dist/types/common/util/invoke.d.ts +35 -0
- package/dist/types/common/util/invoke.d.ts.map +1 -0
- package/dist/types/common/util/obfuscate.d.ts.map +1 -1
- package/dist/types/common/window/page-visibility.d.ts +1 -1
- package/dist/types/common/window/page-visibility.d.ts.map +1 -1
- package/dist/types/common/wrap/index.d.ts +1 -2
- package/dist/types/common/wrap/index.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-history.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-jsonp.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-mutation.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-raf.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-timer.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-xhr.d.ts.map +1 -1
- package/dist/types/features/ajax/aggregate/index.d.ts +2 -2
- package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts +2 -2
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
- package/dist/types/features/metrics/aggregate/index.d.ts +2 -2
- package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/metrics/instrument/index.d.ts +0 -1
- package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
- package/dist/types/features/metrics/instrument/workers-helper.d.ts.map +1 -1
- package/dist/types/features/page_action/aggregate/index.d.ts +2 -2
- package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_event/aggregate/index.d.ts +2 -2
- 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 +3 -4
- package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/aggregate/index.d.ts +3 -3
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
- package/dist/types/features/spa/aggregate/index.d.ts +2 -2
- package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/spa/instrument/index.d.ts.map +1 -1
- package/dist/types/features/utils/agent-session.d.ts +2 -0
- package/dist/types/features/utils/agent-session.d.ts.map +1 -0
- package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
- package/dist/types/features/utils/lazy-loader.d.ts +2 -2
- package/dist/types/features/utils/lazy-loader.d.ts.map +1 -1
- package/dist/types/loaders/api/api.d.ts.map +1 -1
- package/dist/types/loaders/api/apiAsync.d.ts.map +1 -1
- package/dist/types/loaders/configure/configure.d.ts.map +1 -1
- package/package.json +12 -32
- package/src/common/browser-version/ios-version.js +4 -3
- package/src/common/config/state/configurable.js +26 -19
- package/src/common/config/state/init.js +7 -0
- package/src/common/config/state/runtime.js +7 -10
- package/src/common/constants/env.cdn.js +20 -0
- package/src/common/constants/env.js +23 -0
- package/src/common/constants/env.npm.js +21 -0
- package/src/common/context/shared-context.js +2 -1
- package/src/common/event-emitter/contextual-ee.test.js +310 -0
- package/src/common/event-emitter/handle.test.js +56 -0
- package/src/common/event-emitter/register-handler.test.js +61 -0
- package/src/common/event-listener/event-listener-opts.js +4 -4
- package/src/common/harvest/harvest-scheduler.js +12 -8
- package/src/common/harvest/harvest.js +5 -3
- package/src/common/ids/id.js +15 -6
- package/src/common/ids/id.test.js +92 -0
- package/src/common/ids/unique-id.js +77 -54
- package/src/common/ids/unique-id.test.js +58 -0
- package/src/common/session/constants.js +3 -0
- package/src/common/session/session-entity.js +271 -0
- package/src/common/session/session-entity.test.js +317 -0
- package/src/common/storage/first-party-cookies.js +31 -0
- package/src/common/storage/local-memory.js +30 -0
- package/src/common/storage/local-memory.test.js +19 -0
- package/src/common/storage/local-storage.js +28 -0
- package/src/common/storage/local-storage.test.js +17 -0
- package/src/common/timer/interaction-timer.js +75 -0
- package/src/common/timer/interaction-timer.test.js +167 -0
- package/src/common/timer/timer.js +31 -0
- package/src/common/timer/timer.test.js +100 -0
- package/src/common/timing/nav-timing.js +50 -30
- package/src/common/timing/nav-timing.test.js +161 -0
- package/src/common/unload/eol.js +2 -3
- package/src/common/url/clean-url.test.js +25 -0
- package/src/common/url/encode.test.js +80 -0
- package/src/common/url/location.js +4 -0
- package/src/common/url/location.test.js +15 -0
- package/src/common/url/parse-url.js +1 -2
- package/src/common/url/parse-url.test.js +110 -0
- package/src/common/url/protocol.js +3 -13
- package/src/common/url/protocol.test.js +18 -0
- package/src/common/util/data-size.js +6 -0
- package/src/common/util/data-size.test.js +50 -0
- package/src/common/util/global-scope.js +1 -2
- package/src/common/util/invoke.js +55 -0
- package/src/common/util/invoke.test.js +65 -0
- package/src/common/util/obfuscate.js +2 -6
- package/src/common/window/page-visibility.js +3 -3
- package/src/common/wrap/index.js +1 -2
- package/src/common/wrap/wrap-events.js +5 -5
- package/src/common/wrap/wrap-fetch.js +4 -3
- package/src/common/wrap/wrap-history.js +6 -3
- package/src/common/wrap/wrap-jsonp.js +5 -3
- package/src/common/wrap/wrap-mutation.js +6 -3
- package/src/common/wrap/wrap-promise.js +7 -6
- package/src/common/wrap/wrap-promise.test.js +140 -0
- package/src/common/wrap/wrap-raf.js +5 -3
- package/src/common/wrap/wrap-timer.js +6 -4
- package/src/common/wrap/wrap-xhr.js +4 -3
- package/src/features/ajax/aggregate/index.js +2 -2
- package/src/features/ajax/instrument/index.js +1 -1
- package/src/features/jserrors/aggregate/index.js +3 -3
- package/src/features/jserrors/instrument/index.js +4 -2
- package/src/features/metrics/aggregate/index.js +21 -7
- package/src/features/metrics/instrument/index.js +0 -30
- package/src/features/metrics/instrument/workers-helper.js +9 -6
- package/src/features/page_action/aggregate/index.js +2 -2
- package/src/features/page_view_event/aggregate/index.js +21 -9
- package/src/features/page_view_timing/aggregate/index.js +40 -29
- package/src/features/page_view_timing/long-tasks.js +10 -10
- package/src/features/session_trace/aggregate/index.js +17 -14
- package/src/features/session_trace/instrument/index.js +3 -2
- package/src/features/spa/aggregate/index.js +5 -5
- package/src/features/spa/instrument/index.js +4 -2
- package/src/features/utils/agent-session.js +68 -0
- package/src/features/utils/feature-base.js +1 -1
- package/src/features/utils/instrument-base.js +5 -2
- package/src/features/utils/lazy-loader.js +1 -1
- package/src/loaders/agent.js +1 -1
- package/src/loaders/api/api.js +3 -6
- package/src/loaders/api/apiAsync.js +2 -1
- package/src/loaders/configure/configure.js +2 -7
- package/dist/cjs/common/constants/environment-variables.js +0 -20
- package/dist/cjs/common/util/single.js +0 -23
- package/dist/cjs/common/window/session-storage.js +0 -87
- package/dist/cjs/common/wrap/wrap-console.js +0 -54
- package/dist/cjs/features/utils/aggregate-base.js +0 -13
- package/dist/esm/common/constants/environment-variables.js +0 -11
- package/dist/esm/common/util/single.js +0 -16
- package/dist/esm/common/window/session-storage.js +0 -77
- package/dist/esm/common/wrap/wrap-console.js +0 -46
- package/dist/esm/features/utils/aggregate-base.js +0 -6
- package/dist/types/common/constants/environment-variables.d.ts +0 -4
- package/dist/types/common/constants/environment-variables.d.ts.map +0 -1
- package/dist/types/common/util/single.d.ts +0 -2
- package/dist/types/common/util/single.d.ts.map +0 -1
- package/dist/types/common/window/session-storage.d.ts +0 -18
- package/dist/types/common/window/session-storage.d.ts.map +0 -1
- package/dist/types/common/wrap/wrap-console.d.ts +0 -16
- package/dist/types/common/wrap/wrap-console.d.ts.map +0 -1
- package/dist/types/features/utils/aggregate-base.d.ts +0 -4
- package/dist/types/features/utils/aggregate-base.d.ts.map +0 -1
- package/src/common/constants/environment-variables.js +0 -11
- package/src/common/util/single.js +0 -18
- package/src/common/window/session-storage.js +0 -75
- package/src/common/wrap/wrap-console.js +0 -47
- package/src/features/utils/aggregate-base.js +0 -7
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _navTiming = require("./nav-timing");
|
|
4
|
+
const offset = 123;
|
|
5
|
+
const testValues = {
|
|
6
|
+
unloadEventStart: 1,
|
|
7
|
+
redirectStart: 2,
|
|
8
|
+
unloadEventEnd: 3,
|
|
9
|
+
redirectEnd: 4,
|
|
10
|
+
fetchStart: 5,
|
|
11
|
+
domainLookupStart: 6,
|
|
12
|
+
domainLookupEnd: 7,
|
|
13
|
+
connectStart: 8,
|
|
14
|
+
secureConnectionStart: 9,
|
|
15
|
+
connectEnd: 10,
|
|
16
|
+
requestStart: 11,
|
|
17
|
+
responseStart: 12,
|
|
18
|
+
responseEnd: 13,
|
|
19
|
+
domLoading: 14,
|
|
20
|
+
domInteractive: 15,
|
|
21
|
+
domContentLoadedEventStart: 16,
|
|
22
|
+
domContentLoadedEventEnd: 17,
|
|
23
|
+
domComplete: 18,
|
|
24
|
+
loadEventStart: 19,
|
|
25
|
+
loadEventEnd: 20,
|
|
26
|
+
type: 'reload',
|
|
27
|
+
redirectCount: 22
|
|
28
|
+
};
|
|
29
|
+
const legacyTestValues = {
|
|
30
|
+
unloadEventStart: offset + 1,
|
|
31
|
+
redirectStart: offset + 2,
|
|
32
|
+
unloadEventEnd: offset + 3,
|
|
33
|
+
redirectEnd: offset + 4,
|
|
34
|
+
fetchStart: offset + 5,
|
|
35
|
+
domainLookupStart: offset + 6,
|
|
36
|
+
domainLookupEnd: offset + 7,
|
|
37
|
+
connectStart: offset + 8,
|
|
38
|
+
secureConnectionStart: offset + 9,
|
|
39
|
+
connectEnd: offset + 10,
|
|
40
|
+
requestStart: offset + 11,
|
|
41
|
+
responseStart: offset + 12,
|
|
42
|
+
responseEnd: offset + 13,
|
|
43
|
+
domLoading: offset + 14,
|
|
44
|
+
domInteractive: offset + 15,
|
|
45
|
+
domContentLoadedEventStart: offset + 16,
|
|
46
|
+
domContentLoadedEventEnd: offset + 17,
|
|
47
|
+
domComplete: offset + 18,
|
|
48
|
+
loadEventStart: offset + 19,
|
|
49
|
+
loadEventEnd: offset + 20,
|
|
50
|
+
type: 'reload',
|
|
51
|
+
redirectCount: offset + 22
|
|
52
|
+
};
|
|
53
|
+
const expectedPT = {
|
|
54
|
+
of: offset,
|
|
55
|
+
n: 0,
|
|
56
|
+
u: 1,
|
|
57
|
+
r: 2,
|
|
58
|
+
ue: 3,
|
|
59
|
+
re: 4,
|
|
60
|
+
f: 5,
|
|
61
|
+
dn: 6,
|
|
62
|
+
dne: 7,
|
|
63
|
+
c: 8,
|
|
64
|
+
s: 9,
|
|
65
|
+
ce: 10,
|
|
66
|
+
rq: 11,
|
|
67
|
+
rp: 12,
|
|
68
|
+
rpe: 13,
|
|
69
|
+
dl: 14,
|
|
70
|
+
di: 15,
|
|
71
|
+
ds: 16,
|
|
72
|
+
de: 17,
|
|
73
|
+
dc: 18,
|
|
74
|
+
l: 19,
|
|
75
|
+
le: 20
|
|
76
|
+
};
|
|
77
|
+
const expectedPN = {
|
|
78
|
+
ty: 1,
|
|
79
|
+
rc: 22
|
|
80
|
+
};
|
|
81
|
+
describe('addPT()', () => {
|
|
82
|
+
test('an output object is populated with valid values', () => {
|
|
83
|
+
const output = (0, _navTiming.addPT)(offset, testValues, {});
|
|
84
|
+
expect(output).toEqual(expectedPT);
|
|
85
|
+
});
|
|
86
|
+
test('an object with invalid values is handled', () => {
|
|
87
|
+
const output = (0, _navTiming.addPT)(offset, {
|
|
88
|
+
...testValues,
|
|
89
|
+
invalidValue: 'test'
|
|
90
|
+
}, {});
|
|
91
|
+
expect(output).toEqual(expectedPT);
|
|
92
|
+
const output2 = (0, _navTiming.addPT)(offset, {
|
|
93
|
+
...testValues,
|
|
94
|
+
loadEventEnd: -1
|
|
95
|
+
}, {});
|
|
96
|
+
let expected = {
|
|
97
|
+
...expectedPT
|
|
98
|
+
};
|
|
99
|
+
delete expected.le;
|
|
100
|
+
expect(output2).toEqual(expected);
|
|
101
|
+
const output3 = (0, _navTiming.addPT)(offset, {
|
|
102
|
+
...testValues,
|
|
103
|
+
loadEventEnd: 'test'
|
|
104
|
+
}, {});
|
|
105
|
+
expected = {
|
|
106
|
+
...expectedPT
|
|
107
|
+
};
|
|
108
|
+
delete expected.le;
|
|
109
|
+
expect(output3).toEqual(expected);
|
|
110
|
+
const output4 = (0, _navTiming.addPT)(offset, {
|
|
111
|
+
...testValues,
|
|
112
|
+
loadEventEnd: null
|
|
113
|
+
}, {});
|
|
114
|
+
expected = {
|
|
115
|
+
...expectedPT
|
|
116
|
+
};
|
|
117
|
+
delete expected.le;
|
|
118
|
+
expect(output4).toEqual(expected);
|
|
119
|
+
const legacyoutput = (0, _navTiming.addPT)(offset, {
|
|
120
|
+
...legacyTestValues,
|
|
121
|
+
invalidValue: 'test'
|
|
122
|
+
}, {}, true);
|
|
123
|
+
expect(legacyoutput).toEqual(expectedPT);
|
|
124
|
+
const legacyoutput2 = (0, _navTiming.addPT)(offset, {
|
|
125
|
+
...legacyTestValues,
|
|
126
|
+
loadEventEnd: -1
|
|
127
|
+
}, {}, true);
|
|
128
|
+
let legacyexpected = {
|
|
129
|
+
...expectedPT
|
|
130
|
+
};
|
|
131
|
+
delete legacyexpected.le;
|
|
132
|
+
expect(legacyoutput2).toEqual(expected);
|
|
133
|
+
const legacyoutput3 = (0, _navTiming.addPT)(offset, {
|
|
134
|
+
...legacyTestValues,
|
|
135
|
+
loadEventEnd: 'test'
|
|
136
|
+
}, {}, true);
|
|
137
|
+
legacyexpected = {
|
|
138
|
+
...expectedPT
|
|
139
|
+
};
|
|
140
|
+
delete legacyexpected.le;
|
|
141
|
+
expect(legacyoutput3).toEqual(legacyexpected);
|
|
142
|
+
const legacyoutput4 = (0, _navTiming.addPT)(offset, {
|
|
143
|
+
...legacyTestValues,
|
|
144
|
+
loadEventEnd: null
|
|
145
|
+
}, {}, true);
|
|
146
|
+
legacyexpected = {
|
|
147
|
+
...expectedPT
|
|
148
|
+
};
|
|
149
|
+
delete legacyexpected.le;
|
|
150
|
+
expect(legacyoutput4).toEqual(legacyexpected);
|
|
151
|
+
});
|
|
152
|
+
test('rounds values to integers', () => {
|
|
153
|
+
const output = (0, _navTiming.addPT)(offset, {
|
|
154
|
+
unloadEventStart: 3.14159
|
|
155
|
+
}, {});
|
|
156
|
+
expect(output.u).toEqual(3);
|
|
157
|
+
const legacyoutput = (0, _navTiming.addPT)(0, {
|
|
158
|
+
unloadEventStart: 3.14159
|
|
159
|
+
}, {}, true);
|
|
160
|
+
expect(legacyoutput.u).toEqual(3);
|
|
161
|
+
});
|
|
162
|
+
test('adds entries to navTimingValues', () => {
|
|
163
|
+
const beforeLength = _navTiming.navTimingValues.length;
|
|
164
|
+
(0, _navTiming.addPT)(offset, {
|
|
165
|
+
testValues
|
|
166
|
+
}, {});
|
|
167
|
+
const afterLength = _navTiming.navTimingValues.length;
|
|
168
|
+
expect(afterLength - beforeLength).toEqual(21); // 20 + value of n
|
|
169
|
+
|
|
170
|
+
const legacybeforeLength = _navTiming.navTimingValues.length;
|
|
171
|
+
(0, _navTiming.addPT)(offset, {
|
|
172
|
+
legacyTestValues
|
|
173
|
+
}, {}, true);
|
|
174
|
+
const legacyafterLength = _navTiming.navTimingValues.length;
|
|
175
|
+
expect(legacyafterLength - legacybeforeLength).toEqual(21); // 20 + value of n
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
describe('addPN()', () => {
|
|
180
|
+
test('an output object is populated with valid values', () => {
|
|
181
|
+
const output = (0, _navTiming.addPN)(testValues, {});
|
|
182
|
+
expect(output).toEqual(expectedPN);
|
|
183
|
+
});
|
|
184
|
+
test('adds entries to navTimingValues', () => {
|
|
185
|
+
const beforeLength = _navTiming.navTimingValues.length;
|
|
186
|
+
(0, _navTiming.addPN)(offset, {
|
|
187
|
+
testValues
|
|
188
|
+
}, {});
|
|
189
|
+
const afterLength = _navTiming.navTimingValues.length;
|
|
190
|
+
expect(afterLength - beforeLength).toEqual(2);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.subscribeToEOL = subscribeToEOL;
|
|
7
7
|
var _firefoxVersion = require("../browser-version/firefox-version");
|
|
8
8
|
var _eventListenerOpts = require("../event-listener/event-listener-opts");
|
|
9
|
-
var
|
|
9
|
+
var _invoke = require("../util/invoke");
|
|
10
10
|
var _globalScope = require("../util/global-scope");
|
|
11
11
|
var _pageVisibility = require("../window/page-visibility");
|
|
12
12
|
/*
|
|
@@ -40,7 +40,7 @@ function subscribeToEOL(cb, allowBFCache) {
|
|
|
40
40
|
(0, _eventListenerOpts.windowAddEventListener)('pagehide', cb); // when user navigates away, and because safari iOS v14.4- doesn't fully support vis change
|
|
41
41
|
// --this ought to be removed once support for version below 14.5 phases out
|
|
42
42
|
} else {
|
|
43
|
-
var oneCall = (0,
|
|
43
|
+
var oneCall = (0, _invoke.single)(cb);
|
|
44
44
|
|
|
45
45
|
// Firefox has a bug wherein a slow-loading resource loaded from the 'pagehide'
|
|
46
46
|
// or 'unload' event will delay the 'load' event firing on the next page load.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _cleanUrl = require("./clean-url");
|
|
4
|
+
test.each([['http://domain.com/path?query=5', 'http://domain.com/path'], ['http://domain.com/path#fragment', 'http://domain.com/path'], ['http://domain.com/path?query=5#fragment', 'http://domain.com/path'], ['http://domain.com/path?query=5?dumb#fragment', 'http://domain.com/path'], ['http://domain.com/path?query=5#fragment#dumb', 'http://domain.com/path'], ['http://domain.com/path?query=5#fragment#dumb?additional_query', 'http://domain.com/path'], ['http://domain.com/path?query=5#fragment/silly/dumber#dumbest?additional_query=silly#what_is_this_even', 'http://domain.com/path']])('cleanURL should remove hash', (input, expected) => {
|
|
5
|
+
expect((0, _cleanUrl.cleanURL)(input)).toEqual(expected);
|
|
6
|
+
});
|
|
7
|
+
test.each([['http://domain.com/path?query=5', 'http://domain.com/path'], ['http://domain.com/path#fragment', 'http://domain.com/path#fragment'], ['http://domain.com/path?query=5#fragment', 'http://domain.com/path#fragment'], ['http://domain.com/path?query=5?dumb#fragment', 'http://domain.com/path#fragment'], ['http://domain.com/path?query=5#fragment#dumb', 'http://domain.com/path#fragment#dumb'], ['http://domain.com/path?query=5#fragment#dumb?additional_query', 'http://domain.com/path#fragment#dumb'], ['http://domain.com/path?query=5#fragment/silly/dumber#dumbest?additional_query=silly#what_is_this_even', 'http://domain.com/path#fragment/silly/dumber#dumbest']])('cleanURL should retain hash if second argument is true', (input, expected) => {
|
|
8
|
+
expect((0, _cleanUrl.cleanURL)(input, true)).toEqual(expected);
|
|
9
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var encode = _interopRequireWildcard(require("./encode"));
|
|
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
|
+
describe('query string encoding', () => {
|
|
7
|
+
test('escapes string components except safe characters', () => {
|
|
8
|
+
const input = 'Asdf:, :, /@$;';
|
|
9
|
+
const expected = 'Asdf:,%20:,%20/@$;';
|
|
10
|
+
expect(encode.qs(input)).toEqual(expected);
|
|
11
|
+
});
|
|
12
|
+
test('null and undefined value returns \'null\'', () => {
|
|
13
|
+
expect(encode.qs(null)).toEqual('null');
|
|
14
|
+
expect(encode.qs(undefined)).toEqual('null');
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
describe('fromArray encoding', () => {
|
|
18
|
+
test('cuts cleanly at end of byte', () => {
|
|
19
|
+
const input = ['a', 'b', 'c'];
|
|
20
|
+
const expected = 'ab';
|
|
21
|
+
expect(encode.fromArray(input, 2)).toEqual(expected);
|
|
22
|
+
});
|
|
23
|
+
test('fall back to largest whole chunk', () => {
|
|
24
|
+
const input = ['aa', 'bb', 'cc'];
|
|
25
|
+
const expected = 'aabb';
|
|
26
|
+
expect(encode.fromArray(input, 5)).toEqual(expected);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe('object encoding', () => {
|
|
30
|
+
test('cuts cleanly at end of byte', () => {
|
|
31
|
+
const input = {
|
|
32
|
+
foo: [1, 2, 3]
|
|
33
|
+
};
|
|
34
|
+
const expected = '&foo=%5B1,2%5D';
|
|
35
|
+
expect(encode.obj(input, 12)).toEqual(expected);
|
|
36
|
+
});
|
|
37
|
+
test('fall back to largest whole chunk', () => {
|
|
38
|
+
const input = {
|
|
39
|
+
bar: ['a', 'b', 'c']
|
|
40
|
+
};
|
|
41
|
+
const expected = '&bar=%5B%22a%22,%22b%22%5D';
|
|
42
|
+
expect(encode.obj(input, 30)).toEqual(expected);
|
|
43
|
+
});
|
|
44
|
+
test('handles circular objects', () => {
|
|
45
|
+
const circular = {};
|
|
46
|
+
circular.circular = circular;
|
|
47
|
+
const input = {
|
|
48
|
+
bar: ['a', circular, 'c']
|
|
49
|
+
};
|
|
50
|
+
const expected = '&bar=%5B%22a%22,%7B%7D,%22c%22%5D';
|
|
51
|
+
expect(encode.obj(input, 1000)).toEqual(expected);
|
|
52
|
+
});
|
|
53
|
+
test('handles circular arrays', () => {
|
|
54
|
+
const circular = [];
|
|
55
|
+
circular.push(circular);
|
|
56
|
+
const input = {
|
|
57
|
+
bar: ['a', circular, 'c']
|
|
58
|
+
};
|
|
59
|
+
const expected = '&bar=%5B%22a%22,%5Bnull%5D,%22c%22%5D';
|
|
60
|
+
expect(encode.obj(input, 1000)).toEqual(expected);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe('encode key value pairs as query params', () => {
|
|
64
|
+
test('ignores input when value is null or undefined', () => {
|
|
65
|
+
expect(encode.param('foo', null)).toEqual('');
|
|
66
|
+
expect(encode.param('foo', undefined)).toEqual('');
|
|
67
|
+
});
|
|
68
|
+
test('encodes key value pair correctly', () => {
|
|
69
|
+
expect(encode.param('foo', 'bar')).toEqual('&foo=bar');
|
|
70
|
+
});
|
|
71
|
+
test('ignores input when value is not a string', () => {
|
|
72
|
+
expect(encode.param('foo', {})).toEqual('');
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -9,6 +9,10 @@ exports.getLocation = getLocation;
|
|
|
9
9
|
* SPDX-License-Identifier: Apache-2.0
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* This method only exists to support testing in JIL and can be removed once tests are migrated to WDIO.
|
|
14
|
+
* @returns global scope location
|
|
15
|
+
*/
|
|
12
16
|
function getLocation() {
|
|
13
17
|
return '' + location;
|
|
14
18
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _faker = require("@faker-js/faker");
|
|
4
|
+
var _location = require("./location");
|
|
5
|
+
test('should always return a string', () => {
|
|
6
|
+
jest.spyOn(window, 'location', 'get').mockReturnValue({});
|
|
7
|
+
expect(typeof (0, _location.getLocation)()).toEqual('string');
|
|
8
|
+
});
|
|
9
|
+
test('should return window location', () => {
|
|
10
|
+
const expected = _faker.faker.internet.url();
|
|
11
|
+
jest.spyOn(window, 'location', 'get').mockReturnValue(expected);
|
|
12
|
+
expect((0, _location.getLocation)()).toEqual(expected);
|
|
13
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
});
|
|
@@ -3,23 +3,13 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.isFileProtocol = isFileProtocol;
|
|
7
7
|
var _globalScope = require("../util/global-scope");
|
|
8
8
|
/*
|
|
9
9
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
10
10
|
* SPDX-License-Identifier: Apache-2.0
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
const protocol = {
|
|
14
|
-
isFileProtocol: isFileProtocol,
|
|
15
|
-
supportabilityMetricSent: false
|
|
16
|
-
};
|
|
17
|
-
exports.protocol = protocol;
|
|
18
13
|
function isFileProtocol() {
|
|
19
|
-
|
|
20
|
-
if (isFile) {
|
|
21
|
-
//metrics.recordSupportability('Generic/FileProtocol/Detected') -- may be implemented later? Probably make sure it's once per window
|
|
22
|
-
protocol.supportabilityMetricSent = true;
|
|
23
|
-
}
|
|
24
|
-
return isFile;
|
|
14
|
+
return Boolean(_globalScope.globalScope?.location?.protocol === 'file:');
|
|
25
15
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _faker = require("@faker-js/faker");
|
|
4
|
+
var _protocol = require("./protocol");
|
|
5
|
+
test('should return true when location url contains file protocol', () => {
|
|
6
|
+
jest.spyOn(window, 'location', 'get').mockReturnValue({
|
|
7
|
+
protocol: 'file:'
|
|
8
|
+
});
|
|
9
|
+
expect((0, _protocol.isFileProtocol)()).toEqual(true);
|
|
10
|
+
});
|
|
11
|
+
test('should return false when location url does not contains file protocol', () => {
|
|
12
|
+
jest.spyOn(window, 'location', 'get').mockReturnValue({
|
|
13
|
+
protocol: 'http:'
|
|
14
|
+
});
|
|
15
|
+
expect((0, _protocol.isFileProtocol)()).toEqual(false);
|
|
16
|
+
});
|
|
@@ -10,6 +10,12 @@ var _stringify = require("./stringify");
|
|
|
10
10
|
* SPDX-License-Identifier: Apache-2.0
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Returns the size of the provided data. Designed for measuring XHR responses.
|
|
15
|
+
*
|
|
16
|
+
* @param {*} data - The data to be measured.
|
|
17
|
+
* @returns {(number|undefined)} - The size of the data or undefined if size cannot be determined.
|
|
18
|
+
*/
|
|
13
19
|
function dataSize(data) {
|
|
14
20
|
if (typeof data === 'string' && data.length) return data.length;
|
|
15
21
|
if (typeof data !== 'object') return undefined;
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.debounce = debounce;
|
|
7
|
+
exports.single = single;
|
|
8
|
+
/**
|
|
9
|
+
* Reduce the invocation of the supplied function so that it is only invoked
|
|
10
|
+
* once within a given timeout.
|
|
11
|
+
*
|
|
12
|
+
* If `wait` is `0`, the function will be invoked during the next tick.
|
|
13
|
+
* If `options.leading` is false or not provided, the function will be invoked
|
|
14
|
+
* N milliseconds after the last invocation of the returned function where
|
|
15
|
+
* N is the `timeout` value.
|
|
16
|
+
* If `options.leading` is true, the function will be invoked immediately upon
|
|
17
|
+
* the first invocation of the returned function and not again for N milliseconds
|
|
18
|
+
* where N is the `timeout` value.
|
|
19
|
+
* @param {function} func Function whose invocation should be limited so it is only invoked
|
|
20
|
+
* once within a given timeout period.
|
|
21
|
+
* @param {number} timeout Time in milliseconds that the function should only be invoked
|
|
22
|
+
* once within.
|
|
23
|
+
* @param {object} options Debounce options
|
|
24
|
+
* @param {boolean} options.leading Forces the function to be invoked on the first
|
|
25
|
+
* invocation of the returned function instead of N milliseconds after the last
|
|
26
|
+
* invocation.
|
|
27
|
+
* @returns {function} A wrapping function that will ensure the provided function
|
|
28
|
+
* is invoked only once within the given timeout.
|
|
29
|
+
*/
|
|
30
|
+
function debounce(func) {
|
|
31
|
+
var _this = this;
|
|
32
|
+
let timeout = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 500;
|
|
33
|
+
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
34
|
+
const leading = options?.leading || false;
|
|
35
|
+
let timer;
|
|
36
|
+
return function () {
|
|
37
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
38
|
+
args[_key] = arguments[_key];
|
|
39
|
+
}
|
|
40
|
+
if (leading && timer === undefined) {
|
|
41
|
+
func.apply(_this, args);
|
|
42
|
+
timer = setTimeout(() => timer = clearTimeout(timer), timeout);
|
|
43
|
+
}
|
|
44
|
+
if (!leading) {
|
|
45
|
+
clearTimeout(timer);
|
|
46
|
+
timer = setTimeout(() => {
|
|
47
|
+
func.apply(_this, args);
|
|
48
|
+
}, timeout);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Reduce the invocation of the supplied function so that it is only invoked
|
|
55
|
+
* once.
|
|
56
|
+
* @param {function} func Function whose invocation should be limited so it is only invoked
|
|
57
|
+
* once.
|
|
58
|
+
* @returns {function} A wrapping function that will ensure the provided function
|
|
59
|
+
* is invoked only once.
|
|
60
|
+
*/
|
|
61
|
+
function single(func) {
|
|
62
|
+
var _this2 = this;
|
|
63
|
+
let called = false;
|
|
64
|
+
return function () {
|
|
65
|
+
if (!called) {
|
|
66
|
+
called = true;
|
|
67
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
68
|
+
args[_key2] = arguments[_key2];
|
|
69
|
+
}
|
|
70
|
+
func.apply(_this2, args);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
}
|