@newrelic/browser-agent 1.234.0 → 1.236.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (372) hide show
  1. package/README.md +42 -2
  2. package/dist/cjs/common/config/state/init.js +3 -0
  3. package/dist/cjs/common/config/state/runtime.js +4 -4
  4. package/dist/cjs/common/constants/env.cdn.js +2 -2
  5. package/dist/cjs/common/constants/env.npm.js +1 -1
  6. package/dist/cjs/common/constants/runtime.js +52 -0
  7. package/dist/cjs/common/constants/shared-channel.js +19 -0
  8. package/dist/cjs/common/event-listener/event-listener-opts.js +3 -3
  9. package/dist/cjs/common/harvest/harvest-scheduler.js +35 -16
  10. package/dist/cjs/common/harvest/harvest.js +163 -144
  11. package/dist/cjs/common/harvest/types.js +54 -0
  12. package/dist/cjs/common/ids/id.js +2 -2
  13. package/dist/cjs/common/ids/unique-id.js +3 -3
  14. package/dist/cjs/common/session/session-entity.js +21 -13
  15. package/dist/cjs/common/timer/interaction-timer.js +3 -3
  16. package/dist/cjs/common/unload/eol.js +10 -11
  17. package/dist/cjs/common/url/canonicalize-url.js +2 -2
  18. package/dist/cjs/common/url/parse-url.js +3 -3
  19. package/dist/cjs/common/url/protocol.js +2 -2
  20. package/dist/cjs/common/util/feature-flags.js +23 -12
  21. package/dist/cjs/common/util/obfuscate.js +2 -2
  22. package/dist/cjs/common/util/submit-data.js +61 -79
  23. package/dist/cjs/common/window/nreum.js +14 -14
  24. package/dist/cjs/common/wrap/wrap-events.js +3 -3
  25. package/dist/cjs/common/wrap/wrap-fetch.js +5 -5
  26. package/dist/cjs/common/wrap/wrap-history.js +2 -2
  27. package/dist/cjs/common/wrap/wrap-jsonp.js +2 -2
  28. package/dist/cjs/common/wrap/wrap-mutation.js +2 -2
  29. package/dist/cjs/common/wrap/wrap-promise.js +2 -2
  30. package/dist/cjs/common/wrap/wrap-raf.js +3 -3
  31. package/dist/cjs/common/wrap/wrap-timer.js +5 -5
  32. package/dist/cjs/common/wrap/wrap-xhr.js +3 -3
  33. package/dist/cjs/features/ajax/aggregate/index.js +1 -1
  34. package/dist/cjs/features/ajax/instrument/distributed-tracing.js +2 -2
  35. package/dist/cjs/features/ajax/instrument/index.js +6 -7
  36. package/dist/cjs/features/jserrors/aggregate/index.js +11 -4
  37. package/dist/cjs/features/jserrors/instrument/index.js +6 -19
  38. package/dist/cjs/features/metrics/aggregate/framework-detection.js +2 -2
  39. package/dist/cjs/features/metrics/aggregate/index.js +3 -3
  40. package/dist/cjs/features/page_action/aggregate/index.js +3 -3
  41. package/dist/cjs/features/page_view_event/aggregate/index.js +10 -11
  42. package/dist/cjs/features/page_view_event/instrument/index.js +2 -2
  43. package/dist/cjs/features/page_view_timing/aggregate/index.js +3 -5
  44. package/dist/cjs/features/page_view_timing/instrument/index.js +2 -2
  45. package/dist/cjs/features/session_replay/aggregate/index.js +99 -82
  46. package/dist/cjs/features/session_replay/replay-mode.js +28 -0
  47. package/dist/cjs/features/session_trace/aggregate/index.js +222 -99
  48. package/dist/cjs/features/session_trace/constants.js +1 -3
  49. package/dist/cjs/features/session_trace/instrument/index.js +2 -18
  50. package/dist/cjs/features/spa/aggregate/index.js +1 -1
  51. package/dist/cjs/features/spa/constants.js +0 -1
  52. package/dist/cjs/features/spa/instrument/index.js +2 -2
  53. package/dist/cjs/features/utils/agent-session.js +20 -36
  54. package/dist/cjs/features/utils/aggregate-base.js +7 -12
  55. package/dist/cjs/features/utils/handler-cache.js +28 -23
  56. package/dist/cjs/features/utils/instrument-base.js +58 -40
  57. package/dist/cjs/index.js +7 -0
  58. package/dist/cjs/loaders/agent.js +7 -1
  59. package/dist/cjs/loaders/api/api.js +2 -2
  60. package/dist/cjs/loaders/api/apiAsync.js +6 -4
  61. package/dist/cjs/loaders/configure/configure.js +2 -2
  62. package/dist/cjs/loaders/features/featureDependencies.js +2 -0
  63. package/dist/cjs/loaders/micro-agent.js +29 -38
  64. package/dist/esm/common/config/state/init.js +3 -0
  65. package/dist/esm/common/config/state/runtime.js +1 -1
  66. package/dist/esm/common/constants/env.cdn.js +2 -2
  67. package/dist/esm/common/constants/env.npm.js +1 -1
  68. package/dist/esm/common/constants/runtime.js +38 -0
  69. package/dist/esm/common/constants/shared-channel.js +12 -0
  70. package/dist/esm/common/event-listener/event-listener-opts.js +1 -1
  71. package/dist/esm/common/harvest/harvest-scheduler.js +34 -17
  72. package/dist/esm/common/harvest/harvest.js +160 -142
  73. package/dist/esm/common/harvest/types.js +47 -0
  74. package/dist/esm/common/ids/id.js +1 -1
  75. package/dist/esm/common/ids/unique-id.js +1 -1
  76. package/dist/esm/common/session/session-entity.js +18 -12
  77. package/dist/esm/common/timer/interaction-timer.js +2 -2
  78. package/dist/esm/common/unload/eol.js +1 -2
  79. package/dist/esm/common/url/canonicalize-url.js +1 -1
  80. package/dist/esm/common/url/parse-url.js +1 -1
  81. package/dist/esm/common/url/protocol.js +1 -1
  82. package/dist/esm/common/util/feature-flags.js +23 -12
  83. package/dist/esm/common/util/obfuscate.js +2 -2
  84. package/dist/esm/common/util/submit-data.js +58 -76
  85. package/dist/esm/common/window/nreum.js +1 -1
  86. package/dist/esm/common/wrap/wrap-events.js +1 -1
  87. package/dist/esm/common/wrap/wrap-fetch.js +1 -1
  88. package/dist/esm/common/wrap/wrap-history.js +1 -1
  89. package/dist/esm/common/wrap/wrap-jsonp.js +1 -1
  90. package/dist/esm/common/wrap/wrap-mutation.js +1 -1
  91. package/dist/esm/common/wrap/wrap-promise.js +1 -1
  92. package/dist/esm/common/wrap/wrap-raf.js +2 -2
  93. package/dist/esm/common/wrap/wrap-timer.js +2 -2
  94. package/dist/esm/common/wrap/wrap-xhr.js +1 -1
  95. package/dist/esm/features/ajax/aggregate/index.js +1 -1
  96. package/dist/esm/features/ajax/instrument/distributed-tracing.js +1 -1
  97. package/dist/esm/features/ajax/instrument/index.js +1 -2
  98. package/dist/esm/features/jserrors/aggregate/index.js +10 -3
  99. package/dist/esm/features/jserrors/instrument/index.js +3 -16
  100. package/dist/esm/features/metrics/aggregate/framework-detection.js +1 -1
  101. package/dist/esm/features/metrics/aggregate/index.js +1 -1
  102. package/dist/esm/features/page_action/aggregate/index.js +1 -1
  103. package/dist/esm/features/page_view_event/aggregate/index.js +1 -2
  104. package/dist/esm/features/page_view_event/instrument/index.js +1 -1
  105. package/dist/esm/features/page_view_timing/aggregate/index.js +2 -4
  106. package/dist/esm/features/page_view_timing/instrument/index.js +1 -1
  107. package/dist/esm/features/session_replay/aggregate/index.js +92 -78
  108. package/dist/esm/features/session_replay/replay-mode.js +23 -0
  109. package/dist/esm/features/session_trace/aggregate/index.js +223 -100
  110. package/dist/esm/features/session_trace/constants.js +0 -1
  111. package/dist/esm/features/session_trace/instrument/index.js +2 -18
  112. package/dist/esm/features/spa/aggregate/index.js +1 -1
  113. package/dist/esm/features/spa/constants.js +0 -1
  114. package/dist/esm/features/spa/instrument/index.js +1 -1
  115. package/dist/esm/features/utils/agent-session.js +21 -37
  116. package/dist/esm/features/utils/aggregate-base.js +7 -12
  117. package/dist/esm/features/utils/handler-cache.js +28 -23
  118. package/dist/esm/features/utils/instrument-base.js +57 -39
  119. package/dist/esm/index.js +1 -4
  120. package/dist/esm/loaders/agent.js +7 -1
  121. package/dist/esm/loaders/api/api.js +2 -2
  122. package/dist/esm/loaders/api/apiAsync.js +3 -3
  123. package/dist/esm/loaders/configure/configure.js +1 -1
  124. package/dist/esm/loaders/features/featureDependencies.js +2 -0
  125. package/dist/esm/loaders/micro-agent.js +29 -38
  126. package/dist/types/common/config/state/init.d.ts.map +1 -1
  127. package/dist/types/common/constants/runtime.d.ts +29 -0
  128. package/dist/types/common/constants/runtime.d.ts.map +1 -0
  129. package/dist/types/common/constants/shared-channel.d.ts +5 -0
  130. package/dist/types/common/constants/shared-channel.d.ts.map +1 -0
  131. package/dist/types/common/harvest/harvest-scheduler.d.ts +5 -1
  132. package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
  133. package/dist/types/common/harvest/harvest.d.ts +49 -38
  134. package/dist/types/common/harvest/harvest.d.ts.map +1 -1
  135. package/dist/types/common/harvest/types.d.ts +100 -0
  136. package/dist/types/common/harvest/types.d.ts.map +1 -0
  137. package/dist/types/common/session/session-entity.d.ts +9 -5
  138. package/dist/types/common/session/session-entity.d.ts.map +1 -1
  139. package/dist/types/common/unload/eol.d.ts.map +1 -1
  140. package/dist/types/common/util/feature-flags.d.ts +1 -0
  141. package/dist/types/common/util/feature-flags.d.ts.map +1 -1
  142. package/dist/types/common/util/submit-data.d.ts +62 -64
  143. package/dist/types/common/util/submit-data.d.ts.map +1 -1
  144. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
  145. package/dist/types/features/jserrors/aggregate/index.d.ts +2 -1
  146. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  147. package/dist/types/features/jserrors/instrument/index.d.ts +1 -1
  148. package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -1
  149. package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
  150. package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
  151. package/dist/types/features/session_replay/aggregate/index.d.ts +14 -5
  152. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  153. package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
  154. package/dist/types/features/session_replay/replay-mode.d.ts +9 -0
  155. package/dist/types/features/session_replay/replay-mode.d.ts.map +1 -0
  156. package/dist/types/features/session_trace/aggregate/index.d.ts +21 -3
  157. package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
  158. package/dist/types/features/session_trace/constants.d.ts +0 -1
  159. package/dist/types/features/session_trace/constants.d.ts.map +1 -1
  160. package/dist/types/features/session_trace/instrument/index.d.ts +0 -2
  161. package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
  162. package/dist/types/features/spa/constants.d.ts.map +1 -1
  163. package/dist/types/features/utils/agent-session.d.ts.map +1 -1
  164. package/dist/types/features/utils/aggregate-base.d.ts +6 -1
  165. package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
  166. package/dist/types/features/utils/handler-cache.d.ts +12 -11
  167. package/dist/types/features/utils/handler-cache.d.ts.map +1 -1
  168. package/dist/types/features/utils/instrument-base.d.ts +17 -1
  169. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  170. package/dist/types/index.d.ts +1 -0
  171. package/dist/types/loaders/agent.d.ts +4 -4
  172. package/dist/types/loaders/agent.d.ts.map +1 -1
  173. package/dist/types/loaders/features/featureDependencies.d.ts.map +1 -1
  174. package/dist/types/loaders/micro-agent.d.ts +3 -4
  175. package/dist/types/loaders/micro-agent.d.ts.map +1 -1
  176. package/package.json +14 -7
  177. package/src/common/config/__mocks__/config.js +11 -0
  178. package/src/common/config/state/init.js +1 -0
  179. package/src/common/config/state/runtime.js +1 -1
  180. package/src/common/constants/__mocks__/env.js +3 -0
  181. package/src/common/constants/__mocks__/runtime.js +8 -0
  182. package/src/common/constants/env.cdn.test.js +7 -0
  183. package/src/common/constants/env.npm.test.js +7 -0
  184. package/src/common/constants/env.test.js +7 -0
  185. package/src/common/constants/runtime.js +71 -0
  186. package/src/common/constants/runtime.test.js +168 -0
  187. package/src/common/constants/shared-channel.js +13 -0
  188. package/src/common/context/__mocks__/shared-context.js +8 -0
  189. package/src/common/event-listener/__mocks__/event-listener-opts.js +7 -0
  190. package/src/common/event-listener/event-listener-opts.js +1 -1
  191. package/src/common/harvest/__mocks__/harvest.js +13 -0
  192. package/src/common/harvest/harvest-scheduler.js +31 -19
  193. package/src/common/harvest/harvest-scheduler.test.js +491 -20
  194. package/src/common/harvest/harvest.js +147 -130
  195. package/src/common/harvest/harvest.test.js +788 -139
  196. package/src/common/harvest/types.js +47 -0
  197. package/src/common/ids/id.js +1 -1
  198. package/src/common/ids/unique-id.js +1 -1
  199. package/src/common/session/__mocks__/session-entity.js +25 -0
  200. package/src/common/session/{session-entity.test.js → session-entity.component-test.js} +71 -48
  201. package/src/common/session/session-entity.js +16 -13
  202. package/src/common/timer/interaction-timer.js +2 -2
  203. package/src/common/timing/__mocks__/now.js +1 -0
  204. package/src/common/unload/__mocks__/eol.js +1 -0
  205. package/src/common/unload/eol.js +1 -2
  206. package/src/common/url/__mocks__/clean-url.js +1 -0
  207. package/src/common/url/__mocks__/encode.js +7 -0
  208. package/src/common/url/__mocks__/location.js +1 -0
  209. package/src/common/url/canonicalize-url.js +1 -1
  210. package/src/common/url/canonicalize-url.test.js +32 -21
  211. package/src/common/url/parse-url.js +1 -1
  212. package/src/common/url/parse-url.test.js +3 -3
  213. package/src/common/url/protocol.js +1 -1
  214. package/src/common/util/__mocks__/obfuscate.js +10 -0
  215. package/src/common/util/__mocks__/stringify.js +1 -0
  216. package/src/common/util/__mocks__/submit-data.js +6 -0
  217. package/src/common/util/__mocks__/traverse.js +1 -0
  218. package/src/common/util/data-size.test.js +27 -20
  219. package/src/common/util/feature-flags.js +24 -12
  220. package/src/common/util/feature-flags.test.js +98 -0
  221. package/src/common/util/obfuscate.component-test.js +173 -0
  222. package/src/common/util/obfuscate.js +2 -2
  223. package/src/common/util/submit-data.js +42 -56
  224. package/src/common/util/submit-data.test.js +158 -137
  225. package/src/common/window/nreum.js +1 -1
  226. package/src/common/wrap/wrap-events.js +1 -1
  227. package/src/common/wrap/wrap-fetch.js +1 -1
  228. package/src/common/wrap/wrap-history.js +1 -1
  229. package/src/common/wrap/wrap-jsonp.js +1 -1
  230. package/src/common/wrap/wrap-mutation.js +1 -1
  231. package/src/common/wrap/wrap-promise.js +1 -1
  232. package/src/common/wrap/wrap-promise.test.js +2 -2
  233. package/src/common/wrap/wrap-raf.js +2 -2
  234. package/src/common/wrap/wrap-timer.js +2 -2
  235. package/src/common/wrap/wrap-xhr.js +1 -1
  236. package/src/features/ajax/aggregate/index.js +1 -1
  237. package/src/features/ajax/instrument/distributed-tracing.js +1 -1
  238. package/src/features/ajax/instrument/index.js +1 -2
  239. package/src/features/jserrors/aggregate/compute-stack-trace.test.js +1 -1
  240. package/src/features/jserrors/aggregate/index.js +12 -3
  241. package/src/features/jserrors/instrument/index.js +3 -16
  242. package/src/features/metrics/aggregate/framework-detection.js +1 -1
  243. package/src/features/metrics/aggregate/framework-detection.test.js +2 -2
  244. package/src/features/metrics/aggregate/index.js +1 -1
  245. package/src/features/page_action/aggregate/index.js +1 -1
  246. package/src/features/page_view_event/aggregate/index.js +1 -2
  247. package/src/features/page_view_event/instrument/index.js +1 -1
  248. package/src/features/page_view_timing/aggregate/index.js +2 -4
  249. package/src/features/page_view_timing/instrument/index.js +1 -1
  250. package/src/features/session_replay/aggregate/index.component-test.js +368 -0
  251. package/src/features/session_replay/aggregate/index.js +96 -71
  252. package/src/features/session_replay/instrument/index.js +0 -1
  253. package/src/features/session_replay/replay-mode.js +23 -0
  254. package/src/features/session_trace/aggregate/index.js +198 -79
  255. package/src/features/session_trace/constants.js +0 -1
  256. package/src/features/session_trace/instrument/index.js +3 -20
  257. package/src/features/spa/aggregate/index.js +1 -1
  258. package/src/features/spa/constants.js +0 -1
  259. package/src/features/spa/instrument/index.js +1 -1
  260. package/src/features/utils/agent-session.js +22 -34
  261. package/src/features/utils/agent-session.test.js +194 -0
  262. package/src/features/utils/aggregate-base.js +12 -9
  263. package/src/features/utils/aggregate-base.test.js +122 -0
  264. package/src/features/utils/feature-base.test.js +45 -0
  265. package/src/features/utils/handler-cache.js +29 -23
  266. package/src/features/utils/handler-cache.test.js +72 -0
  267. package/src/features/utils/instrument-base.js +45 -29
  268. package/src/features/utils/instrument-base.test.js +209 -0
  269. package/src/features/utils/lazy-feature-loader.test.js +37 -0
  270. package/src/index.js +1 -3
  271. package/src/loaders/agent.js +8 -1
  272. package/src/loaders/api/api.js +2 -2
  273. package/src/loaders/api/apiAsync.js +3 -3
  274. package/src/loaders/configure/configure.js +1 -1
  275. package/src/loaders/features/featureDependencies.js +2 -0
  276. package/src/loaders/micro-agent.js +26 -30
  277. package/dist/cjs/common/browser-version/firefox-version.js +0 -17
  278. package/dist/cjs/common/browser-version/ios-version.js +0 -19
  279. package/dist/cjs/common/event-emitter/contextual-ee.test.js +0 -282
  280. package/dist/cjs/common/event-emitter/handle.test.js +0 -58
  281. package/dist/cjs/common/event-emitter/register-handler.test.js +0 -55
  282. package/dist/cjs/common/harvest/harvest-scheduler.test.js +0 -39
  283. package/dist/cjs/common/harvest/harvest.test.js +0 -224
  284. package/dist/cjs/common/ids/id.test.js +0 -85
  285. package/dist/cjs/common/ids/unique-id.test.js +0 -49
  286. package/dist/cjs/common/session/session-entity.test.js +0 -460
  287. package/dist/cjs/common/storage/local-memory.js +0 -35
  288. package/dist/cjs/common/storage/local-memory.test.js +0 -20
  289. package/dist/cjs/common/storage/local-storage.test.js +0 -14
  290. package/dist/cjs/common/timer/interaction-timer.test.js +0 -216
  291. package/dist/cjs/common/timer/timer.test.js +0 -105
  292. package/dist/cjs/common/timing/nav-timing.test.js +0 -192
  293. package/dist/cjs/common/url/canonicalize-url.test.js +0 -42
  294. package/dist/cjs/common/url/clean-url.test.js +0 -9
  295. package/dist/cjs/common/url/encode.test.js +0 -74
  296. package/dist/cjs/common/url/location.test.js +0 -13
  297. package/dist/cjs/common/url/parse-url.test.js +0 -111
  298. package/dist/cjs/common/url/protocol.test.js +0 -15
  299. package/dist/cjs/common/util/console.test.js +0 -30
  300. package/dist/cjs/common/util/data-size.test.js +0 -47
  301. package/dist/cjs/common/util/get-or-set.test.js +0 -47
  302. package/dist/cjs/common/util/global-scope.js +0 -58
  303. package/dist/cjs/common/util/invoke.test.js +0 -49
  304. package/dist/cjs/common/util/map-own.test.js +0 -49
  305. package/dist/cjs/common/util/stringify.test.js +0 -48
  306. package/dist/cjs/common/util/submit-data.test.js +0 -221
  307. package/dist/cjs/common/util/traverse.test.js +0 -44
  308. package/dist/cjs/common/wrap/wrap-promise.test.js +0 -119
  309. package/dist/cjs/features/jserrors/aggregate/canonical-function-name.test.js +0 -31
  310. package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +0 -383
  311. package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +0 -40
  312. package/dist/cjs/features/jserrors/aggregate/string-hash-code.test.js +0 -27
  313. package/dist/cjs/features/metrics/aggregate/framework-detection.test.js +0 -137
  314. package/dist/cjs/features/metrics/aggregate/polyfill-detection.es5.test.js +0 -17
  315. package/dist/cjs/features/metrics/aggregate/polyfill-detection.test.js +0 -165
  316. package/dist/cjs/features/spa/aggregate/interaction-node.test.js +0 -16
  317. package/dist/esm/common/browser-version/firefox-version.js +0 -10
  318. package/dist/esm/common/browser-version/ios-version.js +0 -11
  319. package/dist/esm/common/event-emitter/contextual-ee.test.js +0 -278
  320. package/dist/esm/common/event-emitter/handle.test.js +0 -54
  321. package/dist/esm/common/event-emitter/register-handler.test.js +0 -51
  322. package/dist/esm/common/harvest/harvest-scheduler.test.js +0 -37
  323. package/dist/esm/common/harvest/harvest.test.js +0 -222
  324. package/dist/esm/common/ids/id.test.js +0 -81
  325. package/dist/esm/common/ids/unique-id.test.js +0 -44
  326. package/dist/esm/common/session/session-entity.test.js +0 -458
  327. package/dist/esm/common/storage/local-memory.js +0 -28
  328. package/dist/esm/common/storage/local-memory.test.js +0 -18
  329. package/dist/esm/common/storage/local-storage.test.js +0 -12
  330. package/dist/esm/common/timer/interaction-timer.test.js +0 -214
  331. package/dist/esm/common/timer/timer.test.js +0 -103
  332. package/dist/esm/common/timing/nav-timing.test.js +0 -190
  333. package/dist/esm/common/url/canonicalize-url.test.js +0 -38
  334. package/dist/esm/common/url/clean-url.test.js +0 -7
  335. package/dist/esm/common/url/encode.test.js +0 -70
  336. package/dist/esm/common/url/location.test.js +0 -11
  337. package/dist/esm/common/url/parse-url.test.js +0 -107
  338. package/dist/esm/common/url/protocol.test.js +0 -13
  339. package/dist/esm/common/util/console.test.js +0 -28
  340. package/dist/esm/common/util/data-size.test.js +0 -45
  341. package/dist/esm/common/util/get-or-set.test.js +0 -45
  342. package/dist/esm/common/util/global-scope.js +0 -45
  343. package/dist/esm/common/util/invoke.test.js +0 -47
  344. package/dist/esm/common/util/map-own.test.js +0 -47
  345. package/dist/esm/common/util/stringify.test.js +0 -46
  346. package/dist/esm/common/util/submit-data.test.js +0 -219
  347. package/dist/esm/common/util/traverse.test.js +0 -42
  348. package/dist/esm/common/wrap/wrap-promise.test.js +0 -115
  349. package/dist/esm/features/jserrors/aggregate/canonical-function-name.test.js +0 -29
  350. package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +0 -379
  351. package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +0 -38
  352. package/dist/esm/features/jserrors/aggregate/string-hash-code.test.js +0 -25
  353. package/dist/esm/features/metrics/aggregate/framework-detection.test.js +0 -133
  354. package/dist/esm/features/metrics/aggregate/polyfill-detection.es5.test.js +0 -15
  355. package/dist/esm/features/metrics/aggregate/polyfill-detection.test.js +0 -163
  356. package/dist/esm/features/spa/aggregate/interaction-node.test.js +0 -14
  357. package/dist/types/common/browser-version/firefox-version.d.ts +0 -2
  358. package/dist/types/common/browser-version/firefox-version.d.ts.map +0 -1
  359. package/dist/types/common/browser-version/ios-version.d.ts +0 -3
  360. package/dist/types/common/browser-version/ios-version.d.ts.map +0 -1
  361. package/dist/types/common/storage/local-memory.d.ts +0 -8
  362. package/dist/types/common/storage/local-memory.d.ts.map +0 -1
  363. package/dist/types/common/util/global-scope.d.ts +0 -14
  364. package/dist/types/common/util/global-scope.d.ts.map +0 -1
  365. package/src/common/browser-version/firefox-version.js +0 -10
  366. package/src/common/browser-version/ios-version.js +0 -11
  367. package/src/common/storage/local-memory.js +0 -30
  368. package/src/common/storage/local-memory.test.js +0 -19
  369. package/src/common/util/global-scope.js +0 -49
  370. /package/src/common/timer/{interaction-timer.test.js → interaction-timer.component-test.js} +0 -0
  371. /package/src/common/url/{encode.test.js → encode.component-test.js} +0 -0
  372. /package/src/common/url/{protocol.test.js → protocol.component-test.js} +0 -0
