@newrelic/browser-agent 1.241.0 → 1.243.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 (132) hide show
  1. package/CHANGELOG.md +1465 -0
  2. package/dist/cjs/cdn/polyfills/lite.js +13 -1
  3. package/dist/cjs/cdn/polyfills/pro.js +17 -1
  4. package/dist/cjs/cdn/polyfills/spa.js +18 -1
  5. package/dist/cjs/common/config/state/init.js +32 -5
  6. package/dist/cjs/common/constants/env.cdn.js +1 -1
  7. package/dist/cjs/common/constants/env.npm.js +1 -1
  8. package/dist/cjs/common/dom/query-selector.js +16 -0
  9. package/dist/cjs/common/session/session-entity.js +20 -2
  10. package/dist/cjs/common/wrap/wrap-function.js +1 -1
  11. package/dist/cjs/features/ajax/aggregate/index.js +1 -1
  12. package/dist/cjs/features/session_replay/aggregate/index.js +84 -50
  13. package/dist/cjs/features/utils/feature-base.js +1 -2
  14. package/dist/cjs/features/utils/instrument-base.js +1 -0
  15. package/dist/cjs/loaders/api/api.js +2 -2
  16. package/dist/cjs/loaders/api/apiAsync.js +0 -37
  17. package/dist/cjs/loaders/configure/configure.js +1 -1
  18. package/dist/cjs/loaders/configure/public-path.js +6 -3
  19. package/dist/esm/cdn/polyfills/lite.js +8 -1
  20. package/dist/esm/cdn/polyfills/pro.js +13 -2
  21. package/dist/esm/cdn/polyfills/spa.js +13 -1
  22. package/dist/esm/common/config/state/init.js +32 -5
  23. package/dist/esm/common/constants/env.cdn.js +1 -1
  24. package/dist/esm/common/constants/env.npm.js +1 -1
  25. package/dist/esm/common/dom/query-selector.js +9 -0
  26. package/dist/esm/common/session/session-entity.js +18 -1
  27. package/dist/esm/common/wrap/wrap-function.js +1 -1
  28. package/dist/esm/features/ajax/aggregate/index.js +1 -1
  29. package/dist/esm/features/session_replay/aggregate/index.js +83 -50
  30. package/dist/esm/features/utils/feature-base.js +1 -2
  31. package/dist/esm/features/utils/instrument-base.js +1 -0
  32. package/dist/esm/loaders/api/api.js +2 -2
  33. package/dist/esm/loaders/api/apiAsync.js +1 -36
  34. package/dist/esm/loaders/configure/configure.js +1 -1
  35. package/dist/esm/loaders/configure/public-path.js +6 -3
  36. package/dist/types/common/config/state/init.d.ts.map +1 -1
  37. package/dist/types/common/dom/query-selector.d.ts +2 -0
  38. package/dist/types/common/dom/query-selector.d.ts.map +1 -0
  39. package/dist/types/common/session/session-entity.d.ts +5 -0
  40. package/dist/types/common/session/session-entity.d.ts.map +1 -1
  41. package/dist/types/features/session_replay/aggregate/index.d.ts +11 -14
  42. package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
  43. package/dist/types/features/utils/feature-base.d.ts.map +1 -1
  44. package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
  45. package/dist/types/loaders/api/api.d.ts.map +1 -1
  46. package/dist/types/loaders/api/apiAsync.d.ts.map +1 -1
  47. package/dist/types/loaders/configure/public-path.d.ts +1 -1
  48. package/dist/types/loaders/configure/public-path.d.ts.map +1 -1
  49. package/package.json +2 -2
  50. package/src/cdn/polyfills/lite.js +14 -1
  51. package/src/cdn/polyfills/pro.js +23 -2
  52. package/src/cdn/polyfills/spa.js +24 -1
  53. package/src/common/config/state/init.js +33 -4
  54. package/src/common/dom/query-selector.js +9 -0
  55. package/src/common/session/session-entity.js +20 -1
  56. package/src/common/wrap/wrap-function.js +1 -1
  57. package/src/features/ajax/aggregate/index.js +2 -2
  58. package/src/features/session_replay/aggregate/index.js +82 -34
  59. package/src/features/utils/feature-base.js +1 -2
  60. package/src/features/utils/instrument-base.js +1 -0
  61. package/src/loaders/api/api.js +1 -2
  62. package/src/loaders/api/apiAsync.js +1 -39
  63. package/src/loaders/configure/configure.js +1 -1
  64. package/src/loaders/configure/public-path.js +6 -3
  65. package/src/common/aggregate/aggregator.test.js +0 -107
  66. package/src/common/config/state/configurable.test.js +0 -73
  67. package/src/common/config/state/info.test.js +0 -31
  68. package/src/common/config/state/init.test.js +0 -28
  69. package/src/common/config/state/loader-config.test.js +0 -21
  70. package/src/common/config/state/runtime.test.js +0 -21
  71. package/src/common/constants/env.cdn.test.js +0 -7
  72. package/src/common/constants/env.npm.test.js +0 -7
  73. package/src/common/constants/env.test.js +0 -7
  74. package/src/common/constants/runtime.test.js +0 -176
  75. package/src/common/deny-list/deny-list.test.js +0 -104
  76. package/src/common/drain/drain.test.js +0 -74
  77. package/src/common/event-emitter/contextual-ee.component-test.js +0 -293
  78. package/src/common/event-emitter/handle.test.js +0 -56
  79. package/src/common/event-emitter/register-handler.test.js +0 -61
  80. package/src/common/harvest/harvest-scheduler.test.js +0 -492
  81. package/src/common/harvest/harvest.test.js +0 -813
  82. package/src/common/ids/id.test.js +0 -92
  83. package/src/common/ids/unique-id.test.js +0 -58
  84. package/src/common/session/session-entity.component-test.js +0 -346
  85. package/src/common/storage/local-storage.test.js +0 -17
  86. package/src/common/timer/interaction-timer.component-test.js +0 -212
  87. package/src/common/timer/timer.test.js +0 -99
  88. package/src/common/timing/nav-timing.test.js +0 -161
  89. package/src/common/url/canonicalize-url.test.js +0 -45
  90. package/src/common/url/clean-url.test.js +0 -25
  91. package/src/common/url/encode.test.js +0 -81
  92. package/src/common/url/location.test.js +0 -15
  93. package/src/common/url/parse-url.test.js +0 -110
  94. package/src/common/url/protocol.test.js +0 -17
  95. package/src/common/util/console.test.js +0 -34
  96. package/src/common/util/data-size.test.js +0 -56
  97. package/src/common/util/feature-flags.test.js +0 -94
  98. package/src/common/util/get-or-set.test.js +0 -58
  99. package/src/common/util/invoke.test.js +0 -65
  100. package/src/common/util/map-own.test.js +0 -52
  101. package/src/common/util/obfuscate.component-test.js +0 -173
  102. package/src/common/util/stringify.test.js +0 -49
  103. package/src/common/util/submit-data.test.js +0 -183
  104. package/src/common/util/traverse.test.js +0 -50
  105. package/src/common/vitals/cumulative-layout-shift.test.js +0 -71
  106. package/src/common/vitals/first-contentful-paint.test.js +0 -124
  107. package/src/common/vitals/first-input-delay.test.js +0 -88
  108. package/src/common/vitals/first-paint.test.js +0 -127
  109. package/src/common/vitals/interaction-to-next-paint.test.js +0 -74
  110. package/src/common/vitals/largest-contentful-paint.test.js +0 -94
  111. package/src/common/vitals/long-task.test.js +0 -122
  112. package/src/common/vitals/time-to-first-byte.test.js +0 -147
  113. package/src/common/vitals/vital-metric.test.js +0 -171
  114. package/src/common/wrap/wrap-promise.component-test.js +0 -110
  115. package/src/features/ajax/instrument/distributed-tracing.test.js +0 -375
  116. package/src/features/jserrors/aggregate/canonical-function-name.test.js +0 -13
  117. package/src/features/jserrors/aggregate/compute-stack-trace.test.js +0 -414
  118. package/src/features/jserrors/aggregate/format-stack-trace.test.js +0 -39
  119. package/src/features/jserrors/aggregate/string-hash-code.test.js +0 -12
  120. package/src/features/metrics/aggregate/framework-detection.test.js +0 -332
  121. package/src/features/page_view_timing/aggregate/index.component-test.js +0 -86
  122. package/src/features/session_replay/aggregate/index.component-test.js +0 -317
  123. package/src/features/spa/aggregate/interaction-node.test.js +0 -17
  124. package/src/features/utils/agent-session.test.js +0 -194
  125. package/src/features/utils/aggregate-base.test.js +0 -123
  126. package/src/features/utils/feature-base.test.js +0 -45
  127. package/src/features/utils/handler-cache.test.js +0 -72
  128. package/src/features/utils/instrument-base.test.js +0 -216
  129. package/src/features/utils/lazy-feature-loader.test.js +0 -37
  130. package/src/loaders/api/api.component-test.js +0 -45
  131. package/src/loaders/api/api.test.js +0 -85
  132. package/src/loaders/api/apiAsync.test.js +0 -17
