From 687350af8ed5f21d2d92a92d8d3ee67de397ce65 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 8 Apr 2024 10:28:46 -0400 Subject: [PATCH] test: Port onerror tests to playwright --- .../suites/public-api/instrumentation/init.js | 2 +- .../onError/thrown-strings/subject.js | 5 +++++ .../onError/thrown-strings/test.ts | 17 +++++++++++++++++ .../browser/test/integration/suites/shell.js | 1 - 4 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/thrown-strings/subject.js create mode 100644 dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/thrown-strings/test.ts diff --git a/dev-packages/browser-integration-tests/suites/public-api/instrumentation/init.js b/dev-packages/browser-integration-tests/suites/public-api/instrumentation/init.js index d8c94f36fdd0..e76bf17b4af2 100644 --- a/dev-packages/browser-integration-tests/suites/public-api/instrumentation/init.js +++ b/dev-packages/browser-integration-tests/suites/public-api/instrumentation/init.js @@ -3,5 +3,5 @@ import * as Sentry from '@sentry/browser'; window.Sentry = Sentry; Sentry.init({ - dsn: 'https://public@dsn.ingest.sentry.io/1337', + dsn: 'https://public@dsn.ingest.sentry.io/1337' }); diff --git a/dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/thrown-strings/subject.js b/dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/thrown-strings/subject.js new file mode 100644 index 000000000000..7429303cab1a --- /dev/null +++ b/dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/thrown-strings/subject.js @@ -0,0 +1,5 @@ +function throwStringError() { + throw 'stringError'; +} + +throwStringError(); diff --git a/dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/thrown-strings/test.ts b/dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/thrown-strings/test.ts new file mode 100644 index 000000000000..64c868806fc4 --- /dev/null +++ b/dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/thrown-strings/test.ts @@ -0,0 +1,17 @@ +import { expect } from '@playwright/test'; +import type { Event } from '@sentry/types'; + +import { sentryTest } from '../../../../../utils/fixtures'; +import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers'; + +sentryTest('should catch thrown strings', async ({ getLocalTestPath, page }) => { + const url = await getLocalTestPath({ testDir: __dirname }); + + const eventData = await getFirstSentryEnvelopeRequest(page, url); + + expect(eventData.exception?.values).toHaveLength(1); + expect(eventData.exception?.values?.[0].type).toMatch(/SyntaxError/); + + // two frames - one from the eval and one from try catch + expect(eventData.exception?.values?.[0].stacktrace?.frames?.length).toBe(2); +}); diff --git a/packages/browser/test/integration/suites/shell.js b/packages/browser/test/integration/suites/shell.js index 7df81ae2b53e..bec3ab7a8768 100644 --- a/packages/browser/test/integration/suites/shell.js +++ b/packages/browser/test/integration/suites/shell.js @@ -22,7 +22,6 @@ function runVariant(variant) { /** * The test runner will replace each of these placeholders with the contents of the corresponding file. */ - {{ suites/onerror.js }} // biome-ignore format: No trailing commas {{ suites/onunhandledrejection.js }} // biome-ignore format: No trailing commas {{ suites/builtins.js }} // biome-ignore format: No trailing commas {{ suites/loader.js }} // biome-ignore format: No trailing commas