Skip to content

Commit

Permalink
test: Tests for prepareFramesForEvent reserved words frame strip
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Nov 27, 2018
1 parent 3ce404b commit c27e1e3
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Unreleased

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

## 4.3.4

Expand Down
18 changes: 11 additions & 7 deletions packages/browser/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ const commitHash = require('child_process')
.execSync('git rev-parse --short HEAD', { encoding: 'utf-8' })
.trim();

const uglifyInstance = uglify({
mangle: {
// captureExceptions and captureMessage are public API methods and they don't need to be listed here
// as mangler doesn't touch user-facing thing, however sentryWrapepd is not, and it would be mangled into a minified version.
// We need those full names to correctly detect our internal frames for stripping.
// I listed all of them here just for the clarity sake, as they are all used in the frames manipulation process.
reserved: ['captureException', 'captureMessage', 'sentryWrapped'],
},
});

const bundleConfig = {
input: 'src/index.ts',
output: {
Expand Down Expand Up @@ -86,13 +96,7 @@ export default [
// Uglify has to be at the end of compilation, BUT before the license banner
plugins: bundleConfig.plugins
.slice(0, -1)
.concat(
uglify({
mangle: {
reserved: ['addBreadcrumb', 'captureException', 'captureMessage', 'sentryWrapped'],
},
}),
)
.concat(uglifyInstance)
.concat(bundleConfig.plugins.slice(-1)),
}),
];
71 changes: 71 additions & 0 deletions packages/browser/test/parsers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { expect } from 'chai';
import { prepareFramesForEvent } from '../src/parsers';

describe('Parsers', () => {
describe('prepareFramesForEvent()', () => {
describe('removed top frame if its internally reserved word (public API)', async () => {
it('reserved captureException', () => {
const stack = [
{ context: ['x'], column: 1, line: 4, url: 'anything.js', func: 'captureException', args: [] },
{ context: ['x'], column: 1, line: 3, url: 'anything.js', func: 'foo', args: [] },
{ context: ['x'], column: 1, line: 2, url: 'anything.js', func: 'bar', args: [] },
];

// Should remove `captureException` as its a name considered "internal"
const frames = prepareFramesForEvent(stack);

expect(frames.length).equal(2);
expect(frames[0].function).equal('bar');
expect(frames[1].function).equal('foo');
});

it('reserved captureMessage', () => {
const stack = [
{ context: ['x'], column: 1, line: 4, url: 'anything.js', func: 'captureMessage', args: [] },
{ context: ['x'], column: 1, line: 3, url: 'anything.js', func: 'foo', args: [] },
{ context: ['x'], column: 1, line: 2, url: 'anything.js', func: 'bar', args: [] },
];

// Should remove `captureMessage` as its a name considered "internal"
const frames = prepareFramesForEvent(stack);

expect(frames.length).equal(2);
expect(frames[0].function).equal('bar');
expect(frames[1].function).equal('foo');
});
});

describe('removed bottom frame if its internally reserved word (internal API)', async () => {
it('reserved sentryWrapped', () => {
const stack = [
{ context: ['x'], column: 1, line: 3, url: 'anything.js', func: 'foo', args: [] },
{ context: ['x'], column: 1, line: 2, url: 'anything.js', func: 'bar', args: [] },
{ context: ['x'], column: 1, line: 1, url: 'anything.js', func: 'sentryWrapped', args: [] },
];

// Should remove `sentryWrapped` as its a name considered "internal"
const frames = prepareFramesForEvent(stack);

expect(frames.length).equal(2);
expect(frames[0].function).equal('bar');
expect(frames[1].function).equal('foo');
});
});

it('removed top and bottom frame if they are internally reserved words', async () => {
const stack = [
{ context: ['x'], column: 1, line: 4, url: 'anything.js', func: 'captureMessage', args: [] },
{ context: ['x'], column: 1, line: 3, url: 'anything.js', func: 'foo', args: [] },
{ context: ['x'], column: 1, line: 2, url: 'anything.js', func: 'bar', args: [] },
{ context: ['x'], column: 1, line: 1, url: 'anything.js', func: 'sentryWrapped', args: [] },
];

// Should remove `captureMessage` and `sentryWrapped` as its a name considered "internal"
const frames = prepareFramesForEvent(stack);

expect(frames.length).equal(2);
expect(frames[0].function).equal('bar');
expect(frames[1].function).equal('foo');
});
});
});

0 comments on commit c27e1e3

Please sign in to comment.