Skip to content

Commit 2da12d1

Browse files
author
Luca Forstner
committed
Add test
1 parent 81c326e commit 2da12d1

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

packages/core/src/utils/prepareEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ function applyClientOptions(event: Event, options: ClientOptions): void {
116116
/**
117117
* Applies debug metadata images to the event in order to apply source maps by looking up their debug ID.
118118
*/
119-
function applyDebugMetadata(event: Event, stackParser: StackParser): void {
119+
export function applyDebugMetadata(event: Event, stackParser: StackParser): void {
120120
const debugIdMap = GLOBAL_OBJ._sentryDebugIds;
121121
if (debugIdMap) {
122122
// Build a map of abs_path -> debug_id
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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

Comments
 (0)