Skip to content

Commit e4005da

Browse files
committed
wip: test crappery
1 parent 37cdf64 commit e4005da

File tree

5 files changed

+693
-15
lines changed

5 files changed

+693
-15
lines changed

packages/wasm/package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@
1616
"access": "public"
1717
},
1818
"dependencies": {
19-
"@sentry/types": "5.27.6",
2019
"@sentry/browser": "5.27.6",
20+
"@sentry/types": "5.27.6",
2121
"tslib": "^1.9.3"
2222
},
2323
"devDependencies": {
2424
"@sentry-internal/eslint-config-sdk": "5.27.6",
25-
"chai": "^4.1.2",
25+
"@types/jest-environment-puppeteer": "^4.4.0",
26+
"@types/puppeteer": "^5.4.0",
2627
"eslint": "7.6.0",
2728
"jest": "^24.7.1",
29+
"jest-puppeteer": "^4.4.0",
2830
"npm-run-all": "^4.1.2",
2931
"prettier": "1.19.0",
32+
"puppeteer": "^5.5.0",
3033
"rimraf": "^2.6.3",
3134
"typescript": "3.7.5"
3235
},
@@ -53,6 +56,7 @@
5356
"extends": "../../package.json"
5457
},
5558
"jest": {
59+
"preset": "jest-puppeteer",
5660
"collectCoverage": true,
5761
"transform": {
5862
"^.+\\.ts$": "ts-jest"
@@ -61,7 +65,6 @@
6165
"js",
6266
"ts"
6367
],
64-
"testEnvironment": "node",
6568
"testMatch": [
6669
"**/*.test.ts"
6770
],
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { Event } from '@sentry/types';
3+
import { TestClient } from '../../core/test/mocks/client';
4+
5+
import { Wasm } from '../src';
6+
7+
import { readFile } from 'fs';
8+
import { Hub } from '@sentry/browser';
9+
10+
let exceptionEvent: Event;
11+
12+
function fakeFetch(file: string): Promise<Response> {
13+
return new Promise((resolve, reject) => {
14+
readFile(`${__dirname}/${file}`, (err, buf) => {
15+
if (err) {
16+
return reject(err);
17+
}
18+
let resp = new Response(buf);
19+
Object.defineProperty(resp, 'url', { value: `http://localhost:8002/${file}` });
20+
return resolve(resp);
21+
});
22+
});
23+
}
24+
25+
async function getInternalFunc(): Promise<WebAssembly.ExportValue> {
26+
const module = await WebAssembly.instantiateStreaming(fakeFetch('simple.wasm'), {
27+
env: {
28+
external_func: () => {
29+
throw Error('I failed');
30+
},
31+
},
32+
});
33+
return module.instance.exports.internal_func;
34+
}
35+
36+
describe('Wasm', () => {
37+
beforeEach(() => {
38+
exceptionEvent = {
39+
exception: {
40+
values: [
41+
{
42+
stacktrace: {
43+
frames: [
44+
{
45+
colno: 7,
46+
filename: 'http://localhost:8002/',
47+
function: 'async*',
48+
in_app: true,
49+
lineno: 41,
50+
},
51+
{
52+
colno: 9,
53+
filename: 'http://localhost:8002/',
54+
function: '?',
55+
in_app: true,
56+
lineno: 37,
57+
},
58+
{
59+
filename: 'http://localhost:8002/simple.wasm:wasm-function[1]:0x8c',
60+
function: 'internal_func',
61+
in_app: true,
62+
},
63+
{
64+
colno: 13,
65+
filename: 'http://localhost:8002/',
66+
function: 'crash',
67+
in_app: true,
68+
lineno: 23,
69+
},
70+
],
71+
},
72+
},
73+
],
74+
},
75+
};
76+
});
77+
78+
describe('captures wasm errors', () => {
79+
it('should be titled "Google"', async () => {
80+
await page.goto('file://' + __dirname + '/simple.html');
81+
await expect(page.title()).resolves.toMatch('Google');
82+
});
83+
/*
84+
const client = new TestClient({
85+
integrations: [new Wasm()],
86+
beforeSend: event => {
87+
console.log(event);
88+
return null;
89+
},
90+
});
91+
const hub = new Hub();
92+
hub.bindClient(client);
93+
hub.run(async () => {
94+
try {
95+
await getInternalFunc();
96+
} catch (err) {
97+
Sentry.captureException(err);
98+
}
99+
});
100+
*/
101+
});
102+
103+
/*
104+
describe('bails when unable to extract frames', () => {
105+
it('no exception values', () => {
106+
const brokenEvent = {
107+
exception: {
108+
values: undefined,
109+
},
110+
};
111+
// expect(wasm.process(brokenEvent)).toEqual(brokenEvent);
112+
});
113+
114+
it('no frames', () => {
115+
const brokenEvent = {
116+
exception: {
117+
values: [
118+
{
119+
stacktrace: {},
120+
},
121+
],
122+
},
123+
};
124+
// expect(wasm.process(brokenEvent)).toEqual(brokenEvent);
125+
});
126+
});
127+
*/
128+
});

packages/wasm/test/simple.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!doctype html>
2+
<title>Google</title>
3+
<script>
4+
console.log("aha!");
5+
</script>

packages/wasm/test/simple.wasm

4.07 KB
Binary file not shown.

0 commit comments

Comments
 (0)