Skip to content

Commit c27e1e3

Browse files
committed
test: Tests for prepareFramesForEvent reserved words frame strip
1 parent 3ce404b commit c27e1e3

File tree

3 files changed

+84
-8
lines changed

3 files changed

+84
-8
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## Unreleased
44

55
- [node] HTTP(S) Proxy support
6-
- [npde] Expose lastEventId method
6+
- [node] Expose lastEventId method
7+
- [browser] Correctly detect and remove wrapped function frames
78

89
## 4.3.4
910

packages/browser/rollup.config.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ const commitHash = require('child_process')
88
.execSync('git rev-parse --short HEAD', { encoding: 'utf-8' })
99
.trim();
1010

11+
const uglifyInstance = uglify({
12+
mangle: {
13+
// captureExceptions and captureMessage are public API methods and they don't need to be listed here
14+
// as mangler doesn't touch user-facing thing, however sentryWrapepd is not, and it would be mangled into a minified version.
15+
// We need those full names to correctly detect our internal frames for stripping.
16+
// I listed all of them here just for the clarity sake, as they are all used in the frames manipulation process.
17+
reserved: ['captureException', 'captureMessage', 'sentryWrapped'],
18+
},
19+
});
20+
1121
const bundleConfig = {
1222
input: 'src/index.ts',
1323
output: {
@@ -86,13 +96,7 @@ export default [
8696
// Uglify has to be at the end of compilation, BUT before the license banner
8797
plugins: bundleConfig.plugins
8898
.slice(0, -1)
89-
.concat(
90-
uglify({
91-
mangle: {
92-
reserved: ['addBreadcrumb', 'captureException', 'captureMessage', 'sentryWrapped'],
93-
},
94-
}),
95-
)
99+
.concat(uglifyInstance)
96100
.concat(bundleConfig.plugins.slice(-1)),
97101
}),
98102
];

packages/browser/test/parsers.test.ts

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { expect } from 'chai';
2+
import { prepareFramesForEvent } from '../src/parsers';
3+
4+
describe('Parsers', () => {
5+
describe('prepareFramesForEvent()', () => {
6+
describe('removed top frame if its internally reserved word (public API)', async () => {
7+
it('reserved captureException', () => {
8+
const stack = [
9+
{ context: ['x'], column: 1, line: 4, url: 'anything.js', func: 'captureException', args: [] },
10+
{ context: ['x'], column: 1, line: 3, url: 'anything.js', func: 'foo', args: [] },
11+
{ context: ['x'], column: 1, line: 2, url: 'anything.js', func: 'bar', args: [] },
12+
];
13+
14+
// Should remove `captureException` as its a name considered "internal"
15+
const frames = prepareFramesForEvent(stack);
16+
17+
expect(frames.length).equal(2);
18+
expect(frames[0].function).equal('bar');
19+
expect(frames[1].function).equal('foo');
20+
});
21+
22+
it('reserved captureMessage', () => {
23+
const stack = [
24+
{ context: ['x'], column: 1, line: 4, url: 'anything.js', func: 'captureMessage', args: [] },
25+
{ context: ['x'], column: 1, line: 3, url: 'anything.js', func: 'foo', args: [] },
26+
{ context: ['x'], column: 1, line: 2, url: 'anything.js', func: 'bar', args: [] },
27+
];
28+
29+
// Should remove `captureMessage` as its a name considered "internal"
30+
const frames = prepareFramesForEvent(stack);
31+
32+
expect(frames.length).equal(2);
33+
expect(frames[0].function).equal('bar');
34+
expect(frames[1].function).equal('foo');
35+
});
36+
});
37+
38+
describe('removed bottom frame if its internally reserved word (internal API)', async () => {
39+
it('reserved sentryWrapped', () => {
40+
const stack = [
41+
{ context: ['x'], column: 1, line: 3, url: 'anything.js', func: 'foo', args: [] },
42+
{ context: ['x'], column: 1, line: 2, url: 'anything.js', func: 'bar', args: [] },
43+
{ context: ['x'], column: 1, line: 1, url: 'anything.js', func: 'sentryWrapped', args: [] },
44+
];
45+
46+
// Should remove `sentryWrapped` as its a name considered "internal"
47+
const frames = prepareFramesForEvent(stack);
48+
49+
expect(frames.length).equal(2);
50+
expect(frames[0].function).equal('bar');
51+
expect(frames[1].function).equal('foo');
52+
});
53+
});
54+
55+
it('removed top and bottom frame if they are internally reserved words', async () => {
56+
const stack = [
57+
{ context: ['x'], column: 1, line: 4, url: 'anything.js', func: 'captureMessage', args: [] },
58+
{ context: ['x'], column: 1, line: 3, url: 'anything.js', func: 'foo', args: [] },
59+
{ context: ['x'], column: 1, line: 2, url: 'anything.js', func: 'bar', args: [] },
60+
{ context: ['x'], column: 1, line: 1, url: 'anything.js', func: 'sentryWrapped', args: [] },
61+
];
62+
63+
// Should remove `captureMessage` and `sentryWrapped` as its a name considered "internal"
64+
const frames = prepareFramesForEvent(stack);
65+
66+
expect(frames.length).equal(2);
67+
expect(frames[0].function).equal('bar');
68+
expect(frames[1].function).equal('foo');
69+
});
70+
});
71+
});

0 commit comments

Comments
 (0)