|
| 1 | +import type { Event } from '@sentry/types'; |
| 2 | +import { createStackParser, GLOBAL_OBJ } from '@sentry/utils'; |
| 3 | + |
| 4 | +import { applyDebugMetadata } from '../../src/utils/prepareEvent'; |
| 5 | + |
| 6 | +describe('applyDebugMetadata', () => { |
| 7 | + afterEach(() => { |
| 8 | + GLOBAL_OBJ._sentryDebugIds = undefined; |
| 9 | + }); |
| 10 | + |
| 11 | + it('should put debug source map images in debug_meta field', () => { |
| 12 | + GLOBAL_OBJ._sentryDebugIds = { |
| 13 | + 'filename1.js\nfilename1.js': 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa', |
| 14 | + 'filename2.js\nfilename2.js': 'bbbbbbbb-bbbb-4bbb-bbbb-bbbbbbbbbb', |
| 15 | + 'filename4.js\nfilename4.js': 'cccccccc-cccc-4ccc-cccc-cccccccccc', |
| 16 | + }; |
| 17 | + |
| 18 | + const stackParser = createStackParser([0, line => ({ filename: line, abs_path: line })]); |
| 19 | + |
| 20 | + const event: Event = { |
| 21 | + exception: { |
| 22 | + values: [ |
| 23 | + { |
| 24 | + stacktrace: { |
| 25 | + frames: [ |
| 26 | + { abs_path: 'filename1.js', filename: 'filename1.js' }, |
| 27 | + { abs_path: 'filename2.js', filename: 'filename2.js' }, |
| 28 | + { abs_path: 'filename1.js', filename: 'filename1.js' }, |
| 29 | + { abs_path: 'filename3.js', filename: 'filename3.js' }, |
| 30 | + ], |
| 31 | + }, |
| 32 | + }, |
| 33 | + ], |
| 34 | + }, |
| 35 | + }; |
| 36 | + |
| 37 | + applyDebugMetadata(event, stackParser); |
| 38 | + |
| 39 | + expect(event.debug_meta?.images).toContainEqual({ |
| 40 | + type: 'sourcemap', |
| 41 | + code_file: 'filename1.js', |
| 42 | + debug_id: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa', |
| 43 | + }); |
| 44 | + |
| 45 | + expect(event.debug_meta?.images).toContainEqual({ |
| 46 | + type: 'sourcemap', |
| 47 | + code_file: 'filename2.js', |
| 48 | + debug_id: 'bbbbbbbb-bbbb-4bbb-bbbb-bbbbbbbbbb', |
| 49 | + }); |
| 50 | + |
| 51 | + // expect not to contain an image for the stack frame that doesn't have a corresponding debug id |
| 52 | + expect(event.debug_meta?.images).not.toContainEqual( |
| 53 | + expect.objectContaining({ |
| 54 | + type: 'sourcemap', |
| 55 | + code_file: 'filename3.js', |
| 56 | + }), |
| 57 | + ); |
| 58 | + |
| 59 | + // expect not to contain an image for the debug id mapping that isn't contained in the stack trace |
| 60 | + expect(event.debug_meta?.images).not.toContainEqual( |
| 61 | + expect.objectContaining({ |
| 62 | + type: 'sourcemap', |
| 63 | + code_file: 'filename4.js', |
| 64 | + debug_id: 'cccccccc-cccc-4ccc-cccc-cccccccccc', |
| 65 | + }), |
| 66 | + ); |
| 67 | + }); |
| 68 | +}); |
0 commit comments