|
1 | 1 | import * as SentryNode from '@sentry/node';
|
2 | 2 | import type { NodeClient } from '@sentry/node';
|
| 3 | +import { Scope } from '@sentry/node'; |
| 4 | +import { getGlobalScope } from '@sentry/node'; |
3 | 5 | import { SDK_VERSION } from '@sentry/node';
|
| 6 | +import type { EventProcessor } from '@sentry/types'; |
4 | 7 | import { beforeEach, describe, expect, it, vi } from 'vitest';
|
5 | 8 | import type { SentryNuxtServerOptions } from '../../src/common/types';
|
6 | 9 | import { init } from '../../src/server';
|
7 |
| -import { mergeRegisterEsmLoaderHooks } from '../../src/server/sdk'; |
| 10 | +import { clientSourceMapErrorFilter, mergeRegisterEsmLoaderHooks } from '../../src/server/sdk'; |
8 | 11 |
|
9 | 12 | const nodeInit = vi.spyOn(SentryNode, 'init');
|
10 | 13 |
|
@@ -83,6 +86,88 @@ describe('Nuxt Server SDK', () => {
|
83 | 86 | expect.any(Object),
|
84 | 87 | );
|
85 | 88 | });
|
| 89 | + |
| 90 | + it('registers an event processor', async () => { |
| 91 | + let passedEventProcessors: EventProcessor[] = []; |
| 92 | + const addEventProcessor = vi |
| 93 | + .spyOn(getGlobalScope(), 'addEventProcessor') |
| 94 | + .mockImplementation((eventProcessor: EventProcessor) => { |
| 95 | + passedEventProcessors = [...passedEventProcessors, eventProcessor]; |
| 96 | + return new Scope(); |
| 97 | + }); |
| 98 | + |
| 99 | + init({ |
| 100 | + dsn: 'https://[email protected]/1337', |
| 101 | + }); |
| 102 | + |
| 103 | + expect(addEventProcessor).toHaveBeenCalledTimes(2); |
| 104 | + expect(passedEventProcessors[0]?.id).toEqual('NuxtLowQualityTransactionsFilter'); |
| 105 | + expect(passedEventProcessors[1]?.id).toEqual('NuxtClientSourceMapErrorFilter'); |
| 106 | + }); |
| 107 | + }); |
| 108 | + |
| 109 | + describe('clientSourceMapErrorFilter', () => { |
| 110 | + const options = { debug: false }; |
| 111 | + const filter = clientSourceMapErrorFilter(options); |
| 112 | + |
| 113 | + describe('filters out errors', () => { |
| 114 | + it.each([ |
| 115 | + [ |
| 116 | + 'source map errors with leading /', |
| 117 | + { |
| 118 | + exception: { values: [{ value: "ENOENT: no such file or directory, open '/path/to/_nuxt/file.js.map'" }] }, |
| 119 | + }, |
| 120 | + ], |
| 121 | + [ |
| 122 | + 'source map errors without leading /', |
| 123 | + { exception: { values: [{ value: "ENOENT: no such file or directory, open 'path/to/_nuxt/file.js.map'" }] } }, |
| 124 | + ], |
| 125 | + [ |
| 126 | + 'source map errors with long path', |
| 127 | + { |
| 128 | + exception: { |
| 129 | + values: [ |
| 130 | + { |
| 131 | + value: |
| 132 | + "ENOENT: no such file or directory, open 'path/to/public/_nuxt/public/long/long/path/file.js.map'", |
| 133 | + }, |
| 134 | + ], |
| 135 | + }, |
| 136 | + }, |
| 137 | + ], |
| 138 | + ])('filters out %s', (_, event) => { |
| 139 | + // @ts-expect-error Event type is not correct in tests |
| 140 | + expect(filter(event)).toBeNull(); |
| 141 | + }); |
| 142 | + }); |
| 143 | + |
| 144 | + describe('does not filter out errors', () => { |
| 145 | + it.each([ |
| 146 | + ['other errors', { exception: { values: [{ value: 'Some other error' }] } }], |
| 147 | + ['events with no exceptions', {}], |
| 148 | + [ |
| 149 | + 'events without _nuxt in path', |
| 150 | + { |
| 151 | + exception: { values: [{ value: "ENOENT: no such file or directory, open '/path/to/other/file.js.map'" }] }, |
| 152 | + }, |
| 153 | + ], |
| 154 | + [ |
| 155 | + 'source map errors with different casing', |
| 156 | + { |
| 157 | + exception: { values: [{ value: "ENOENT: No Such file or directory, open '/path/to/_nuxt/file.js.map'" }] }, |
| 158 | + }, |
| 159 | + ], |
| 160 | + [ |
| 161 | + 'non-source-map file', |
| 162 | + { exception: { values: [{ value: "ENOENT: no such file or directory, open '/path/to/_nuxt/file.js'" }] } }, |
| 163 | + ], |
| 164 | + ['events with no exception values', { exception: { values: [] } }], |
| 165 | + ['events with null exception value', { exception: { values: [null] } }], |
| 166 | + ])('does not filter out %s', (_, event) => { |
| 167 | + // @ts-expect-error Event type is not correct in tests |
| 168 | + expect(filter(event)).toEqual(event); |
| 169 | + }); |
| 170 | + }); |
86 | 171 | });
|
87 | 172 |
|
88 | 173 | describe('mergeRegisterEsmLoaderHooks', () => {
|
|
0 commit comments