(hooks: NestedHooks)
| 10 | }; |
| 11 | |
| 12 | export function setupSentryTest(hooks: NestedHooks): void { |
| 13 | hooks.beforeEach(function (this: SentryTestContext) { |
| 14 | window._sentryTestEvents = []; |
| 15 | const errorMessages: string[] = []; |
| 16 | this.errorMessages = errorMessages; |
| 17 | |
| 18 | /** |
| 19 | * Stub out fetch function to assert on Sentry calls. |
| 20 | */ |
| 21 | this.fetchStub = sinon.stub(window, 'fetch'); |
| 22 | |
| 23 | /** |
| 24 | * Stops global test suite failures from unhandled rejections and allows assertion on them. |
| 25 | * onUncaughtException is used in QUnit 2.17 onwards. |
| 26 | */ |
| 27 | this.qunitOnUnhandledRejection = sinon.stub( |
| 28 | QUnit, |
| 29 | // @ts-expect-error this is OK |
| 30 | QUnit.onUncaughtException ? 'onUncaughtException' : 'onUnhandledRejection', |
| 31 | ); |
| 32 | |
| 33 | // @ts-expect-error this is fine |
| 34 | QUnit.onError = function ({ message }: { message: string }) { |
| 35 | errorMessages.push(message.split('Error: ')[1]!); |
| 36 | return true; |
| 37 | }; |
| 38 | |
| 39 | setupOnerror(function (error: Error) { |
| 40 | errorMessages.push(error.message); |
| 41 | throw error; |
| 42 | }); |
| 43 | |
| 44 | this._windowOnError = window.onerror; |
| 45 | |
| 46 | /** |
| 47 | * Will collect errors when run via testem in cli |
| 48 | */ |
| 49 | window.onerror = error => { |
| 50 | errorMessages.push(error.toString().split('Error: ')[1]!); |
| 51 | }; |
| 52 | }); |
| 53 | |
| 54 | hooks.afterEach(function (this: SentryTestContext) { |
| 55 | this.fetchStub.restore(); |
| 56 | this.qunitOnUnhandledRejection.restore(); |
| 57 | window.onerror = this._windowOnError; |
| 58 | resetOnerror(); |
| 59 | }); |
| 60 | } |
no test coverage detected