@@ -1,137 +0,0 @@
1
- "use strict";
2
-
3
- var _faker = require("@faker-js/faker");
4
- var _frameworkDetection = require("./framework-detection");
5
- 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); }
6
- 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; }
7
- jest.mock('../../../common/util/global-scope', () => ({
8
- isBrowserScope: true
9
- }));
10
- afterEach(() => {
11
- document.body.innerHTML = '';
12
- });
13
- test('framework detection should not happen in non-browser scope', async () => {
14
- global.React = {};
15
- jest.resetModules();
16
- jest.doMock('../../../common/util/global-scope', () => ({
17
- isBrowserScope: false
18
- }));
19
- const frameworkDetector = await Promise.resolve().then(() => _interopRequireWildcard(require('./framework-detection')));
20
- expect(frameworkDetector.getFrameworks()).toEqual([]);
21
- delete global.React;
22
- });
23
- test('should detect react from global React property', () => {
24
- global.React = {};
25
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['React']);
26
- delete global.React;
27
- });
28
- test('should detect react from global ReactDOM property', () => {
29
- global.ReactDOM = {};
30
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['React']);
31
- delete global.ReactDOM;
32
- });
33
- test('should detect react from global ReactRedux property', () => {
34
- global.ReactRedux = {};
35
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['React']);
36
- delete global.ReactRedux;
37
- });
38
- test('should detect react from html [data-reactroot] property', () => {
39
- document.body.innerHTML = '<div data-reactroot=""></div>';
40
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['React']);
41
- });
42
- test('should detect react from html [data-reactid] property', () => {
43
- document.body.innerHTML = '<div data-reactid=""></div>';
44
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['React']);
45
- });
46
- test('should detect react from element _reactRootContainer property', () => {
47
- const element = document.createElement('div');
48
- element._reactRootContainer = {};
49
- document.body.innerHTML = '<html><body></body></html>';
50
- document.body.appendChild(element);
51
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['React']);
52
- });
53
- test('should detect angularjs from global angular property', () => {
54
- global.angular = {};
55
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
56
- delete global.angular;
57
- });
58
- test('should detect angularjs from html .ng-binding property', () => {
59
- document.body.innerHTML = '<div class="ng-binding"></div>';
60
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
61
- });
62
- test('should detect angularjs from html [ng-app] property', () => {
63
- document.body.innerHTML = '<div ng-app=""></div>';
64
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
65
- });
66
- test('should detect angularjs from html [data-ng-app] property', () => {
67
- document.body.innerHTML = '<div data-ng-app=""></div>';
68
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
69
- });
70
- test('should detect angularjs from html [ng-controller] property', () => {
71
- document.body.innerHTML = '<div ng-controller=""></div>';
72
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
73
- });
74
- test('should detect angularjs from html [data-ng-controller] property', () => {
75
- document.body.innerHTML = '<div data-ng-controller=""></div>';
76
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
77
- });
78
- test('should detect angularjs from html [ng-repeat] property', () => {
79
- document.body.innerHTML = '<div ng-repeat=""></div>';
80
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
81
- });
82
- test('should detect angularjs from html [data-ng-repeat] property', () => {
83
- document.body.innerHTML = '<div data-ng-repeat=""></div>';
84
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
85
- });
86
- test('should detect angularjs from angular.js script element', () => {
87
- document.body.innerHTML = "<script src=\"".concat(_faker.faker.internet.url(), "/angular.js\"></script>");
88
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
89
- });
90
- test('should detect angularjs from angular.min.js script element', () => {
91
- document.body.innerHTML = "<script src=\"".concat(_faker.faker.internet.url(), "/angular.min.js\"></script>");
92
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['AngularJS']);
93
- });
94
- test('should detect angular from global ng property', () => {
95
- global.ng = {};
96
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Angular']);
97
- delete global.ng;
98
- });
99
- test('should detect angular from html [ng-version] property', () => {
100
- document.body.innerHTML = '<div ng-version=""></div>';
101
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Angular']);
102
- });
103
- test('should detect backbone from global Backbone property', () => {
104
- global.Backbone = {};
105
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Backbone']);
106
- delete global.Backbone;
107
- });
108
- test('should detect ember from global Ember property', () => {
109
- global.Ember = {};
110
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Ember']);
111
- delete global.Ember;
112
- });
113
- test('should detect vue from global Vue property', () => {
114
- global.Vue = {};
115
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Vue']);
116
- delete global.Vue;
117
- });
118
- test('should detect meteor from global Meteor property', () => {
119
- global.Meteor = {};
120
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Meteor']);
121
- delete global.Meteor;
122
- });
123
- test('should detect zepto from global Zepto property', () => {
124
- global.Zepto = {};
125
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Zepto']);
126
- delete global.Zepto;
127
- });
128
- test('should detect jquery from global jQuery property', () => {
129
- global.jQuery = {};
130
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['Jquery']);
131
- delete global.jQuery;
132
- });
133
- test('should detect mootools from global MooTools property', () => {
134
- global.MooTools = {};
135
- expect((0, _frameworkDetection.getFrameworks)()).toEqual(['MooTools']);
136
- delete global.MooTools;
137
- });
@@ -1,17 +0,0 @@
1
- "use strict";
2
-
3
- var _polyfillDetection = require("./polyfill-detection.es5");
4
- afterEach(() => {
5
- jest.resetAllMocks();
6
- });
7
- test('should always return an empty array', () => {
8
- const originalFn = Array.from;
9
- Array.from = jest.fn(function () {
10
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
11
- args[_key] = arguments[_key];
12
- }
13
- return originalFn.apply(this, args);
14
- });
15
- expect((0, _polyfillDetection.getPolyfills)()).toEqual([]);
16
- Array.from = originalFn;
17
- });
@@ -1,165 +0,0 @@
1
- "use strict";
2
-
3
- var _polyfillDetection = require("./polyfill-detection");
4
- /* eslint-disable no-global-assign */
5
- /* eslint-disable no-extend-native */
6
-
7
- // DO NOT test Function.prototype.apply, it causes recursion in Jest
8
-
9
- test('should return an empty array when nothing is polyfilled', () => {
10
- expect((0, _polyfillDetection.getPolyfills)()).toEqual([]);
11
- });
12
- test('should indicate Function.prototype.bind is polyfilled', () => {
13
- const originalFn = Function.prototype.bind;
14
- Function.prototype.bind = jest.fn(function () {
15
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
16
- args[_key] = arguments[_key];
17
- }
18
- return originalFn.apply(this, args);
19
- });
20
- expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Function.bind']);
21
- Function.prototype.bind = originalFn;
22
- });
23
- test('should indicate Function.prototype.call is polyfilled', () => {
24
- const originalFn = Function.prototype.call;
25
- Function.prototype.call = jest.fn(function () {
26
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
27
- args[_key2] = arguments[_key2];
28
- }
29
- return originalFn.apply(this, args);
30
- });
31
- expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Function.call']);
32
- Function.prototype.call = originalFn;
33
- });
34
- test('should indicate Array.prototype.includes is polyfilled', () => {
35
- const originalFn = Array.prototype.includes;
36
- Array.prototype.includes = jest.fn(function () {
37
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
38
- args[_key3] = arguments[_key3];
39
- }
40
- return originalFn.apply(this, args);
41
- });
42
- expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Array.includes']);
43
- Array.prototype.includes = originalFn;
44
- });
45
- test('should indicate Array.from is polyfilled', () => {
46
- const originalFn = Array.from;
47
- Array.from = jest.fn(function () {
48
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
49
- args[_key4] = arguments[_key4];
50
- }
51
- return originalFn.apply(this, args);
52
- });
53
- expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Array.from']);
54
- Array.from = originalFn;
55
- });
56
- test('should indicate Array.prototype.find is polyfilled', () => {
57
- const originalFn = Array.prototype.find;
58
- Array.prototype.find = jest.fn(function () {
59
- for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
60
- args[_key5] = arguments[_key5];
61
- }
62
- return originalFn.apply(this, args);
63
- });
64
- expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Array.find']);
65
- Array.prototype.find = originalFn;
66
- });
67
- test('should indicate Array.prototype.flat is polyfilled', () => {
68
- const originalFn = Array.prototype.flat;
69
- Array.prototype.flat = jest.fn(function () {
70
- for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
71
- args[_key6] = arguments[_key6];
72
- }
73
- return originalFn.apply(this, args);
74
- });
75
- expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Array.flat']);
76
- Array.prototype.flat = originalFn;
77
- });
78
- test('should indicate Array.prototype.flatMap is polyfilled', () => {
79
- const originalFn = Array.prototype.flatMap;
80
- Array.prototype.flatMap = jest.fn(function () {
81
- for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
82
- args[_key7] = arguments[_key7];
83
- }
84
- return originalFn.apply(this, args);
85
- });
86
- expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Array.flatMap']);
87
- Array.prototype.flatMap = originalFn;
88
- });
89
- test('should indicate Object.assign is polyfilled', () => {
90
- const originalFn = Object.assign;
91
- Object.assign = jest.fn(function () {
92
- for (var _len8 = arguments.length, args = new Array(_len8), _key8 = 0; _key8 < _len8; _key8++) {
93
- args[_key8] = arguments[_key8];
94
- }
95
- return originalFn.apply(this, args);
96
- });
97
- expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Object.assign']);
98
- Object.assign = originalFn;
99
- });
100
- test('should indicate Object.entries is polyfilled', () => {
101
- const originalFn = Object.entries;
102
- Object.entries = jest.fn(function () {
103
- for (var _len9 = arguments.length, args = new Array(_len9), _key9 = 0; _key9 < _len9; _key9++) {
104
- args[_key9] = arguments[_key9];
105
- }
106
- return originalFn.apply(this, args);
107
- });
108
- expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Object.entries']);
109
- Object.entries = originalFn;
110
- });
111
- test('should indicate Object.values is polyfilled', () => {
112
- const originalFn = Object.values;
113
- Object.values = jest.fn(function () {
114
- for (var _len10 = arguments.length, args = new Array(_len10), _key10 = 0; _key10 < _len10; _key10++) {
115
- args[_key10] = arguments[_key10];
116
- }
117
- return originalFn.apply(this, args);
118
- });
119
- expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Object.values']);
120
- Object.values = originalFn;
121
- });
122
- test('should indicate Map constructor is polyfilled', () => {
123
- const originalFn = Map;
124
- Map = jest.fn(function () {
125
- for (var _len11 = arguments.length, args = new Array(_len11), _key11 = 0; _key11 < _len11; _key11++) {
126
- args[_key11] = arguments[_key11];
127
- }
128
- return originalFn.apply(this, args);
129
- });
130
- expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Map']);
131
- Map = originalFn;
132
- });
133
- test('should indicate Set constructor is polyfilled', () => {
134
- const originalFn = Set;
135
- Set = jest.fn(function () {
136
- for (var _len12 = arguments.length, args = new Array(_len12), _key12 = 0; _key12 < _len12; _key12++) {
137
- args[_key12] = arguments[_key12];
138
- }
139
- return originalFn.apply(this, args);
140
- });
141
- expect((0, _polyfillDetection.getPolyfills)()).toEqual(['Set']);
142
- Set = originalFn;
143
- });
144
- test('should indicate WeakMap constructor is polyfilled', () => {
145
- const originalFn = WeakMap;
146
- WeakMap = jest.fn(function () {
147
- for (var _len13 = arguments.length, args = new Array(_len13), _key13 = 0; _key13 < _len13; _key13++) {
148
- args[_key13] = arguments[_key13];
149
- }
150
- return originalFn.apply(this, args);
151
- });
152
- expect((0, _polyfillDetection.getPolyfills)()).toEqual(['WeakMap']);
153
- WeakMap = originalFn;
154
- });
155
- test('should indicate WeakSet constructor is polyfilled', () => {
156
- const originalFn = WeakSet;
157
- WeakSet = jest.fn(function () {
158
- for (var _len14 = arguments.length, args = new Array(_len14), _key14 = 0; _key14 < _len14; _key14++) {
159
- args[_key14] = arguments[_key14];
160
- }
161
- return originalFn.apply(this, args);
162
- });
163
- expect((0, _polyfillDetection.getPolyfills)()).toEqual(['WeakSet']);
164
- WeakSet = originalFn;
165
- });
@@ -1,16 +0,0 @@
1
- "use strict";
2
-
3
- var _faker = require("@faker-js/faker");
4
- var _interactionNode = require("./interaction-node");
5
- test('finishing node with cancelled parent should not throw an error', () => {
6
- const interaction = {
7
- remaining: 0,
8
- onNodeAdded: jest.fn(),
9
- checkFinish: jest.fn()
10
- };
11
- const interactionRootNode = new _interactionNode.InteractionNode(interaction, null, 'interaction', _faker.faker.date.past().getUTCSeconds());
12
- const interactionNode = interactionRootNode.child('test', _faker.faker.date.past().getUTCSeconds(), 'test', false);
13
- interactionRootNode.cancel();
14
- interactionNode.finish();
15
- expect(interactionRootNode.children.length).toEqual(0);
16
- });
@@ -1,10 +0,0 @@
1
- /*
2
- * Copyright 2020 New Relic Corporation. All rights reserved.
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
-
6
- /* eslint-disable no-useless-escape */
7
-
8
- export var ffVersion = 0;
9
- var match = navigator.userAgent.match(/Firefox[\/\s](\d+\.\d+)/);
10
- if (match) ffVersion = +match[1];
@@ -1,11 +0,0 @@
1
- export const isiOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
2
-
3
- /* Feature detection to get our version(s). */
4
-
5
- // Shared Web Workers introduced in iOS 16.0+ and n/a in 15.6-
6
- export const iOS_below16 = isiOS && Boolean(typeof SharedWorker === 'undefined');
7
- /*
8
- ^ It was discovered in Safari 14 (https://bugs.webkit.org/show_bug.cgi?id=225305) that the buffered flag in PerformanceObserver
9
- did not work. This affects our onFCP metric in particular since web-vitals uses that flag to retrieve paint timing entries.
10
- This was fixed in v16+.
11
- */
@@ -1,278 +0,0 @@
1
- import { faker } from '@faker-js/faker';
2
- let mockNREUM;
3
- let runtime;
4
- beforeEach(() => {
5
- mockNREUM = {};
6
- runtime = {};
7
- jest.doMock('../window/nreum', () => ({
8
- __esModule: true,
9
- gosNREUM: jest.fn(() => mockNREUM)
10
- }));
11
- jest.doMock('../config/config', () => ({
12
- __esModule: true,
13
- getRuntime: jest.fn(() => runtime)
14
- }));
15
- });
16
- afterEach(() => {
17
- jest.resetModules();
18
- jest.resetAllMocks();
19
- });
20
- describe('global event-emitter', () => {
21
- test('it returns the event-emitter defined on window.NREUM', async () => {
22
- const mockEE = {};
23
- mockNREUM.ee = mockEE;
24
- const {
25
- ee
26
- } = await import('./contextual-ee');
27
- expect(ee).toEqual(mockEE);
28
- });
29
- test('it sets the global event-emitter on window.NREUM', async () => {
30
- const {
31
- ee
32
- } = await import('./contextual-ee');
33
- expect(ee).toEqual(mockNREUM.ee);
34
- });
35
- });
36
- describe('scoping event-emitter', () => {
37
- test('it creates a new child event-emitter', async () => {
38
- const {
39
- ee
40
- } = await import('./contextual-ee');
41
- const childName = faker.datatype.uuid();
42
- const result = ee.get(childName);
43
- expect(result).not.toEqual(mockNREUM.ee);
44
- expect(result).toEqual(ee.get(childName)); // Should always return the same event-emitter
45
- expect(result.debugId).toEqual(childName);
46
- });
47
- test('it creates a child event-emitter with an isolated backlog', async () => {
48
- const childName = faker.random.alphaNumeric(16);
49
- jest.doMock('../config/config', () => ({
50
- __esModule: true,
51
- getRuntime: jest.fn(id => {
52
- if (id === childName) {
53
- return {
54
- isolatedBacklog: true
55
- };
56
- }
57
- return runtime;
58
- })
59
- }));
60
- const {
61
- ee
62
- } = await import('./contextual-ee');
63
- const result = ee.get(childName);
64
- expect(ee.backlog).not.toBe(result.backlog);
65
- });
66
- });
67
- describe('event-emitter context', () => {
68
- test('it returns a new context', async () => {
69
- const {
70
- ee
71
- } = await import('./contextual-ee');
72
- const result = ee.context();
73
- expect(result).toEqual({});
74
- });
75
- test('it returns the same context', async () => {
76
- const {
77
- ee
78
- } = await import('./contextual-ee');
79
- const result = ee.context();
80
- expect(result).toEqual(ee.context(result));
81
- });
82
- test('it adds the context to the provided object', async () => {
83
- const {
84
- ee
85
- } = await import('./contextual-ee');
86
- const obj = {};
87
- const result = ee.context(obj);
88
- expect(result).toEqual(obj['nr@context']);
89
- });
90
- });
91
- describe('event-emitter buffer', () => {
92
- test('it should create a new buffer for the given group', async () => {
93
- const {
94
- ee
95
- } = await import('./contextual-ee');
96
- const eventType = faker.datatype.uuid();
97
- const group = faker.datatype.uuid();
98
- ee.buffer([eventType], group);
99
- expect(ee.backlog).toEqual(expect.objectContaining({
100
- [group]: []
101
- }));
102
- expect(ee.isBuffering(eventType)).toEqual(true);
103
- });
104
- test('it should default group to "feature"', async () => {
105
- const {
106
- ee
107
- } = await import('./contextual-ee');
108
- const eventType = faker.datatype.uuid();
109
- ee.buffer([eventType]);
110
- expect(ee.backlog).toEqual(expect.objectContaining({
111
- feature: []
112
- }));
113
- expect(ee.isBuffering(eventType)).toEqual(true);
114
- });
115
- test('it should not create buffer if event-emitter is aborted', async () => {
116
- const {
117
- ee
118
- } = await import('./contextual-ee');
119
- const eventType = faker.datatype.uuid();
120
- const group = faker.datatype.uuid();
121
- ee.backlog = {
122
- api: ['foo', 'bar', 'baz']
123
- };
124
- ee.abort();
125
- ee.buffer([eventType], group);
126
- expect(ee.backlog).toEqual({});
127
- expect(ee.isBuffering(eventType)).toEqual(false);
128
- });
129
- });
130
- describe('event-emitter abort', () => {
131
- test('it aborts if there is an API backlog', async () => {
132
- const {
133
- ee
134
- } = await import('./contextual-ee');
135
- ee.backlog = {
136
- api: ['foo', 'bar', 'baz']
137
- };
138
- ee.abort();
139
- expect(ee.aborted).toEqual(true);
140
- expect(ee.backlog).toEqual({});
141
- });
142
- test('it aborts if there is a feature backlog', async () => {
143
- const {
144
- ee
145
- } = await import('./contextual-ee');
146
- ee.backlog = {
147
- feature: ['foo', 'bar', 'baz']
148
- };
149
- ee.abort();
150
- expect(ee.aborted).toEqual(true);
151
- expect(ee.backlog).toEqual({});
152
- });
153
- });
154
- describe('event-emitter emit', () => {
155
- test('should execute the listener', async () => {
156
- const {
157
- ee
158
- } = await import('./contextual-ee');
159
- const mockListener = jest.fn();
160
- const eventType = faker.datatype.uuid();
161
- const eventArgs = ['a', 'b', 'c'];
162
- ee.on(eventType, mockListener);
163
- ee.emit(eventType, eventArgs);
164
- expect(mockListener).toHaveBeenCalledWith(eventArgs[0], eventArgs[1], eventArgs[2]);
165
- });
166
- test('should not execute the listener after removal', async () => {
167
- const {
168
- ee
169
- } = await import('./contextual-ee');
170
- const mockListener = jest.fn();
171
- const eventType = faker.datatype.uuid();
172
- const eventArgs = ['a', 'b', 'c'];
173
- ee.on(eventType, mockListener);
174
- ee.emit(eventType, eventArgs);
175
- ee.removeEventListener(eventType, mockListener);
176
- ee.emit(eventType, eventArgs);
177
- expect(mockListener).toHaveBeenCalledTimes(1);
178
- });
179
- test('should return early if global event-emitter is aborted', async () => {
180
- const {
181
- ee
182
- } = await import('./contextual-ee');
183
- const mockListener = jest.fn();
184
- const eventType = faker.datatype.uuid();
185
- const eventArgs = ['a', 'b', 'c'];
186
- ee.backlog = {
187
- api: ['foo', 'bar', 'baz']
188
- };
189
- ee.abort();
190
- ee.on(eventType, mockListener);
191
- ee.emit(eventType, eventArgs);
192
- expect(mockListener).toHaveBeenCalledTimes(0);
193
- });
194
- test('should still emit if global event-emitter is aborted but force flag is true', async () => {
195
- const {
196
- ee
197
- } = await import('./contextual-ee');
198
- const scopeEE = ee.get(faker.datatype.uuid());
199
- const mockScopeListener = jest.fn();
200
- const eventType = faker.datatype.uuid();
201
- const eventArgs = ['a', 'b', 'c'];
202
- ee.backlog = {
203
- api: ['foo', 'bar', 'baz']
204
- };
205
- ee.abort();
206
- scopeEE.on(eventType, mockScopeListener);
207
- scopeEE.emit(eventType, eventArgs, {}, true);
208
- expect(mockScopeListener).toHaveBeenCalledTimes(1);
209
- });
210
- test('should bubble the event if bubble flag is true', async () => {
211
- const {
212
- ee
213
- } = await import('./contextual-ee');
214
- const scopeEE = ee.get(faker.datatype.uuid());
215
- const mockListener = jest.fn();
216
- const mockScopeListener = jest.fn();
217
- const eventType = faker.datatype.uuid();
218
- const eventArgs = ['a', 'b', 'c'];
219
- ee.on(eventType, mockListener);
220
- scopeEE.on(eventType, mockScopeListener);
221
- scopeEE.emit(eventType, eventArgs, {}, false, true);
222
- expect(mockScopeListener).toHaveBeenCalledTimes(1);
223
- expect(mockListener).toHaveBeenCalledTimes(1);
224
- });
225
- test('should not bubble the event if bubble flag is false', async () => {
226
- const {
227
- ee
228
- } = await import('./contextual-ee');
229
- const scopeEE = ee.get(faker.datatype.uuid());
230
- const mockListener = jest.fn();
231
- const mockScopeListener = jest.fn();
232
- const eventType = faker.datatype.uuid();
233
- const eventArgs = ['a', 'b', 'c'];
234
- ee.on(eventType, mockListener);
235
- scopeEE.on(eventType, mockScopeListener);
236
- scopeEE.emit(eventType, eventArgs, {}, false, false);
237
- expect(mockScopeListener).toHaveBeenCalledTimes(1);
238
- expect(mockListener).not.toHaveBeenCalled();
239
- });
240
- test('should buffer the event on the scoped event-emitter', async () => {
241
- const {
242
- ee
243
- } = await import('./contextual-ee');
244
- const scopeEE = ee.get(faker.datatype.uuid());
245
- const mockListener = jest.fn();
246
- const mockScopeListener = jest.fn();
247
- const eventType = faker.datatype.uuid();
248
- const eventArgs = ['a', 'b', 'c'];
249
- ee.on(eventType, mockListener);
250
- ee.buffer([eventType]);
251
- scopeEE.on(eventType, mockScopeListener);
252
- scopeEE.buffer([eventType]);
253
- scopeEE.emit(eventType, eventArgs, {}, false, false);
254
- expect(mockScopeListener).toHaveBeenCalledTimes(1);
255
- expect(mockListener).not.toHaveBeenCalled();
256
- expect(scopeEE.backlog.feature).toEqual(expect.arrayContaining([expect.arrayContaining([scopeEE, eventType, eventArgs, {}])]));
257
- expect(ee.backlog.feature).toEqual(scopeEE.backlog.feature);
258
- });
259
- });
260
- describe('getOrSetContext', () => {
261
- test('it returns a new context', async () => {
262
- const {
263
- getOrSetContext
264
- } = await import('./contextual-ee');
265
- const obj = {};
266
- const result = getOrSetContext(obj);
267
- expect(result).toEqual({});
268
- expect(result).toEqual(obj['nr@context']);
269
- });
270
- test('it returns the same context', async () => {
271
- const {
272
- getOrSetContext
273
- } = await import('./contextual-ee');
274
- const obj = {};
275
- const result = getOrSetContext(obj);
276
- expect(getOrSetContext(obj)).toEqual(result);
277
- });
278
- });