@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,214 @@
|
|
|
1
|
+
import { InteractionTimer } from './interaction-timer';
|
|
2
|
+
jest.useFakeTimers();
|
|
3
|
+
let now;
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
now = Date.now();
|
|
6
|
+
jest.setSystemTime(now);
|
|
7
|
+
});
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
jest.clearAllMocks();
|
|
10
|
+
});
|
|
11
|
+
describe('constructor', () => {
|
|
12
|
+
test('appropriate properties are set with valid values -- no refresh', () => {
|
|
13
|
+
const timer = new InteractionTimer({
|
|
14
|
+
onEnd: jest.fn()
|
|
15
|
+
}, 100);
|
|
16
|
+
const requiredKeys = ['onEnd', 'initialMs', 'startTimestamp', 'timer'];
|
|
17
|
+
expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy();
|
|
18
|
+
});
|
|
19
|
+
test('appropriate properties are set with valid values -- with refresh', () => {
|
|
20
|
+
const timer = new InteractionTimer({
|
|
21
|
+
onEnd: jest.fn()
|
|
22
|
+
}, 100);
|
|
23
|
+
const requiredKeys = ['onEnd', 'refresh', 'initialMs', 'startTimestamp', 'timer'];
|
|
24
|
+
expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy();
|
|
25
|
+
});
|
|
26
|
+
test('required keys are enforced', () => {
|
|
27
|
+
try {
|
|
28
|
+
new InteractionTimer({}, 100);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
expect(e).toEqual(new Error('onEnd handler is required'));
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
new InteractionTimer({
|
|
34
|
+
onEnd: jest.fn()
|
|
35
|
+
});
|
|
36
|
+
} catch (e) {
|
|
37
|
+
expect(e).toEqual(new Error('ms duration is required'));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
test('refresh type timers set event listeners', () => {
|
|
41
|
+
// eslint-disable-next-line
|
|
42
|
+
let ee = {
|
|
43
|
+
on: jest.fn().mockImplementation((evt, cb) => {
|
|
44
|
+
cb([{
|
|
45
|
+
type: 'click'
|
|
46
|
+
}]);
|
|
47
|
+
})
|
|
48
|
+
};
|
|
49
|
+
let it = new InteractionTimer({
|
|
50
|
+
onEnd: jest.fn(),
|
|
51
|
+
onRefresh: jest.fn(),
|
|
52
|
+
ee
|
|
53
|
+
}, 100);
|
|
54
|
+
// scroll, keypress, click
|
|
55
|
+
expect(ee.on).toHaveBeenCalledTimes(1);
|
|
56
|
+
expect(it.onRefresh).toHaveBeenCalledTimes(1);
|
|
57
|
+
|
|
58
|
+
// eslint-disable-next-line
|
|
59
|
+
ee = {
|
|
60
|
+
on: jest.fn().mockImplementation((evt, cb) => {
|
|
61
|
+
cb([{
|
|
62
|
+
type: 'scroll'
|
|
63
|
+
}]);
|
|
64
|
+
})
|
|
65
|
+
};
|
|
66
|
+
it = new InteractionTimer({
|
|
67
|
+
onEnd: jest.fn(),
|
|
68
|
+
onRefresh: jest.fn(),
|
|
69
|
+
ee
|
|
70
|
+
}, 100);
|
|
71
|
+
// scroll, keypress, click
|
|
72
|
+
expect(ee.on).toHaveBeenCalledTimes(1);
|
|
73
|
+
expect(it.onRefresh).toHaveBeenCalledTimes(1);
|
|
74
|
+
|
|
75
|
+
// eslint-disable-next-line
|
|
76
|
+
ee = {
|
|
77
|
+
on: jest.fn().mockImplementation((evt, cb) => {
|
|
78
|
+
cb([{
|
|
79
|
+
type: 'keydown'
|
|
80
|
+
}]);
|
|
81
|
+
})
|
|
82
|
+
};
|
|
83
|
+
it = new InteractionTimer({
|
|
84
|
+
onEnd: jest.fn(),
|
|
85
|
+
onRefresh: jest.fn(),
|
|
86
|
+
ee
|
|
87
|
+
}, 100);
|
|
88
|
+
// scroll, keypress, click
|
|
89
|
+
expect(ee.on).toHaveBeenCalledTimes(1);
|
|
90
|
+
expect(it.onRefresh).toHaveBeenCalledTimes(1);
|
|
91
|
+
const aelSpy = jest.spyOn(document, 'addEventListener');
|
|
92
|
+
// eslint-disable-next-line
|
|
93
|
+
ee = {
|
|
94
|
+
on: jest.fn().mockImplementation((evt, cb) => {
|
|
95
|
+
cb([{
|
|
96
|
+
type: 'keydown'
|
|
97
|
+
}]);
|
|
98
|
+
})
|
|
99
|
+
};
|
|
100
|
+
it = new InteractionTimer({
|
|
101
|
+
onEnd: jest.fn(),
|
|
102
|
+
onRefresh: jest.fn(),
|
|
103
|
+
ee
|
|
104
|
+
}, 100);
|
|
105
|
+
// visibility change
|
|
106
|
+
expect(aelSpy).toHaveBeenCalledTimes(1);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
describe('create()', () => {
|
|
110
|
+
test('Create sets a timeout that can execute a cb', () => {
|
|
111
|
+
const timer = new InteractionTimer({
|
|
112
|
+
onEnd: jest.fn()
|
|
113
|
+
}, 100);
|
|
114
|
+
expect(timer.timer).toBeTruthy();
|
|
115
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
116
|
+
jest.runOnlyPendingTimers();
|
|
117
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(1);
|
|
118
|
+
});
|
|
119
|
+
test('Create can fallback to use defaults', () => {
|
|
120
|
+
let called = 0;
|
|
121
|
+
const timer1 = new InteractionTimer({
|
|
122
|
+
onEnd: jest.fn()
|
|
123
|
+
}, 100);
|
|
124
|
+
timer1.create();
|
|
125
|
+
const timer2 = new InteractionTimer({
|
|
126
|
+
onEnd: jest.fn()
|
|
127
|
+
}, 100);
|
|
128
|
+
timer2.create(timer2.onEnd);
|
|
129
|
+
const timer3 = new InteractionTimer({
|
|
130
|
+
onEnd: jest.fn()
|
|
131
|
+
}, 100);
|
|
132
|
+
timer3.create(undefined, 100);
|
|
133
|
+
jest.runAllTimers(200);
|
|
134
|
+
expect(timer1.onEnd).toHaveBeenCalledTimes(1);
|
|
135
|
+
expect(timer2.onEnd).toHaveBeenCalledTimes(1);
|
|
136
|
+
expect(timer3.onEnd).toHaveBeenCalledTimes(1);
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
describe('refresh()', () => {
|
|
140
|
+
test('refresh prevents the callback from firing', () => {
|
|
141
|
+
const timer = new InteractionTimer({
|
|
142
|
+
onEnd: jest.fn(),
|
|
143
|
+
onRefresh: jest.fn()
|
|
144
|
+
}, 100);
|
|
145
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
146
|
+
jest.advanceTimersByTime(75);
|
|
147
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
148
|
+
timer.refresh();
|
|
149
|
+
jest.advanceTimersByTime(75);
|
|
150
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
151
|
+
jest.advanceTimersByTime(100);
|
|
152
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(1);
|
|
153
|
+
});
|
|
154
|
+
test('refresh executes a callback for consumers', () => {
|
|
155
|
+
const timer = new InteractionTimer({
|
|
156
|
+
onEnd: jest.fn(),
|
|
157
|
+
onRefresh: jest.fn()
|
|
158
|
+
}, 100);
|
|
159
|
+
timer.refresh();
|
|
160
|
+
expect(timer.onRefresh).toHaveBeenCalledTimes(1);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
describe('pause()', () => {
|
|
164
|
+
test('pause prevents the callback from firing', () => {
|
|
165
|
+
const timer = new InteractionTimer({
|
|
166
|
+
onEnd: jest.fn()
|
|
167
|
+
}, 100);
|
|
168
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
169
|
+
timer.pause();
|
|
170
|
+
jest.advanceTimersByTime(150);
|
|
171
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
172
|
+
});
|
|
173
|
+
test('pause sets remainingMs timestamp', () => {
|
|
174
|
+
const timer = new InteractionTimer({
|
|
175
|
+
onEnd: jest.fn()
|
|
176
|
+
}, 100);
|
|
177
|
+
expect(timer.remainingMs).toEqual(undefined);
|
|
178
|
+
timer.pause();
|
|
179
|
+
expect(timer.remainingMs).toEqual(timer.initialMs - (now - timer.startTimestamp));
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
describe('clear()', () => {
|
|
183
|
+
test('clear prevents the callback from firing and deletes the pointer', () => {
|
|
184
|
+
const timer = new InteractionTimer({
|
|
185
|
+
onEnd: jest.fn()
|
|
186
|
+
}, 100);
|
|
187
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
188
|
+
timer.clear();
|
|
189
|
+
jest.advanceTimersByTime(150);
|
|
190
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
191
|
+
expect(timer.timer).toEqual(null);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
describe('end()', () => {
|
|
195
|
+
test('end clears the callback and calls the onEnd callback', () => {
|
|
196
|
+
const timer = new InteractionTimer({
|
|
197
|
+
onEnd: jest.fn()
|
|
198
|
+
}, 100);
|
|
199
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
200
|
+
timer.end();
|
|
201
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(1);
|
|
202
|
+
expect(timer.timer).toEqual(null);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
describe('isValid', () => {
|
|
206
|
+
test('isValid validates timeStamps', () => {
|
|
207
|
+
const timer = new InteractionTimer({
|
|
208
|
+
onEnd: jest.fn()
|
|
209
|
+
}, 100);
|
|
210
|
+
expect(timer.isValid()).toEqual(true);
|
|
211
|
+
timer.startTimestamp -= 100;
|
|
212
|
+
expect(timer.isValid()).toEqual(false);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class Timer {
|
|
2
|
+
constructor(opts, ms) {
|
|
3
|
+
if (!opts.onEnd) throw new Error('onEnd handler is required');
|
|
4
|
+
if (!ms) throw new Error('ms duration is required');
|
|
5
|
+
this.onEnd = opts.onEnd;
|
|
6
|
+
this.initialMs = ms;
|
|
7
|
+
this.startTimestamp = Date.now();
|
|
8
|
+
this.timer = this.create(this.onEnd, ms);
|
|
9
|
+
}
|
|
10
|
+
create(cb, ms) {
|
|
11
|
+
if (this.timer) this.clear();
|
|
12
|
+
return setTimeout(() => cb ? cb() : this.onEnd(), ms || this.initialMs);
|
|
13
|
+
}
|
|
14
|
+
clear() {
|
|
15
|
+
clearTimeout(this.timer);
|
|
16
|
+
this.timer = null;
|
|
17
|
+
}
|
|
18
|
+
end() {
|
|
19
|
+
this.clear();
|
|
20
|
+
this.onEnd();
|
|
21
|
+
}
|
|
22
|
+
isValid() {
|
|
23
|
+
return this.initialMs - (Date.now() - this.startTimestamp) > 0;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Timer } from './timer';
|
|
2
|
+
jest.useFakeTimers();
|
|
3
|
+
let now;
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
now = Date.now();
|
|
6
|
+
jest.setSystemTime(now);
|
|
7
|
+
});
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
jest.clearAllMocks();
|
|
10
|
+
});
|
|
11
|
+
describe('constructor', () => {
|
|
12
|
+
test('appropriate properties are set with valid values -- no refresh', () => {
|
|
13
|
+
const timer = new Timer({
|
|
14
|
+
onEnd: jest.fn()
|
|
15
|
+
}, 100);
|
|
16
|
+
const requiredKeys = ['onEnd', 'initialMs', 'startTimestamp', 'timer'];
|
|
17
|
+
expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy();
|
|
18
|
+
});
|
|
19
|
+
test('appropriate properties are set with valid values -- with refresh', () => {
|
|
20
|
+
const timer = new Timer({
|
|
21
|
+
onEnd: jest.fn()
|
|
22
|
+
}, 100);
|
|
23
|
+
const requiredKeys = ['onEnd', 'initialMs', 'startTimestamp', 'timer'];
|
|
24
|
+
expect(requiredKeys.every(rk => !!timer[rk])).toBeTruthy();
|
|
25
|
+
});
|
|
26
|
+
test('required keys are enforced', () => {
|
|
27
|
+
try {
|
|
28
|
+
new Timer({}, 100);
|
|
29
|
+
} catch (e) {
|
|
30
|
+
expect(e).toEqual(new Error('onEnd handler is required'));
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
new Timer({
|
|
34
|
+
onEnd: jest.fn()
|
|
35
|
+
});
|
|
36
|
+
} catch (e) {
|
|
37
|
+
expect(e).toEqual(new Error('ms duration is required'));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe('create()', () => {
|
|
42
|
+
test('Create sets a timeout that can execute a cb', () => {
|
|
43
|
+
const timer = new Timer({
|
|
44
|
+
onEnd: jest.fn()
|
|
45
|
+
}, 100);
|
|
46
|
+
expect(timer.timer).toBeTruthy();
|
|
47
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
48
|
+
jest.runOnlyPendingTimers();
|
|
49
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(1);
|
|
50
|
+
});
|
|
51
|
+
test('Create can fallback to use defaults', () => {
|
|
52
|
+
let called = 0;
|
|
53
|
+
const timer1 = new Timer({
|
|
54
|
+
onEnd: jest.fn()
|
|
55
|
+
}, 100);
|
|
56
|
+
timer1.create();
|
|
57
|
+
const timer2 = new Timer({
|
|
58
|
+
onEnd: jest.fn()
|
|
59
|
+
}, 100);
|
|
60
|
+
timer2.create(timer2.onEnd);
|
|
61
|
+
const timer3 = new Timer({
|
|
62
|
+
onEnd: jest.fn()
|
|
63
|
+
}, 100);
|
|
64
|
+
timer3.create(undefined, 100);
|
|
65
|
+
jest.runAllTimers(200);
|
|
66
|
+
expect(timer1.onEnd).toHaveBeenCalledTimes(1);
|
|
67
|
+
expect(timer2.onEnd).toHaveBeenCalledTimes(1);
|
|
68
|
+
expect(timer3.onEnd).toHaveBeenCalledTimes(1);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
describe('clear()', () => {
|
|
72
|
+
test('clear prevents the callback from firing and deletes the pointer', () => {
|
|
73
|
+
const timer = new Timer({
|
|
74
|
+
onEnd: jest.fn()
|
|
75
|
+
}, 100);
|
|
76
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
77
|
+
timer.clear();
|
|
78
|
+
jest.advanceTimersByTime(150);
|
|
79
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
80
|
+
expect(timer.timer).toEqual(null);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
describe('end()', () => {
|
|
84
|
+
test('end clears the callback and calls the onEnd callback', () => {
|
|
85
|
+
const timer = new Timer({
|
|
86
|
+
onEnd: jest.fn()
|
|
87
|
+
}, 100);
|
|
88
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(0);
|
|
89
|
+
timer.end();
|
|
90
|
+
expect(timer.onEnd).toHaveBeenCalledTimes(1);
|
|
91
|
+
expect(timer.timer).toEqual(null);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
describe('isValid', () => {
|
|
95
|
+
test('isValid validates timeStamps', () => {
|
|
96
|
+
const timer = new Timer({
|
|
97
|
+
onEnd: jest.fn()
|
|
98
|
+
}, 100);
|
|
99
|
+
expect(timer.isValid()).toEqual(true);
|
|
100
|
+
timer.startTimestamp -= 100;
|
|
101
|
+
expect(timer.isValid()).toEqual(false);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -25,43 +25,65 @@ var RESPONSE = 'response';
|
|
|
25
25
|
var LOAD_EVENT = 'loadEvent';
|
|
26
26
|
var DOM_CONTENT_LOAD_EVENT = 'domContentLoadedEvent';
|
|
27
27
|
export var navTimingValues = [];
|
|
28
|
-
|
|
28
|
+
function getPntType(type) {
|
|
29
|
+
if (typeof type == 'number') return type;
|
|
30
|
+
const types = {
|
|
31
|
+
navigate: undefined,
|
|
32
|
+
reload: 1,
|
|
33
|
+
back_forward: 2,
|
|
34
|
+
prerender: 3
|
|
35
|
+
};
|
|
36
|
+
return types[type];
|
|
37
|
+
}
|
|
38
|
+
export function addPT(offset, pt) {
|
|
39
|
+
let v = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
40
|
+
let isL1Api = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
41
|
+
if (!pt) return;
|
|
29
42
|
v.of = offset;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
handleValue(v.of, v, 'n', true);
|
|
44
|
+
handleValue(pt[UNLOAD_EVENT + START], v, 'u', isL1Api);
|
|
45
|
+
handleValue(pt[REDIRECT + START], v, 'r', isL1Api);
|
|
46
|
+
handleValue(pt[UNLOAD_EVENT + END], v, 'ue', isL1Api);
|
|
47
|
+
handleValue(pt[REDIRECT + END], v, 're', isL1Api);
|
|
48
|
+
handleValue(pt['fetch' + START], v, 'f', isL1Api);
|
|
49
|
+
handleValue(pt[DOMAIN_LOOKUP + START], v, 'dn', isL1Api);
|
|
50
|
+
handleValue(pt[DOMAIN_LOOKUP + END], v, 'dne', isL1Api);
|
|
51
|
+
handleValue(pt['c' + ONNECT + START], v, 'c', isL1Api);
|
|
52
|
+
handleValue(pt['secureC' + ONNECT + 'ion' + START], v, 's', isL1Api);
|
|
53
|
+
handleValue(pt['c' + ONNECT + END], v, 'ce', isL1Api);
|
|
54
|
+
handleValue(pt[REQUEST + START], v, 'rq', isL1Api);
|
|
55
|
+
handleValue(pt[RESPONSE + START], v, 'rp', isL1Api);
|
|
56
|
+
handleValue(pt[RESPONSE + END], v, 'rpe', isL1Api);
|
|
57
|
+
handleValue(pt.domLoading, v, 'dl', isL1Api);
|
|
58
|
+
handleValue(pt.domInteractive, v, 'di', isL1Api);
|
|
59
|
+
handleValue(pt[DOM_CONTENT_LOAD_EVENT + START], v, 'ds', isL1Api);
|
|
60
|
+
handleValue(pt[DOM_CONTENT_LOAD_EVENT + END], v, 'de', isL1Api);
|
|
61
|
+
handleValue(pt.domComplete, v, 'dc', isL1Api);
|
|
62
|
+
handleValue(pt[LOAD_EVENT + START], v, 'l', isL1Api);
|
|
63
|
+
handleValue(pt[LOAD_EVENT + END], v, 'le', isL1Api);
|
|
51
64
|
return v;
|
|
52
65
|
}
|
|
53
66
|
|
|
54
67
|
// Add Performance Navigation values to the given object
|
|
55
68
|
export function addPN(pn, v) {
|
|
56
|
-
|
|
57
|
-
|
|
69
|
+
handleValue(getPntType(pn.type), v, 'ty');
|
|
70
|
+
handleValue(pn.redirectCount, v, 'rc');
|
|
58
71
|
return v;
|
|
59
72
|
}
|
|
60
|
-
|
|
61
|
-
|
|
73
|
+
function handleValue(value, obj, prop, isOldApi) {
|
|
74
|
+
/*
|
|
75
|
+
For L2 Timing API, the value will already be a relative-to-previous-document DOMHighResTimeStamp.
|
|
76
|
+
For L1 (deprecated) Timing, the value is an UNIX epoch timestamp, which we will convert to a relative time using our offset.
|
|
77
|
+
PNT.type is reported as undefined, 1, 2, etc -- note that zero-value properties will be recorded as 'undefined', however DEM interprets undefined "types" as "navigate"
|
|
78
|
+
*/
|
|
62
79
|
if (typeof value === 'number' && value > 0) {
|
|
63
|
-
|
|
64
|
-
|
|
80
|
+
// note that zero-value properties will be recorded as 'undefined'
|
|
81
|
+
if (isOldApi) {
|
|
82
|
+
const offset = obj?.of > 0 ? obj.of : 0; // expect an epoch timestamp, if called by addPT
|
|
83
|
+
value = Math.max(value - offset, 0);
|
|
84
|
+
}
|
|
85
|
+
value = Math.round(value);
|
|
86
|
+
obj[prop] = value;
|
|
65
87
|
}
|
|
66
|
-
navTimingValues.push(
|
|
88
|
+
navTimingValues.push(value);
|
|
67
89
|
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { addPT, addPN, navTimingValues } from './nav-timing';
|
|
2
|
+
const offset = 123;
|
|
3
|
+
const testValues = {
|
|
4
|
+
unloadEventStart: 1,
|
|
5
|
+
redirectStart: 2,
|
|
6
|
+
unloadEventEnd: 3,
|
|
7
|
+
redirectEnd: 4,
|
|
8
|
+
fetchStart: 5,
|
|
9
|
+
domainLookupStart: 6,
|
|
10
|
+
domainLookupEnd: 7,
|
|
11
|
+
connectStart: 8,
|
|
12
|
+
secureConnectionStart: 9,
|
|
13
|
+
connectEnd: 10,
|
|
14
|
+
requestStart: 11,
|
|
15
|
+
responseStart: 12,
|
|
16
|
+
responseEnd: 13,
|
|
17
|
+
domLoading: 14,
|
|
18
|
+
domInteractive: 15,
|
|
19
|
+
domContentLoadedEventStart: 16,
|
|
20
|
+
domContentLoadedEventEnd: 17,
|
|
21
|
+
domComplete: 18,
|
|
22
|
+
loadEventStart: 19,
|
|
23
|
+
loadEventEnd: 20,
|
|
24
|
+
type: 'reload',
|
|
25
|
+
redirectCount: 22
|
|
26
|
+
};
|
|
27
|
+
const legacyTestValues = {
|
|
28
|
+
unloadEventStart: offset + 1,
|
|
29
|
+
redirectStart: offset + 2,
|
|
30
|
+
unloadEventEnd: offset + 3,
|
|
31
|
+
redirectEnd: offset + 4,
|
|
32
|
+
fetchStart: offset + 5,
|
|
33
|
+
domainLookupStart: offset + 6,
|
|
34
|
+
domainLookupEnd: offset + 7,
|
|
35
|
+
connectStart: offset + 8,
|
|
36
|
+
secureConnectionStart: offset + 9,
|
|
37
|
+
connectEnd: offset + 10,
|
|
38
|
+
requestStart: offset + 11,
|
|
39
|
+
responseStart: offset + 12,
|
|
40
|
+
responseEnd: offset + 13,
|
|
41
|
+
domLoading: offset + 14,
|
|
42
|
+
domInteractive: offset + 15,
|
|
43
|
+
domContentLoadedEventStart: offset + 16,
|
|
44
|
+
domContentLoadedEventEnd: offset + 17,
|
|
45
|
+
domComplete: offset + 18,
|
|
46
|
+
loadEventStart: offset + 19,
|
|
47
|
+
loadEventEnd: offset + 20,
|
|
48
|
+
type: 'reload',
|
|
49
|
+
redirectCount: offset + 22
|
|
50
|
+
};
|
|
51
|
+
const expectedPT = {
|
|
52
|
+
of: offset,
|
|
53
|
+
n: 0,
|
|
54
|
+
u: 1,
|
|
55
|
+
r: 2,
|
|
56
|
+
ue: 3,
|
|
57
|
+
re: 4,
|
|
58
|
+
f: 5,
|
|
59
|
+
dn: 6,
|
|
60
|
+
dne: 7,
|
|
61
|
+
c: 8,
|
|
62
|
+
s: 9,
|
|
63
|
+
ce: 10,
|
|
64
|
+
rq: 11,
|
|
65
|
+
rp: 12,
|
|
66
|
+
rpe: 13,
|
|
67
|
+
dl: 14,
|
|
68
|
+
di: 15,
|
|
69
|
+
ds: 16,
|
|
70
|
+
de: 17,
|
|
71
|
+
dc: 18,
|
|
72
|
+
l: 19,
|
|
73
|
+
le: 20
|
|
74
|
+
};
|
|
75
|
+
const expectedPN = {
|
|
76
|
+
ty: 1,
|
|
77
|
+
rc: 22
|
|
78
|
+
};
|
|
79
|
+
describe('addPT()', () => {
|
|
80
|
+
test('an output object is populated with valid values', () => {
|
|
81
|
+
const output = addPT(offset, testValues, {});
|
|
82
|
+
expect(output).toEqual(expectedPT);
|
|
83
|
+
});
|
|
84
|
+
test('an object with invalid values is handled', () => {
|
|
85
|
+
const output = addPT(offset, {
|
|
86
|
+
...testValues,
|
|
87
|
+
invalidValue: 'test'
|
|
88
|
+
}, {});
|
|
89
|
+
expect(output).toEqual(expectedPT);
|
|
90
|
+
const output2 = addPT(offset, {
|
|
91
|
+
...testValues,
|
|
92
|
+
loadEventEnd: -1
|
|
93
|
+
}, {});
|
|
94
|
+
let expected = {
|
|
95
|
+
...expectedPT
|
|
96
|
+
};
|
|
97
|
+
delete expected.le;
|
|
98
|
+
expect(output2).toEqual(expected);
|
|
99
|
+
const output3 = addPT(offset, {
|
|
100
|
+
...testValues,
|
|
101
|
+
loadEventEnd: 'test'
|
|
102
|
+
}, {});
|
|
103
|
+
expected = {
|
|
104
|
+
...expectedPT
|
|
105
|
+
};
|
|
106
|
+
delete expected.le;
|
|
107
|
+
expect(output3).toEqual(expected);
|
|
108
|
+
const output4 = addPT(offset, {
|
|
109
|
+
...testValues,
|
|
110
|
+
loadEventEnd: null
|
|
111
|
+
}, {});
|
|
112
|
+
expected = {
|
|
113
|
+
...expectedPT
|
|
114
|
+
};
|
|
115
|
+
delete expected.le;
|
|
116
|
+
expect(output4).toEqual(expected);
|
|
117
|
+
const legacyoutput = addPT(offset, {
|
|
118
|
+
...legacyTestValues,
|
|
119
|
+
invalidValue: 'test'
|
|
120
|
+
}, {}, true);
|
|
121
|
+
expect(legacyoutput).toEqual(expectedPT);
|
|
122
|
+
const legacyoutput2 = addPT(offset, {
|
|
123
|
+
...legacyTestValues,
|
|
124
|
+
loadEventEnd: -1
|
|
125
|
+
}, {}, true);
|
|
126
|
+
let legacyexpected = {
|
|
127
|
+
...expectedPT
|
|
128
|
+
};
|
|
129
|
+
delete legacyexpected.le;
|
|
130
|
+
expect(legacyoutput2).toEqual(expected);
|
|
131
|
+
const legacyoutput3 = addPT(offset, {
|
|
132
|
+
...legacyTestValues,
|
|
133
|
+
loadEventEnd: 'test'
|
|
134
|
+
}, {}, true);
|
|
135
|
+
legacyexpected = {
|
|
136
|
+
...expectedPT
|
|
137
|
+
};
|
|
138
|
+
delete legacyexpected.le;
|
|
139
|
+
expect(legacyoutput3).toEqual(legacyexpected);
|
|
140
|
+
const legacyoutput4 = addPT(offset, {
|
|
141
|
+
...legacyTestValues,
|
|
142
|
+
loadEventEnd: null
|
|
143
|
+
}, {}, true);
|
|
144
|
+
legacyexpected = {
|
|
145
|
+
...expectedPT
|
|
146
|
+
};
|
|
147
|
+
delete legacyexpected.le;
|
|
148
|
+
expect(legacyoutput4).toEqual(legacyexpected);
|
|
149
|
+
});
|
|
150
|
+
test('rounds values to integers', () => {
|
|
151
|
+
const output = addPT(offset, {
|
|
152
|
+
unloadEventStart: 3.14159
|
|
153
|
+
}, {});
|
|
154
|
+
expect(output.u).toEqual(3);
|
|
155
|
+
const legacyoutput = addPT(0, {
|
|
156
|
+
unloadEventStart: 3.14159
|
|
157
|
+
}, {}, true);
|
|
158
|
+
expect(legacyoutput.u).toEqual(3);
|
|
159
|
+
});
|
|
160
|
+
test('adds entries to navTimingValues', () => {
|
|
161
|
+
const beforeLength = navTimingValues.length;
|
|
162
|
+
addPT(offset, {
|
|
163
|
+
testValues
|
|
164
|
+
}, {});
|
|
165
|
+
const afterLength = navTimingValues.length;
|
|
166
|
+
expect(afterLength - beforeLength).toEqual(21); // 20 + value of n
|
|
167
|
+
|
|
168
|
+
const legacybeforeLength = navTimingValues.length;
|
|
169
|
+
addPT(offset, {
|
|
170
|
+
legacyTestValues
|
|
171
|
+
}, {}, true);
|
|
172
|
+
const legacyafterLength = navTimingValues.length;
|
|
173
|
+
expect(legacyafterLength - legacybeforeLength).toEqual(21); // 20 + value of n
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
describe('addPN()', () => {
|
|
178
|
+
test('an output object is populated with valid values', () => {
|
|
179
|
+
const output = addPN(testValues, {});
|
|
180
|
+
expect(output).toEqual(expectedPN);
|
|
181
|
+
});
|
|
182
|
+
test('adds entries to navTimingValues', () => {
|
|
183
|
+
const beforeLength = navTimingValues.length;
|
|
184
|
+
addPN(offset, {
|
|
185
|
+
testValues
|
|
186
|
+
}, {});
|
|
187
|
+
const afterLength = navTimingValues.length;
|
|
188
|
+
expect(afterLength - beforeLength).toEqual(2);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { ffVersion } from '../browser-version/firefox-version';
|
|
6
6
|
import { windowAddEventListener } from '../event-listener/event-listener-opts';
|
|
7
|
-
import { single } from '../util/
|
|
7
|
+
import { single } from '../util/invoke';
|
|
8
8
|
import { globalScope, isWorkerScope, isBrowserScope } from '../util/global-scope';
|
|
9
9
|
import { subscribeToVisibilityChange } from '../window/page-visibility';
|
|
10
10
|
if (isWorkerScope) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { cleanURL } from './clean-url';
|
|
2
|
+
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) => {
|
|
3
|
+
expect(cleanURL(input)).toEqual(expected);
|
|
4
|
+
});
|
|
5
|
+
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) => {
|
|
6
|
+
expect(cleanURL(input, true)).toEqual(expected);
|
|
7
|
+
});
|