@@ -1,414 +0,0 @@
1
- import { faker } from '@faker-js/faker'
2
- import { browserErrorUtils } from '../../../../tools/testing-utils'
3
-
4
- const globalScopeLocation = 'https://example.com/'
5
-
6
- const mockGlobalScopeLocation = (url) => {
7
- jest.doMock('../../../common/constants/runtime', () => ({
8
- initialLocation: url || globalScopeLocation
9
- }))
10
- }
11
-
12
- afterEach(() => {
13
- jest.resetModules()
14
- jest.clearAllMocks()
15
- })
16
-
17
- const baseMockError = {
18
- toString: 'RangeError: Invalid array length',
19
- name: 'RangeError',
20
- constructor: 'function RangeError() { [native code] }',
21
- message: 'Invalid array length',
22
- stack:
23
- 'RangeError: Invalid array length\n' +
24
- ' at errorTest (' + globalScopeLocation + '?loader=spa#hello:74:16)\n' +
25
- ' at captureError (' + globalScopeLocation + 'js/script.js?loader=spa:17:9)\n' +
26
- ' at onload (' + globalScopeLocation + 'js/script.js?loader=spa:70:5)'
27
- }
28
-
29
- test('parsing should return a failure for a null error object', async () => {
30
- mockGlobalScopeLocation()
31
- const { computeStackTrace } = await import('./compute-stack-trace')
32
- const result = computeStackTrace(null)
33
-
34
- expect(result).toEqual(expect.objectContaining({
35
- mode: 'failed',
36
- stackString: '',
37
- frames: []
38
- }))
39
- })
40
-
41
- describe('errors with stack property', () => {
42
- test('should show <inline> for same-page stack string URLs but not sub-paths', async () => {
43
- const mockError = browserErrorUtils.constructError({
44
- ...baseMockError
45
- })
46
-
47
- mockGlobalScopeLocation()
48
- const { computeStackTrace } = await import('./compute-stack-trace')
49
- const result = computeStackTrace(mockError)
50
-
51
- expect(result).toEqual(expect.objectContaining({
52
- stackString: // canonicalized
53
- 'RangeError: Invalid array length\n' +
54
- ' at errorTest (<inline>:74:16)\n' +
55
- ' at captureError (' + globalScopeLocation + 'js/script.js:17:9)\n' +
56
- ' at onload (' + globalScopeLocation + 'js/script.js:70:5)'
57
- }))
58
- })
59
-
60
- test('parsed name should be unknown when name and constructor are missing', async () => {
61
- const mockError = browserErrorUtils.constructError({
62
- ...baseMockError,
63
- name: null,
64
- constructor: null
65
- })
66
-
67
- mockGlobalScopeLocation()
68
- const { computeStackTrace } = await import('./compute-stack-trace')
69
- const result = computeStackTrace(mockError)
70
-
71
- expect(result).toEqual(expect.objectContaining({
72
- mode: 'stack',
73
- name: 'unknown'
74
- }))
75
- })
76
-
77
- test('parsed stack should not contain nrWrapper', async () => {
78
- const alteredError = baseMockError
79
- alteredError.stack +=
80
- '\n at nrWrapper (' + globalScopeLocation + '?loader=spa:60:17)'
81
- const mockError = browserErrorUtils.constructError(alteredError)
82
-
83
- mockGlobalScopeLocation()
84
- const { computeStackTrace } = await import('./compute-stack-trace')
85
- const result = computeStackTrace(mockError)
86
-
87
- expect(result).toEqual(expect.objectContaining({
88
- mode: 'stack',
89
- name: mockError.name,
90
- message: mockError.message,
91
- stackString: expect.not.stringContaining('nrWrapper')
92
- }))
93
- expect(result.frames).not.toContainEqual(expect.objectContaining({
94
- func: 'nrWrapper'
95
- }))
96
- })
97
-
98
- test('stack should still parse when column numbers are missing', async () => {
99
- const mockError = browserErrorUtils.constructError({
100
- ...baseMockError,
101
- stack:
102
- 'RangeError: Invalid array length\n' +
103
- 'Error: Blocked a frame with origin "http://bam-test-1.nr-local.net:3334" from accessing a cross-origin frame.\n' +
104
- ' at errorTest (' + globalScopeLocation + '?loader=spa:60)\n' +
105
- ' at captureError (' + globalScopeLocation + '?loader=spa:17)\n' +
106
- ' at onload (' + globalScopeLocation + '?loader=spa:57)'
107
- })
108
-
109
- mockGlobalScopeLocation()
110
- const { computeStackTrace } = await import('./compute-stack-trace')
111
- const result = computeStackTrace(mockError)
112
-
113
- expect(result).toEqual(expect.objectContaining({
114
- mode: 'stack',
115
- name: mockError.name,
116
- message: mockError.message,
117
- stackString:
118
- 'RangeError: Invalid array length\n' +
119
- 'Error: Blocked a frame with origin "http://bam-test-1.nr-local.net:3334" from accessing a cross-origin frame.\n' +
120
- ' at errorTest (<inline>:60)\n' +
121
- ' at captureError (<inline>:17)\n' +
122
- ' at onload (<inline>:57)'
123
- }))
124
- expect(result.frames.length).toEqual(3)
125
- expect(result.frames).toContainEqual(expect.objectContaining({
126
- func: 'errorTest',
127
- column: null
128
- }))
129
- expect(result.frames).toContainEqual(expect.objectContaining({
130
- func: 'captureError',
131
- column: null
132
- }))
133
- expect(result.frames).toContainEqual(expect.objectContaining({
134
- func: 'onload',
135
- column: null
136
- }))
137
- })
138
-
139
- test('parser can handle chrome eval stack', async () => {
140
- const mockError = browserErrorUtils.constructError({
141
- ...baseMockError,
142
- stack:
143
- ' at foobar (eval at foobar (' + globalScopeLocation + '))'
144
- })
145
-
146
- mockGlobalScopeLocation()
147
- const { computeStackTrace } = await import('./compute-stack-trace')
148
- const result = computeStackTrace(mockError)
149
-
150
- expect(result).toEqual(expect.objectContaining({
151
- mode: 'stack',
152
- name: mockError.name,
153
- message: mockError.message,
154
- stackString: mockError.stack
155
- }))
156
- expect(result.frames.length).toEqual(1)
157
- expect(result.frames).toContainEqual(expect.objectContaining({
158
- func: 'evaluated code'
159
- }))
160
- })
161
-
162
- test('parser can handle ie eval stack', async () => {
163
- const mockError = browserErrorUtils.constructError({
164
- toString: 'TypeError: Permission denied',
165
- name: 'TypeError',
166
- constructor: '\nfunction TypeError() {\n [native code]\n}\n',
167
- message: 'Permission denied',
168
- stack:
169
- ' at Function code (Function code:23:23)'
170
- })
171
-
172
- mockGlobalScopeLocation()
173
- const { computeStackTrace } = await import('./compute-stack-trace')
174
- const result = computeStackTrace(mockError)
175
-
176
- expect(result).toEqual(expect.objectContaining({
177
- mode: 'stack',
178
- name: mockError.name,
179
- message: mockError.message,
180
- stackString: mockError.stack
181
- }))
182
- expect(result.frames.length).toEqual(1)
183
- expect(result.frames).toContainEqual(expect.objectContaining({
184
- func: 'evaluated code'
185
- }))
186
- })
187
-
188
- test('parser can handle stack with anonymous function', async () => {
189
- const mockError = browserErrorUtils.constructError({
190
- ...baseMockError,
191
- stack:
192
- 'anonymous'
193
- })
194
-
195
- mockGlobalScopeLocation()
196
- const { computeStackTrace } = await import('./compute-stack-trace')
197
- const result = computeStackTrace(mockError)
198
-
199
- expect(result).toEqual(expect.objectContaining({
200
- mode: 'stack',
201
- name: mockError.name,
202
- message: mockError.message,
203
- stackString: mockError.stack
204
- }))
205
- expect(result.frames.length).toEqual(1)
206
- expect(result.frames).toContainEqual(expect.objectContaining({
207
- func: 'evaluated code'
208
- }))
209
- })
210
- })
211
-
212
- describe('errors without stack property and with line property', () => {
213
- /**
214
- * @deprecated sourceURL is no longer present in errors for any browsers we support
215
- */
216
- test('parsed stack should contain sourceURL and line number', async () => {
217
- const sourceURL = faker.internet.url()
218
- const mockError = browserErrorUtils.constructError({
219
- ...baseMockError,
220
- stack: undefined,
221
- line: 100,
222
- sourceURL
223
- })
224
-
225
- mockGlobalScopeLocation()
226
- const { computeStackTrace } = await import('./compute-stack-trace')
227
- const result = computeStackTrace(mockError)
228
-
229
- expect(result).toEqual(expect.objectContaining({
230
- mode: 'sourceline',
231
- name: mockError.name,
232
- message: mockError.message,
233
- stackString: `${mockError.name}: ${mockError.message}\n at ${sourceURL}:${mockError.line}`
234
- }))
235
- expect(result.frames.length).toEqual(1)
236
- expect(result.frames).toContainEqual(expect.objectContaining({
237
- url: sourceURL,
238
- line: mockError.line
239
- }))
240
- })
241
-
242
- /**
243
- * @deprecated sourceURL is no longer present in errors for any browsers we support
244
- */
245
- test('parsed stack should contain sourceURL, line number, and column number', async () => {
246
- const sourceURL = faker.internet.url()
247
- const mockError = browserErrorUtils.constructError({
248
- ...baseMockError,
249
- line: 100,
250
- column: 200,
251
- stack: undefined,
252
- sourceURL
253
- })
254
-
255
- mockGlobalScopeLocation()
256
- const { computeStackTrace } = await import('./compute-stack-trace')
257
- const result = computeStackTrace(mockError)
258
-
259
- expect(result).toEqual(expect.objectContaining({
260
- mode: 'sourceline',
261
- name: mockError.name,
262
- message: mockError.message,
263
- stackString: `${mockError.name}: ${mockError.message}\n at ${sourceURL}:${mockError.line}:${mockError.column}`
264
- }))
265
- expect(result.frames.length).toEqual(1)
266
- expect(result.frames).toContainEqual(expect.objectContaining({
267
- url: sourceURL,
268
- line: mockError.line,
269
- column: mockError.column
270
- }))
271
- })
272
-
273
- test('parsed stack should contain "evaluated code" if sourceURL property is not present', async () => {
274
- const mockError = browserErrorUtils.constructError({
275
- ...baseMockError,
276
- line: 100,
277
- column: 200,
278
- stack: undefined
279
- })
280
-
281
- mockGlobalScopeLocation()
282
- const { computeStackTrace } = await import('./compute-stack-trace')
283
- const result = computeStackTrace(mockError)
284
-
285
- expect(result).toEqual(expect.objectContaining({
286
- mode: 'sourceline',
287
- name: mockError.name,
288
- message: mockError.message,
289
- stackString: `RangeError: ${mockError.message}\n in evaluated code`
290
- }))
291
- expect(result.frames.length).toEqual(1)
292
- expect(result.frames).toContainEqual(expect.objectContaining({
293
- func: 'evaluated code'
294
- }))
295
- })
296
-
297
- /**
298
- * @deprecated sourceURL is no longer present in errors for any browsers we support
299
- */
300
- test('should show <inline> for same-page URLs', async () => {
301
- const pageLocation = faker.internet.url()
302
- const sourceURL = pageLocation + '?abc=123'
303
- const mockError = browserErrorUtils.constructError({
304
- ...baseMockError,
305
- line: 100,
306
- column: 200,
307
- stack: undefined,
308
- sourceURL
309
- })
310
-
311
- mockGlobalScopeLocation(pageLocation)
312
- const { computeStackTrace } = await import('./compute-stack-trace')
313
- const result = computeStackTrace(mockError)
314
-
315
- expect(result).toEqual(expect.objectContaining({
316
- stackString: `${mockError.name}: ${mockError.message}\n at <inline>:${mockError.line}:${mockError.column}`
317
- }))
318
- expect(result.frames).toContainEqual(expect.objectContaining({
319
- url: '<inline>'
320
- }))
321
- })
322
-
323
- /**
324
- * @deprecated sourceURL is no longer present in errors for any browsers we support
325
- */
326
- test('should NOT show <inline> for same-domain URLs with a sub-path', async () => {
327
- const pageLocation = faker.internet.url()
328
- const sourceURL = pageLocation + '/path/to/script.js'
329
- const mockError = browserErrorUtils.constructError({
330
- ...baseMockError,
331
- line: 100,
332
- column: 200,
333
- stack: undefined,
334
- sourceURL
335
- })
336
-
337
- mockGlobalScopeLocation(pageLocation)
338
- const { computeStackTrace } = await import('./compute-stack-trace')
339
- const result = computeStackTrace(mockError)
340
-
341
- expect(result).toEqual(expect.objectContaining({
342
- stackString: `${mockError.name}: ${mockError.message}\n at ${sourceURL}:${mockError.line}:${mockError.column}`
343
- }))
344
- expect(result.frames).toContainEqual(expect.objectContaining({
345
- url: sourceURL
346
- }))
347
- })
348
-
349
- // TODO: computeStackTraceBySourceAndLine does not respect firefox lineNumber and columnNumber properties when stack is empty
350
- })
351
-
352
- /**
353
- * These tests are here because JS allows you to throw absolutely anything as an
354
- * error, including primitives.
355
- */
356
- describe('errors that are messages only or primitives', () => {
357
- test('parser should get error name from constructor', async () => {
358
- const mockError = browserErrorUtils.constructError({
359
- toString: '0',
360
- constructor: 'function Number() { [native code] }'
361
- })
362
-
363
- mockGlobalScopeLocation()
364
- const { computeStackTrace } = await import('./compute-stack-trace')
365
- const result = computeStackTrace(mockError)
366
-
367
- expect(result).toEqual(expect.objectContaining({
368
- mode: 'nameonly',
369
- name: 'Number',
370
- stackString: 'Number: undefined',
371
- frames: []
372
- }))
373
- })
374
-
375
- test('parser should get error name from name property', async () => {
376
- const mockError = browserErrorUtils.constructError({
377
- toString: '0',
378
- name: faker.datatype.uuid(),
379
- constructor: 'function Number() { [native code] }'
380
- })
381
-
382
- mockGlobalScopeLocation()
383
- const { computeStackTrace } = await import('./compute-stack-trace')
384
- const result = computeStackTrace(mockError)
385
-
386
- expect(result).toEqual(expect.objectContaining({
387
- mode: 'nameonly',
388
- name: mockError.name,
389
- stackString: `${mockError.name}: undefined`,
390
- frames: []
391
- }))
392
- })
393
-
394
- test('parser should include the message property', async () => {
395
- const mockError = browserErrorUtils.constructError({
396
- toString: '0',
397
- name: faker.datatype.uuid(),
398
- message: faker.datatype.uuid(),
399
- constructor: 'function Number() { [native code] }'
400
- })
401
-
402
- mockGlobalScopeLocation()
403
- const { computeStackTrace } = await import('./compute-stack-trace')
404
- const result = computeStackTrace(mockError)
405
-
406
- expect(result).toEqual(expect.objectContaining({
407
- mode: 'nameonly',
408
- name: mockError.name,
409
- message: mockError.message,
410
- stackString: `${mockError.name}: ${mockError.message}`,
411
- frames: []
412
- }))
413
- })
414
- })
@@ -1,39 +0,0 @@
1
- import { faker } from '@faker-js/faker'
2
- import { formatStackTrace, truncateSize } from './format-stack-trace'
3
-
4
- describe('formatStackTrace', () => {
5
- test.each([
6
- {
7
- input: ['line 1', 'line 2', 'line 3', 'line 4'],
8
- expected: 'line 1\nline 2\nline 3\nline 4',
9
- title: 'Appends all stack lines together'
10
- },
11
- { input: ['', 'line 1', 'line 2'], expected: 'line 1\nline 2', title: 'Strips leading empty stack frame' },
12
- { input: ['line 1', 'line 2', ''], expected: 'line 1\nline 2', title: 'Strips ending empty stack frame' }
13
- ])('$title', ({ input, expected }) => {
14
- const result = formatStackTrace(input)
15
-
16
- expect(result).toEqual(expected)
17
- })
18
-
19
- test('truncates the middle of the stack lines when more than 100', () => {
20
- const input = Array.apply(null, Array(200))
21
- .map(() => faker.datatype.uuid())
22
- const expected = input.slice(0, 50).join('\n') + `\n< ...truncated ${input.length - 100} lines... >\n` + input.slice(-50).join('\n')
23
-
24
- const result = formatStackTrace(input)
25
-
26
- expect(result).toEqual(expected)
27
- })
28
- })
29
-
30
- describe('truncateSize', () => {
31
- test('should truncate stack string to max limit', () => {
32
- const maxSize = 65530
33
- const input = faker.datatype.string(maxSize + 1)
34
-
35
- const result = truncateSize(input)
36
-
37
- expect(result).toEqual(input.slice(0, maxSize))
38
- })
39
- })
@@ -1,12 +0,0 @@
1
- import { stringHashCode } from './string-hash-code'
2
-
3
- test.each([
4
- { input: undefined, expected: 0, title: 'Return 0 for undefined input' },
5
- { input: null, expected: 0, title: 'Return 0 for null input' },
6
- { input: '', expected: 0, title: 'Return 0 for empty string input' },
7
- { input: 'lksjdflksjdf', expected: 32668720, title: 'Return valid hash of string' }
8
- ])('$title', ({ input, expected }) => {
9
- const result = stringHashCode(input)
10
-
11
- expect(result).toEqual(expected)
12
- })