whisper-money/resources/js/lib/sentry.test.ts

82 lines
2.5 KiB
TypeScript

import type { Event } from '@sentry/react';
import { describe, expect, it } from 'vitest';
import { isChunkLoadErrorEvent, isPostMessageDataCloneNoise } from './sentry';
describe('isChunkLoadErrorEvent', () => {
it('drops recoverable Vite dynamic import failures', () => {
const event: Event = {
exception: {
values: [
{
type: 'TypeError',
value: 'Failed to fetch dynamically imported module: https://whisper.money/build/assets/accounts-BO3xxENF.js',
},
],
},
};
expect(isChunkLoadErrorEvent(event)).toBe(true);
});
it('keeps unrelated TypeError events', () => {
const event: Event = {
exception: {
values: [
{
type: 'TypeError',
value: 'Cannot read properties of undefined',
},
],
},
};
expect(isChunkLoadErrorEvent(event)).toBe(false);
});
});
describe('isPostMessageDataCloneNoise', () => {
it('drops browser postMessage DataCloneError noise', () => {
const event: Event = {
exception: {
values: [
{
type: 'DataCloneError',
value: 'The object can not be cloned.',
stacktrace: {
frames: [
{
function: 'Window.postMessage',
},
],
},
},
],
},
};
expect(isPostMessageDataCloneNoise(event)).toBe(true);
});
it('keeps other DataCloneError events without postMessage frames', () => {
const event: Event = {
exception: {
values: [
{
type: 'DataCloneError',
value: 'The object can not be cloned.',
stacktrace: {
frames: [
{
function: 'structuredClone',
},
],
},
},
],
},
};
expect(isPostMessageDataCloneNoise(event)).toBe(false);
});
});