forked from getsentry/sentry-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Port captureException and captureMessage tests from karma runner (
getsentry#11412) I want to remove the karma/mocha based tests in the browser package. To accomplish this, I'll be porting 1 test suite a day from the old integration tests to playwright. Today is Day 1: `packages/browser/test/integration/suites/api.js` We have decent coverage around singular calls to these methods, so I just added the tests that validate calling `captureException` and `captureMessage` multiple times. I also fixed a spelling mistake with `dev-packages/browser-integration-tests/suites/public-api/captureException/linkedErrors/subject.js`, `linkedErrrors` -> `linkedErrors` ref getsentry#11084
- Loading branch information
1 parent
de4d8c5
commit 1f40194
Showing
11 changed files
with
191 additions
and
163 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
41 changes: 41 additions & 0 deletions
41
...ion-tests/suites/public-api/captureException/multipleErrorsDifferentStacktrace/subject.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
function bar() { | ||
baz(); | ||
} | ||
|
||
function foo() { | ||
bar(); | ||
} | ||
|
||
function foo2() { | ||
// identical to foo, but meant for testing | ||
// different stack frame fns w/ same stack length | ||
bar(); | ||
} | ||
// same error message, but different stacks means that these are considered | ||
// different errors | ||
|
||
// stack: | ||
// bar | ||
try { | ||
bar(); | ||
} catch (e) { | ||
Sentry.captureException(e); | ||
} | ||
|
||
// stack (different # frames): | ||
// bar | ||
// foo | ||
try { | ||
foo(); | ||
} catch (e) { | ||
Sentry.captureException(e); | ||
} | ||
|
||
// stack (same # frames, different frames): | ||
// bar | ||
// foo2 | ||
try { | ||
foo2(); | ||
} catch (e) { | ||
Sentry.captureException(e); | ||
} |
19 changes: 19 additions & 0 deletions
19
...ration-tests/suites/public-api/captureException/multipleErrorsDifferentStacktrace/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getMultipleSentryEnvelopeRequests } from '../../../../utils/helpers'; | ||
|
||
sentryTest('should not reject back-to-back errors with different stack traces', async ({ getLocalTestPath, page }) => { | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
const eventData = await getMultipleSentryEnvelopeRequests<Event>(page, 3, { url }); | ||
|
||
// NOTE: regex because exact error message differs per-browser | ||
expect(eventData[0].exception?.values?.[0].value).toMatch(/baz/); | ||
expect(eventData[0].exception?.values?.[0].type).toMatch('ReferenceError'); | ||
expect(eventData[1].exception?.values?.[0].value).toMatch(/baz/); | ||
expect(eventData[1].exception?.values?.[0].type).toMatch('ReferenceError'); | ||
expect(eventData[2].exception?.values?.[0].value).toMatch(/baz/); | ||
expect(eventData[2].exception?.values?.[0].type).toMatch('ReferenceError'); | ||
}); |
55 changes: 55 additions & 0 deletions
55
...egration-tests/suites/public-api/captureException/multipleErrorsSameStacktrace/subject.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
function throwError(message) { | ||
// eslint-disable-next-line no-param-reassign | ||
message = message || 'foo'; | ||
try { | ||
throw new Error(message); | ||
} catch (o_O) { | ||
Sentry.captureException(o_O); | ||
} | ||
} | ||
|
||
function throwRandomError() { | ||
try { | ||
throw new Error('Exception no ' + (Date.now() + Math.random())); | ||
} catch (o_O) { | ||
Sentry.captureException(o_O); | ||
} | ||
} | ||
|
||
function createError() { | ||
function nestedFunction() { | ||
return new Error('created'); | ||
} | ||
|
||
return nestedFunction(); | ||
} | ||
|
||
function throwSameConsecutiveErrors(message) { | ||
throwError(message); | ||
throwError(message); | ||
} | ||
|
||
// Different exceptions, don't dedupe | ||
for (var i = 0; i < 2; i++) { | ||
throwRandomError(); | ||
} | ||
|
||
// Same exceptions and same stacktrace, dedupe | ||
for (var j = 0; j < 2; j++) { | ||
throwError(); | ||
} | ||
|
||
const syntheticError = createError(); | ||
|
||
// Same exception, with transaction in between, dedupe | ||
Sentry.captureException(syntheticError); | ||
Sentry.captureEvent({ | ||
event_id: 'aa3ff046696b4bc6b609ce6d28fde9e2', | ||
message: 'someMessage', | ||
transaction: 'wat', | ||
type: 'transaction', | ||
}); | ||
Sentry.captureException(syntheticError); | ||
|
||
// Same exceptions, different stacktrace (different line number), don't dedupe | ||
throwSameConsecutiveErrors('bar'); |
21 changes: 21 additions & 0 deletions
21
...integration-tests/suites/public-api/captureException/multipleErrorsSameStacktrace/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getMultipleSentryEnvelopeRequests } from '../../../../utils/helpers'; | ||
|
||
sentryTest('should reject duplicate, back-to-back errors from captureException', async ({ getLocalTestPath, page }) => { | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
const eventData = await getMultipleSentryEnvelopeRequests<Event>(page, 7, { url }); | ||
|
||
// NOTE: regex because exact error message differs per-browser | ||
expect(eventData[0].exception?.values?.[0].value).toMatch(/Exception no \d+/); | ||
expect(eventData[1].exception?.values?.[0].value).toMatch(/Exception no \d+/); | ||
expect(eventData[2].exception?.values?.[0].value).toEqual('foo'); | ||
// transaction so undefined | ||
expect(eventData[3].exception?.values?.[0].value).toEqual('created'); | ||
expect(eventData[4].exception?.values?.[0].value).toEqual(undefined); | ||
expect(eventData[5].exception?.values?.[0].value).toEqual('bar'); | ||
expect(eventData[6].exception?.values?.[0].value).toEqual('bar'); | ||
}); |
8 changes: 8 additions & 0 deletions
8
...ntegration-tests/suites/public-api/captureMessage/multipleMessageAttachStacktrace/init.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
attachStacktrace: true, | ||
}); |
27 changes: 27 additions & 0 deletions
27
...gration-tests/suites/public-api/captureMessage/multipleMessageAttachStacktrace/subject.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
function captureMessage(message) { | ||
// eslint-disable-next-line no-param-reassign | ||
message = message || 'message'; | ||
Sentry.captureMessage(message); | ||
} | ||
|
||
function captureRandomMessage() { | ||
Sentry.captureMessage('Message no ' + (Date.now() + Math.random())); | ||
} | ||
|
||
function captureSameConsecutiveMessages(message) { | ||
captureMessage(message); | ||
captureMessage(message); | ||
} | ||
|
||
// Different messages, don't dedupe | ||
for (var i = 0; i < 2; i++) { | ||
captureRandomMessage(); | ||
} | ||
|
||
// Same messages and same stacktrace, dedupe | ||
for (var j = 0; j < 3; j++) { | ||
captureMessage('same message, same stacktrace'); | ||
} | ||
|
||
// Same messages, different stacktrace (different line number), don't dedupe | ||
captureSameConsecutiveMessages('same message, different stacktrace'); |
20 changes: 20 additions & 0 deletions
20
...ntegration-tests/suites/public-api/captureMessage/multipleMessageAttachStacktrace/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getMultipleSentryEnvelopeRequests } from '../../../../utils/helpers'; | ||
|
||
sentryTest( | ||
'should reject duplicate, back-to-back messages from captureMessage when it has stacktrace', | ||
async ({ getLocalTestPath, page }) => { | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
const eventData = await getMultipleSentryEnvelopeRequests<Event>(page, 5, { url }); | ||
|
||
expect(eventData[0].message).toMatch(/Message no \d+/); | ||
expect(eventData[1].message).toMatch(/Message no \d+/); | ||
expect(eventData[2].message).toMatch('same message, same stacktrace'); | ||
expect(eventData[3].message).toMatch('same message, different stacktrace'); | ||
expect(eventData[4].message).toMatch('same message, different stacktrace'); | ||
}, | ||
); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters