|
| 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 | +}); |
0 commit comments