Skip to content

Commit 156a289

Browse files
authored
feat(wasm): Add test against minified browser bundle (#4526)
The current wasm integration test uses the browser bundle, and is therefore a quick smoke test of whether the bundle is legit. At least temporarily, this makes it test against the minified bundle, too, so it can act as a similar smoke test there. This is helpful as we're changing the bundling process, as it's an extra check to make sure we haven't broken the world. Because this is a likely-temporary (ab)use of this integration test, it's done in the quickest and dirtiest way possible: the page which gets loaded is replicated, with the SDK bundle pointing to the minified version rather than the regular version. If we decide to keep testing against both bundles, we should do it in a more elegant way.
1 parent c8b3691 commit 156a289

File tree

2 files changed

+80
-34
lines changed

2 files changed

+80
-34
lines changed

packages/wasm/test/integration.test.js

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,46 @@
33
const HOST = `http://localhost:${process.env.PORT}`;
44

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

12-
expect(event.exception.values[0].stacktrace.frames).toEqual(
13-
expect.arrayContaining([
14-
expect.objectContaining({
15-
filename: `${HOST}/simple.wasm`,
16-
function: 'internal_func',
17-
in_app: true,
18-
instruction_addr: '0x8c',
19-
addr_mode: 'rel:0',
20-
platform: 'native',
21-
}),
22-
expect.objectContaining({
23-
filename: `${HOST}/`,
24-
function: 'crash',
25-
in_app: true,
26-
}),
27-
]),
28-
);
17+
expect(event.exception.values[0].stacktrace.frames).toEqual(
18+
expect.arrayContaining([
19+
expect.objectContaining({
20+
filename: `${HOST}/simple.wasm`,
21+
function: 'internal_func',
22+
in_app: true,
23+
instruction_addr: '0x8c',
24+
addr_mode: 'rel:0',
25+
platform: 'native',
26+
}),
27+
expect.objectContaining({
28+
filename: `${HOST}/${pagePath}`,
29+
function: 'crash',
30+
in_app: true,
31+
}),
32+
]),
33+
);
2934

30-
expect(event.debug_meta).toMatchObject({
31-
images: [
32-
{
33-
code_file: `${HOST}/simple.wasm`,
34-
code_id: '0ba020cdd2444f7eafdd25999a8e9010',
35-
debug_file: null,
36-
debug_id: '0ba020cdd2444f7eafdd25999a8e90100',
37-
type: 'wasm',
38-
},
39-
],
40-
});
41-
});
35+
expect(event.debug_meta).toMatchObject({
36+
images: [
37+
{
38+
code_file: `${HOST}/simple.wasm`,
39+
code_id: '0ba020cdd2444f7eafdd25999a8e9010',
40+
debug_file: null,
41+
debug_id: '0ba020cdd2444f7eafdd25999a8e90100',
42+
type: 'wasm',
43+
},
44+
],
45+
});
46+
}),
47+
);
4248
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!-- TODO: This is a quick and dirty way to test the minified browser bundle - an exact replica of `index.html` save the
2+
browser bundle `src` value. In the long run, we should rig it so the bundle can be passed in. (Or, once the new bundling
3+
process is nailed down, stop testing against the minified bundle, since that's not really what this test is for.)-->
4+
5+
<!DOCTYPE html>
6+
<!-- Browser SDK Bundle -->
7+
<script src="bundle.min.js"></script>
8+
<!-- Wasm Integration Bundle -->
9+
<script src="wasm.js"></script>
10+
<script>
11+
Sentry.init({
12+
dsn: 'https://[email protected]/42',
13+
integrations: [new Sentry.Integrations.Wasm()],
14+
beforeSend: event => {
15+
window.events.push(event);
16+
return null;
17+
},
18+
});
19+
20+
window.events = [];
21+
22+
window.getEvent = async () => {
23+
function crash() {
24+
throw new Error('whoops');
25+
}
26+
27+
const { instance } = await WebAssembly.instantiateStreaming(fetch('simple.wasm'), {
28+
env: {
29+
external_func: crash,
30+
},
31+
});
32+
33+
try {
34+
instance.exports.internal_func();
35+
} catch (err) {
36+
Sentry.captureException(err);
37+
return window.events.pop();
38+
}
39+
};
40+
</script>

0 commit comments

Comments
 (0)