@posthog/core 1.70.0 → 1.71.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/capture-v1/package.json +6 -0
- package/dist/capture-v1/compression.d.ts +18 -0
- package/dist/capture-v1/compression.d.ts.map +1 -0
- package/dist/capture-v1/compression.js +70 -0
- package/dist/capture-v1/compression.mjs +26 -0
- package/dist/capture-v1/errors.d.ts +48 -0
- package/dist/capture-v1/errors.d.ts.map +1 -0
- package/dist/capture-v1/errors.js +82 -0
- package/dist/capture-v1/errors.mjs +38 -0
- package/dist/capture-v1/index.d.ts +15 -0
- package/dist/capture-v1/index.d.ts.map +1 -0
- package/dist/capture-v1/index.js +88 -0
- package/dist/capture-v1/index.mjs +7 -0
- package/dist/capture-v1/sender.d.ts +150 -0
- package/dist/capture-v1/sender.d.ts.map +1 -0
- package/dist/capture-v1/sender.js +554 -0
- package/dist/capture-v1/sender.mjs +507 -0
- package/dist/capture-v1/serialize.d.ts +30 -0
- package/dist/capture-v1/serialize.d.ts.map +1 -0
- package/dist/capture-v1/serialize.js +106 -0
- package/dist/capture-v1/serialize.mjs +59 -0
- package/dist/capture-v1/transform.d.ts +19 -0
- package/dist/capture-v1/transform.d.ts.map +1 -0
- package/dist/capture-v1/transform.js +118 -0
- package/dist/capture-v1/transform.mjs +77 -0
- package/dist/capture-v1/types.d.ts +52 -0
- package/dist/capture-v1/types.d.ts.map +1 -0
- package/dist/capture-v1/types.js +44 -0
- package/dist/capture-v1/types.mjs +3 -0
- package/dist/capture-v1/uuid.d.ts +9 -0
- package/dist/capture-v1/uuid.d.ts.map +1 -0
- package/dist/capture-v1/uuid.js +75 -0
- package/dist/capture-v1/uuid.mjs +34 -0
- package/dist/featureFlagUtils.d.ts +7 -5
- package/dist/featureFlagUtils.d.ts.map +1 -1
- package/dist/featureFlagUtils.js +17 -11
- package/dist/featureFlagUtils.mjs +14 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +27 -16
- package/dist/index.mjs +1 -1
- package/dist/posthog-core-stateless.d.ts +40 -3
- package/dist/posthog-core-stateless.d.ts.map +1 -1
- package/dist/posthog-core-stateless.js +87 -19
- package/dist/posthog-core-stateless.mjs +87 -19
- package/dist/posthog-core.d.ts +138 -53
- package/dist/posthog-core.d.ts.map +1 -1
- package/dist/posthog-core.js +341 -115
- package/dist/posthog-core.mjs +338 -115
- package/dist/types.d.ts +24 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +25 -12
- package/dist/utils/index.mjs +1 -1
- package/dist/utils/json-utils.d.ts +11 -1
- package/dist/utils/json-utils.d.ts.map +1 -1
- package/dist/utils/json-utils.js +50 -2
- package/dist/utils/json-utils.mjs +46 -1
- package/package.json +12 -2
- package/src/capture-v1/compression.ts +50 -0
- package/src/capture-v1/errors.ts +91 -0
- package/src/capture-v1/index.ts +34 -0
- package/src/capture-v1/sender.ts +779 -0
- package/src/capture-v1/serialize.ts +113 -0
- package/src/capture-v1/transform.ts +135 -0
- package/src/capture-v1/types.ts +59 -0
- package/src/capture-v1/uuid.ts +53 -0
- package/src/featureFlagUtils.ts +22 -10
- package/src/index.ts +1 -0
- package/src/posthog-core-stateless.ts +166 -30
- package/src/posthog-core.ts +615 -178
- package/src/types.ts +21 -1
- package/src/utils/index.ts +1 -1
- package/src/utils/json-utils.ts +64 -1
- package/src/error-tracking/chunk-ids.spec.ts +0 -77
- package/src/error-tracking/coercers/error-event-coercer.spec.ts +0 -142
- package/src/error-tracking/coercers/promise-rejection-event.spec.ts +0 -77
- package/src/error-tracking/coercers/string-coercer.spec.ts +0 -26
- package/src/error-tracking/error-properties-builder.aggregate-errors.spec.ts +0 -412
- package/src/error-tracking/error-properties-builder.coerce.spec.ts +0 -337
- package/src/error-tracking/error-properties-builder.metadata.spec.ts +0 -318
- package/src/error-tracking/error-properties-builder.parse.spec.ts +0 -37
- package/src/error-tracking/exception-steps.spec.ts +0 -115
- package/src/error-tracking/parsers/base.spec.ts +0 -156
- package/src/error-tracking/parsers/index.spec.ts +0 -270
- package/src/error-tracking/parsers/node.spec.ts +0 -34
- package/src/error-tracking/release.spec.ts +0 -34
- package/src/logs/index.spec.ts +0 -2421
- package/src/logs/logs-utils.spec.ts +0 -266
- package/src/metrics/index.spec.ts +0 -1249
- package/src/surveys/activation.spec.ts +0 -61
- package/src/surveys/events.spec.ts +0 -183
- package/src/surveys/keys.spec.ts +0 -29
- package/src/surveys/property-matching.spec.ts +0 -539
- package/src/surveys/shuffling.spec.ts +0 -51
- package/src/surveys/translations.spec.ts +0 -274
- package/src/surveys/validation.spec.ts +0 -168
- package/src/traces/config.spec.ts +0 -271
- package/src/traces/ids.spec.ts +0 -115
- package/src/traces/index.spec.ts +0 -3287
- package/src/traces/live-spans.spec.ts +0 -69
- package/src/traces/otlp.spec.ts +0 -368
- package/src/traces/span.spec.ts +0 -1137
- package/src/traces/traceparent.spec.ts +0 -184
- package/src/utils/bot-detection.spec.ts +0 -107
- package/src/utils/bucketed-rate-limiter.spec.ts +0 -327
- package/src/utils/json-utils.spec.ts +0 -115
- package/src/utils/named-error.spec.ts +0 -36
- package/src/utils/number-utils.spec.ts +0 -212
- package/src/utils/otlp-any-value.spec.ts +0 -376
- package/src/utils/otlp-resource.spec.ts +0 -171
- package/src/utils/promise-queue.spec.ts +0 -55
- package/src/utils/string-utils.spec.ts +0 -158
- package/src/utils/type-utils.spec.ts +0 -38
- package/src/utils/webview-app-utils.spec.ts +0 -118
- package/src/vendor/uuidv7.spec.ts +0 -26
package/src/types.ts
CHANGED
|
@@ -336,6 +336,16 @@ export type PostHogCaptureOptions = {
|
|
|
336
336
|
_originatedFromCaptureException?: boolean
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
+
/**
|
|
340
|
+
* Capture options with the event's `options`, as the React Native client accepts them on every
|
|
341
|
+
* event call. Core reads `options` from this type to decide whether an update processes the person.
|
|
342
|
+
* @internal
|
|
343
|
+
*/
|
|
344
|
+
export type PostHogCaptureOptionsWithEventOptions = PostHogCaptureOptions & {
|
|
345
|
+
/** Settings that tell PostHog how to process the event, sent apart from its properties. */
|
|
346
|
+
options?: { [key: string]: JsonType | undefined }
|
|
347
|
+
}
|
|
348
|
+
|
|
339
349
|
export type PostHogFetchResponse = {
|
|
340
350
|
status: number
|
|
341
351
|
text: () => Promise<string>
|
|
@@ -445,8 +455,14 @@ export type FeatureFlagResult = {
|
|
|
445
455
|
}
|
|
446
456
|
|
|
447
457
|
export type FeatureFlagResultOptions = {
|
|
448
|
-
/**
|
|
458
|
+
/**
|
|
459
|
+
* Whether to send a $feature_flag_called event. Defaults to true.
|
|
460
|
+
*
|
|
461
|
+
* @deprecated Use `sendFeatureFlagEvent` instead.
|
|
462
|
+
*/
|
|
449
463
|
sendEvent?: boolean
|
|
464
|
+
/** Whether to send a $feature_flag_called event. Takes precedence over `sendEvent`. */
|
|
465
|
+
sendFeatureFlagEvent?: boolean
|
|
450
466
|
}
|
|
451
467
|
|
|
452
468
|
export type IsFeatureEnabledOptions = FeatureFlagResultOptions & {
|
|
@@ -543,6 +559,8 @@ export type PostHogFlagsStorageFormat = Pick<PostHogFeatureFlagDetails, 'flags'>
|
|
|
543
559
|
errorsWhileComputingFlags?: boolean
|
|
544
560
|
quotaLimited?: string[]
|
|
545
561
|
requestError?: FeatureFlagRequestError
|
|
562
|
+
/** Set by a failed or quota-limited load when no load had succeeded and no flags were bootstrapped before it. */
|
|
563
|
+
noFlagsCached?: boolean
|
|
546
564
|
}
|
|
547
565
|
|
|
548
566
|
/**
|
|
@@ -1031,6 +1049,8 @@ export type CaptureEvent = {
|
|
|
1031
1049
|
$set_once?: PostHogEventProperties
|
|
1032
1050
|
/** Timestamp for the event */
|
|
1033
1051
|
timestamp?: Date
|
|
1052
|
+
/** Settings that tell PostHog how to process the event, sent apart from its properties. */
|
|
1053
|
+
options?: { [key: string]: JsonType | undefined }
|
|
1034
1054
|
}
|
|
1035
1055
|
|
|
1036
1056
|
/**
|
package/src/utils/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ export * from './browser-utils'
|
|
|
6
6
|
export * from './bucketed-rate-limiter'
|
|
7
7
|
// Named rather than `export *`: the budgets, markers and `sanitizeString` are
|
|
8
8
|
// shared with the OTLP encoder but are not public API.
|
|
9
|
-
export { toJsonSafeValue } from './json-utils'
|
|
9
|
+
export { toJsonSafeValue, withoutNullMembers } from './json-utils'
|
|
10
10
|
export { parseRetryAfterMs } from './retry-after'
|
|
11
11
|
export * from './number-utils'
|
|
12
12
|
export * from './string-utils'
|
package/src/utils/json-utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Traversal budgets and markers, shared with the OTLP attribute encoder. Not
|
|
2
|
-
* public API — `utils/index.ts` re-exports `toJsonSafeValue` only. */
|
|
2
|
+
* public API — `utils/index.ts` re-exports `toJsonSafeValue` and `withoutNullMembers` only. */
|
|
3
3
|
export const MAX_JSON_SAFE_VALUE_DEPTH = 20
|
|
4
4
|
export const MAX_JSON_SAFE_VALUE_ITEMS = 1_000
|
|
5
5
|
export const MAX_JSON_SAFE_VALUE_NODES = 10_000
|
|
@@ -186,3 +186,66 @@ export function assignUserAttributes<T extends Record<string, any>>(
|
|
|
186
186
|
}
|
|
187
187
|
return target
|
|
188
188
|
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Removes object members whose value is `null` or `undefined`, recursively, without touching array positions: a null
|
|
192
|
+
* array element stays `null`, and an object inside an array is replaced by its cleaned copy. Returns the input when
|
|
193
|
+
* nothing changes, and copies only the containers that change. Only plain objects without a `toJSON` method are
|
|
194
|
+
* cleaned; a value already being visited (a cycle), or nested `MAX_JSON_SAFE_VALUE_DEPTH` levels deep or more, is
|
|
195
|
+
* returned as it is.
|
|
196
|
+
*
|
|
197
|
+
* @internal Exposed for cross-package use within this SDK; not part of the stable public API.
|
|
198
|
+
*/
|
|
199
|
+
export function withoutNullMembers<T>(value: T): T {
|
|
200
|
+
const ancestors = new WeakSet<object>()
|
|
201
|
+
const clean = <V>(current: V, depth: number): V => {
|
|
202
|
+
if (
|
|
203
|
+
current === null ||
|
|
204
|
+
typeof current !== 'object' ||
|
|
205
|
+
ancestors.has(current as object) ||
|
|
206
|
+
depth >= MAX_JSON_SAFE_VALUE_DEPTH
|
|
207
|
+
) {
|
|
208
|
+
return current
|
|
209
|
+
}
|
|
210
|
+
if (Array.isArray(current)) {
|
|
211
|
+
ancestors.add(current)
|
|
212
|
+
try {
|
|
213
|
+
let changed = false
|
|
214
|
+
const cleaned = current.map((item) => {
|
|
215
|
+
const next = clean(item, depth + 1)
|
|
216
|
+
changed = changed || next !== item
|
|
217
|
+
return next
|
|
218
|
+
})
|
|
219
|
+
return (changed ? cleaned : current) as V
|
|
220
|
+
} finally {
|
|
221
|
+
ancestors.delete(current)
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const prototype = Object.getPrototypeOf(current)
|
|
225
|
+
if (
|
|
226
|
+
(prototype !== Object.prototype && prototype !== null) ||
|
|
227
|
+
typeof (current as { toJSON?: unknown }).toJSON === 'function'
|
|
228
|
+
) {
|
|
229
|
+
return current
|
|
230
|
+
}
|
|
231
|
+
ancestors.add(current as object)
|
|
232
|
+
try {
|
|
233
|
+
let changed = false
|
|
234
|
+
const cleaned: Record<string, unknown> = {}
|
|
235
|
+
for (const [key, member] of Object.entries(current as Record<string, unknown>)) {
|
|
236
|
+
if (member === null || member === undefined) {
|
|
237
|
+
changed = true
|
|
238
|
+
continue
|
|
239
|
+
}
|
|
240
|
+
const next = clean(member, depth + 1)
|
|
241
|
+
changed = changed || next !== member
|
|
242
|
+
// defineProperty, not assignment, so an own `__proto__` member is copied instead of setting the prototype.
|
|
243
|
+
Object.defineProperty(cleaned, key, { value: next, enumerable: true, writable: true, configurable: true })
|
|
244
|
+
}
|
|
245
|
+
return (changed ? cleaned : current) as V
|
|
246
|
+
} finally {
|
|
247
|
+
ancestors.delete(current as object)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return clean(value, 0)
|
|
251
|
+
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { StackParser } from './types'
|
|
2
|
-
|
|
3
|
-
const stackParser: StackParser = (stack) => [
|
|
4
|
-
{
|
|
5
|
-
platform: 'web:javascript',
|
|
6
|
-
filename: stack.split('|')[0],
|
|
7
|
-
},
|
|
8
|
-
]
|
|
9
|
-
|
|
10
|
-
describe('getFilenameToChunkIdMap', () => {
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
vi.resetModules()
|
|
13
|
-
delete (globalThis as any)._posthogChunkIds
|
|
14
|
-
delete (globalThis as any)._debugIds
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
afterEach(() => {
|
|
18
|
-
delete (globalThis as any)._posthogChunkIds
|
|
19
|
-
delete (globalThis as any)._debugIds
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('maps native debug IDs to filenames', async () => {
|
|
23
|
-
;(globalThis as any)._debugIds = {
|
|
24
|
-
'https://example.com/chunk.js|native': 'native-debug-id',
|
|
25
|
-
}
|
|
26
|
-
const { getFilenameToChunkIdMap } = await import('./chunk-ids')
|
|
27
|
-
|
|
28
|
-
expect(getFilenameToChunkIdMap(stackParser)).toEqual({
|
|
29
|
-
'https://example.com/chunk.js': 'native-debug-id',
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('prefers PostHog chunk IDs over native debug IDs for the same file', async () => {
|
|
34
|
-
;(globalThis as any)._debugIds = {
|
|
35
|
-
'https://example.com/chunk.js|native': 'native-debug-id',
|
|
36
|
-
}
|
|
37
|
-
;(globalThis as any)._posthogChunkIds = {
|
|
38
|
-
'https://example.com/chunk.js|posthog': 'posthog-chunk-id',
|
|
39
|
-
}
|
|
40
|
-
const { getFilenameToChunkIdMap } = await import('./chunk-ids')
|
|
41
|
-
|
|
42
|
-
expect(getFilenameToChunkIdMap(stackParser)).toEqual({
|
|
43
|
-
'https://example.com/chunk.js': 'posthog-chunk-id',
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it('refreshes the cached map when native debug IDs are added', async () => {
|
|
48
|
-
;(globalThis as any)._debugIds = {
|
|
49
|
-
'https://example.com/one.js|native': 'one',
|
|
50
|
-
}
|
|
51
|
-
const { getFilenameToChunkIdMap } = await import('./chunk-ids')
|
|
52
|
-
|
|
53
|
-
expect(getFilenameToChunkIdMap(stackParser)).toEqual({ 'https://example.com/one.js': 'one' })
|
|
54
|
-
|
|
55
|
-
;(globalThis as any)._debugIds['https://example.com/two.js|native'] = 'two'
|
|
56
|
-
|
|
57
|
-
expect(getFilenameToChunkIdMap(stackParser)).toEqual({
|
|
58
|
-
'https://example.com/one.js': 'one',
|
|
59
|
-
'https://example.com/two.js': 'two',
|
|
60
|
-
})
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('refreshes the cached map when a debug ID map is replaced with the same number of entries', async () => {
|
|
64
|
-
;(globalThis as any)._debugIds = {
|
|
65
|
-
'https://example.com/one.js|native': 'one',
|
|
66
|
-
}
|
|
67
|
-
const { getFilenameToChunkIdMap } = await import('./chunk-ids')
|
|
68
|
-
|
|
69
|
-
expect(getFilenameToChunkIdMap(stackParser)).toEqual({ 'https://example.com/one.js': 'one' })
|
|
70
|
-
|
|
71
|
-
;(globalThis as any)._debugIds = {
|
|
72
|
-
'https://example.com/two.js|native': 'two',
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
expect(getFilenameToChunkIdMap(stackParser)).toEqual({ 'https://example.com/two.js': 'two' })
|
|
76
|
-
})
|
|
77
|
-
})
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { ErrorPropertiesBuilder } from '../error-properties-builder'
|
|
2
|
-
import { createDefaultStackParser } from '../parsers'
|
|
3
|
-
import { Exception } from '../types'
|
|
4
|
-
import { ErrorCoercer } from './error-coercer'
|
|
5
|
-
import { ErrorEventCoercer } from './error-event-coercer'
|
|
6
|
-
import { EventCoercer } from './event-coercer'
|
|
7
|
-
import { ObjectCoercer } from './object-coercer'
|
|
8
|
-
import { PrimitiveCoercer } from './primitive-coercer'
|
|
9
|
-
import { StringCoercer } from './string-coercer'
|
|
10
|
-
|
|
11
|
-
// `ErrorEvent` is not available in the Node test environment, so use its runtime brand.
|
|
12
|
-
class FakeErrorEvent {
|
|
13
|
-
message?: string
|
|
14
|
-
error?: unknown
|
|
15
|
-
filename?: string
|
|
16
|
-
lineno?: number
|
|
17
|
-
colno?: number;
|
|
18
|
-
[Symbol.toStringTag] = 'ErrorEvent'
|
|
19
|
-
|
|
20
|
-
constructor(init: Partial<Omit<FakeErrorEvent, typeof Symbol.toStringTag>> = {}) {
|
|
21
|
-
Object.assign(this, init)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
describe('ErrorEventCoercer', () => {
|
|
26
|
-
const coercer = new ErrorEventCoercer()
|
|
27
|
-
const errorPropertiesBuilder = new ErrorPropertiesBuilder(
|
|
28
|
-
[coercer, new ErrorCoercer(), new EventCoercer(), new ObjectCoercer(), new StringCoercer(), new PrimitiveCoercer()],
|
|
29
|
-
createDefaultStackParser()
|
|
30
|
-
)
|
|
31
|
-
|
|
32
|
-
function buildException(input: unknown, syntheticException?: Error): Exception {
|
|
33
|
-
return errorPropertiesBuilder.buildFromUnknown(input, { syntheticException }).$exception_list[0]
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
it.each([
|
|
37
|
-
{
|
|
38
|
-
name: 'an ErrorEvent carrying an Error',
|
|
39
|
-
input: new FakeErrorEvent({ error: new Error('boom') }),
|
|
40
|
-
expected: true,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
name: 'an ErrorEvent carrying a message',
|
|
44
|
-
input: new FakeErrorEvent({ message: 'Script error.' }),
|
|
45
|
-
expected: true,
|
|
46
|
-
},
|
|
47
|
-
{ name: 'an ErrorEvent without an error or message', input: new FakeErrorEvent(), expected: false },
|
|
48
|
-
{ name: 'an ErrorEvent with an empty message', input: new FakeErrorEvent({ message: '' }), expected: false },
|
|
49
|
-
{ name: 'a non-ErrorEvent', input: { message: 'not an ErrorEvent' }, expected: false },
|
|
50
|
-
])('matches $name: $expected', ({ input, expected }) => {
|
|
51
|
-
expect(coercer.match(input)).toBe(expected)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it('unwraps the Error carried by the ErrorEvent', () => {
|
|
55
|
-
const error = new Error('Something broke')
|
|
56
|
-
error.name = 'CustomTestError'
|
|
57
|
-
|
|
58
|
-
expect(buildException(new FakeErrorEvent({ message: 'ignored', error }))).toMatchObject({
|
|
59
|
-
type: 'CustomTestError',
|
|
60
|
-
value: 'Something broke',
|
|
61
|
-
mechanism: { synthetic: false },
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
it('preserves the message and location when there is no Error object', () => {
|
|
66
|
-
const exception = buildException(
|
|
67
|
-
new FakeErrorEvent({
|
|
68
|
-
message: 'Uncaught TypeError: x is not a function',
|
|
69
|
-
filename: 'https://example.com/app.js',
|
|
70
|
-
lineno: 42,
|
|
71
|
-
colno: 13,
|
|
72
|
-
})
|
|
73
|
-
)
|
|
74
|
-
|
|
75
|
-
expect(exception).toMatchObject({
|
|
76
|
-
type: 'TypeError',
|
|
77
|
-
value: 'x is not a function',
|
|
78
|
-
mechanism: { synthetic: true },
|
|
79
|
-
stacktrace: {
|
|
80
|
-
frames: [
|
|
81
|
-
expect.objectContaining({
|
|
82
|
-
filename: 'https://example.com/app.js',
|
|
83
|
-
lineno: 42,
|
|
84
|
-
colno: 13,
|
|
85
|
-
}),
|
|
86
|
-
],
|
|
87
|
-
},
|
|
88
|
-
})
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it.each([
|
|
92
|
-
{ name: 'a zeroed position', lineno: 0, colno: 0 },
|
|
93
|
-
{ name: 'no position at all', lineno: undefined, colno: undefined },
|
|
94
|
-
{ name: 'a column but no line', lineno: 0, colno: 13 },
|
|
95
|
-
])('reports no stack trace for $name', ({ lineno, colno }) => {
|
|
96
|
-
const exception = buildException(
|
|
97
|
-
new FakeErrorEvent({
|
|
98
|
-
message: 'ResizeObserver loop completed with undelivered notifications.',
|
|
99
|
-
filename: 'https://example.com/dashboard/1',
|
|
100
|
-
lineno,
|
|
101
|
-
colno,
|
|
102
|
-
})
|
|
103
|
-
)
|
|
104
|
-
|
|
105
|
-
expect(exception.stacktrace).toBeUndefined()
|
|
106
|
-
expect(exception).toMatchObject({ value: 'ResizeObserver loop completed with undelivered notifications.' })
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('keeps a frame when only the column is zero', () => {
|
|
110
|
-
const exception = buildException(
|
|
111
|
-
new FakeErrorEvent({
|
|
112
|
-
message: 'Uncaught TypeError: x is not a function',
|
|
113
|
-
filename: 'https://example.com/app.js',
|
|
114
|
-
lineno: 42,
|
|
115
|
-
colno: 0,
|
|
116
|
-
})
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
expect(exception.stacktrace?.frames).toEqual([
|
|
120
|
-
expect.objectContaining({ filename: 'https://example.com/app.js', lineno: 42, colno: 0 }),
|
|
121
|
-
])
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
it('does not parse frame-shaped lines from a multiline message', () => {
|
|
125
|
-
const exception = buildException(
|
|
126
|
-
new FakeErrorEvent({
|
|
127
|
-
message: 'Something broke\n at injected (https://example.com/injected.js:1:2)',
|
|
128
|
-
filename: 'https://example.com/app.js',
|
|
129
|
-
lineno: 42,
|
|
130
|
-
colno: 13,
|
|
131
|
-
})
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
expect(exception.stacktrace?.frames).toEqual([
|
|
135
|
-
expect.objectContaining({
|
|
136
|
-
filename: 'https://example.com/app.js',
|
|
137
|
-
lineno: 42,
|
|
138
|
-
colno: 13,
|
|
139
|
-
}),
|
|
140
|
-
])
|
|
141
|
-
})
|
|
142
|
-
})
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { CoercingContext } from '../types'
|
|
2
|
-
import { PromiseRejectionEventCoercer } from './promise-rejection-event'
|
|
3
|
-
|
|
4
|
-
type PromiseRejectionEventTypes = 'rejectionhandled' | 'unhandledrejection'
|
|
5
|
-
|
|
6
|
-
type PromiseRejectionEventInit = {
|
|
7
|
-
promise: Promise<any>
|
|
8
|
-
reason: any
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
class PromiseRejectionEvent extends Event {
|
|
12
|
-
public readonly promise: Promise<any>
|
|
13
|
-
public readonly reason: any
|
|
14
|
-
|
|
15
|
-
public constructor(type: PromiseRejectionEventTypes, options: PromiseRejectionEventInit) {
|
|
16
|
-
super(type)
|
|
17
|
-
|
|
18
|
-
this.promise = options.promise
|
|
19
|
-
this.reason = options.reason
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
describe('PromiseRejectionEventCoercer', () => {
|
|
24
|
-
const coercer = new PromiseRejectionEventCoercer()
|
|
25
|
-
|
|
26
|
-
it('should coerce event with reason is a primitive', () => {
|
|
27
|
-
const pre = new PromiseRejectionEvent('unhandledrejection', {
|
|
28
|
-
promise: Promise.resolve('wat'),
|
|
29
|
-
reason: 'My house is on fire',
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
const ctx = {
|
|
33
|
-
apply: vi.fn(() => ({
|
|
34
|
-
type: 'MockType',
|
|
35
|
-
value: 'MockValue',
|
|
36
|
-
synthetic: true,
|
|
37
|
-
})),
|
|
38
|
-
next: vi.fn(),
|
|
39
|
-
} as CoercingContext
|
|
40
|
-
|
|
41
|
-
expect(coercer.coerce(pre, ctx)).toMatchObject({
|
|
42
|
-
type: 'UnhandledRejection',
|
|
43
|
-
value: 'Non-Error promise rejection captured with value: My house is on fire',
|
|
44
|
-
synthetic: true,
|
|
45
|
-
})
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('should coerce event with reason is an error', () => {
|
|
49
|
-
class CustomTestError extends Error {
|
|
50
|
-
constructor(message: string) {
|
|
51
|
-
super(message)
|
|
52
|
-
this.name = 'CustomTestError'
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const pre = new PromiseRejectionEvent('unhandledrejection', {
|
|
57
|
-
promise: Promise.resolve('wat'),
|
|
58
|
-
reason: new CustomTestError('My house is on fire'),
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
const ctx = {
|
|
62
|
-
apply: vi.fn((err: Error) => ({
|
|
63
|
-
type: err.name,
|
|
64
|
-
value: err.message,
|
|
65
|
-
stack: err.stack,
|
|
66
|
-
synthetic: false,
|
|
67
|
-
})),
|
|
68
|
-
next: vi.fn(),
|
|
69
|
-
} as CoercingContext
|
|
70
|
-
|
|
71
|
-
expect(coercer.coerce(pre, ctx)).toMatchObject({
|
|
72
|
-
type: 'CustomTestError',
|
|
73
|
-
value: 'My house is on fire',
|
|
74
|
-
synthetic: false,
|
|
75
|
-
})
|
|
76
|
-
})
|
|
77
|
-
})
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { CoercingContext } from '../types'
|
|
2
|
-
import { StringCoercer } from './string-coercer'
|
|
3
|
-
|
|
4
|
-
describe('PromiseRejectionEventCoercer', () => {
|
|
5
|
-
const coercer = new StringCoercer()
|
|
6
|
-
|
|
7
|
-
it('should parse string', () => {
|
|
8
|
-
const infos = coercer.getInfos('My house is on fire')
|
|
9
|
-
expect(infos).toMatchObject([undefined, 'My house is on fire'])
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
it('should parse errors', () => {
|
|
13
|
-
const infos = coercer.getInfos('ReferenceError: My house is on fire')
|
|
14
|
-
expect(infos).toMatchObject(['ReferenceError', 'My house is on fire'])
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it('should discard prefix', () => {
|
|
18
|
-
const infos = coercer.getInfos('Uncaught exception: ReferenceError: My house is on fire')
|
|
19
|
-
expect(infos).toMatchObject(['ReferenceError', 'My house is on fire'])
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('should not match other patterns', () => {
|
|
23
|
-
const infos = coercer.getInfos('ValueError: ReferenceError: My house is on fire')
|
|
24
|
-
expect(infos).toMatchObject([undefined, 'ValueError: ReferenceError: My house is on fire'])
|
|
25
|
-
})
|
|
26
|
-
})
|