Skip to content

feat(wasm): Add test against minified browser bundle #4526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 40 additions & 34 deletions packages/wasm/test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,46 @@
const HOST = `http://localhost:${process.env.PORT}`;

describe('Wasm', () => {
it('captured exception should include modified frames and debug_meta attribute', async () => {
await page.goto(HOST);
const event = await page.evaluate(async () => {
return window.getEvent();
});
// TODO: This is a quick and dirty way to test the minified browser bundle - `min-bundle.html` is an exact replica of
// `index.html` save the browser bundle `src` value. In the long run, we should rig it so just the bundle can be
// passed in. (Or, once the new bundling process is nailed down, stop testing against the minified bundle, since
// that's not really what this test is for.)
['index.html', 'min-bundle.html'].forEach(pagePath =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to suggest dynamically generating these using a template, but we should wait till the new bundling process is nailed down.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's exactly what I meant by passing the bundle in. If we decide to keep testing against both, a template is indeed probably the easiest way to do that. I'm not 100% convinced we'll even need to/want to separately test against the minified bundle once we've solved bundling, but that's a bridge we can cross when we get there.

it(`captured exception should include modified frames and debug_meta attribute - ${pagePath}`, async () => {
await page.goto(`${HOST}/${pagePath}`);
const event = await page.evaluate(async () => {
return window.getEvent();
});

expect(event.exception.values[0].stacktrace.frames).toEqual(
expect.arrayContaining([
expect.objectContaining({
filename: `${HOST}/simple.wasm`,
function: 'internal_func',
in_app: true,
instruction_addr: '0x8c',
addr_mode: 'rel:0',
platform: 'native',
}),
expect.objectContaining({
filename: `${HOST}/`,
function: 'crash',
in_app: true,
}),
]),
);
expect(event.exception.values[0].stacktrace.frames).toEqual(
expect.arrayContaining([
expect.objectContaining({
filename: `${HOST}/simple.wasm`,
function: 'internal_func',
in_app: true,
instruction_addr: '0x8c',
addr_mode: 'rel:0',
platform: 'native',
}),
expect.objectContaining({
filename: `${HOST}/${pagePath}`,
function: 'crash',
in_app: true,
}),
]),
);

expect(event.debug_meta).toMatchObject({
images: [
{
code_file: `${HOST}/simple.wasm`,
code_id: '0ba020cdd2444f7eafdd25999a8e9010',
debug_file: null,
debug_id: '0ba020cdd2444f7eafdd25999a8e90100',
type: 'wasm',
},
],
});
});
expect(event.debug_meta).toMatchObject({
images: [
{
code_file: `${HOST}/simple.wasm`,
code_id: '0ba020cdd2444f7eafdd25999a8e9010',
debug_file: null,
debug_id: '0ba020cdd2444f7eafdd25999a8e90100',
type: 'wasm',
},
],
});
}),
);
});
40 changes: 40 additions & 0 deletions packages/wasm/test/public/min-bundle.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!-- TODO: This is a quick and dirty way to test the minified browser bundle - an exact replica of `index.html` save the
browser bundle `src` value. In the long run, we should rig it so the bundle can be passed in. (Or, once the new bundling
process is nailed down, stop testing against the minified bundle, since that's not really what this test is for.)-->

<!DOCTYPE html>
<!-- Browser SDK Bundle -->
<script src="bundle.min.js"></script>
<!-- Wasm Integration Bundle -->
<script src="wasm.js"></script>
<script>
Sentry.init({
dsn: 'https://[email protected]/42',
integrations: [new Sentry.Integrations.Wasm()],
beforeSend: event => {
window.events.push(event);
return null;
},
});

window.events = [];

window.getEvent = async () => {
function crash() {
throw new Error('whoops');
}

const { instance } = await WebAssembly.instantiateStreaming(fetch('simple.wasm'), {
env: {
external_func: crash,
},
});

try {
instance.exports.internal_func();
} catch (err) {
Sentry.captureException(err);
return window.events.pop();
}
};
</script>