-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test: Port onerror tests to playwright #11666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
35e5ddd
test: Port onerror tests to playwright
AbhiPrasad 75af29b
fix lint
AbhiPrasad a308b19
fix test
AbhiPrasad bfb5209
cross webkit error
AbhiPrasad 1957483
Update dev-packages/browser-integration-tests/suites/public-api/instr…
AbhiPrasad 9af707e
Merge branch 'develop' into abhi-karma-test-port
AbhiPrasad 04b7377
yarn fix
AbhiPrasad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
dev-packages/browser-integration-tests/suites/public-api/instrumentation/onError/init.js
This file contains hidden or 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,7 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
}); |
8 changes: 8 additions & 0 deletions
8
...ser-integration-tests/suites/public-api/instrumentation/onError/non-string-arg/subject.js
This file contains hidden or 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 @@ | ||
function run() { | ||
window.onerror({ | ||
type: 'error', | ||
otherKey: 'hi', | ||
}); | ||
} | ||
|
||
run(); |
24 changes: 24 additions & 0 deletions
24
...rowser-integration-tests/suites/public-api/instrumentation/onError/non-string-arg/test.ts
This file contains hidden or 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,24 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../../utils/fixtures'; | ||
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers'; | ||
|
||
sentryTest('should onerror calls with non-string first argument gracefully', async ({ getLocalTestPath, page }) => { | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
|
||
expect(eventData.exception?.values).toHaveLength(1); | ||
expect(eventData.exception?.values?.[0]).toMatchObject({ | ||
type: 'Error', | ||
value: 'Object captured as exception with keys: otherKey, type', | ||
mechanism: { | ||
type: 'onerror', | ||
handled: false, | ||
}, | ||
stacktrace: { | ||
frames: expect.any(Array), | ||
}, | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
...s/browser-integration-tests/suites/public-api/instrumentation/onError/rethrown/subject.js
This file contains hidden or 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,17 @@ | ||
function run() { | ||
try { | ||
try { | ||
foo(); | ||
} catch (e) { | ||
Sentry.captureException(e); | ||
throw e; // intentionally re-throw | ||
} | ||
} catch (e) { | ||
// simulate window.onerror without generating a Script error | ||
window.onerror('error', 'file.js', 1, 1, e); | ||
} | ||
} | ||
|
||
run(); | ||
|
||
Sentry.captureException(new Error('error 2')); |
42 changes: 42 additions & 0 deletions
42
...ages/browser-integration-tests/suites/public-api/instrumentation/onError/rethrown/test.ts
This file contains hidden or 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,42 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../../utils/fixtures'; | ||
import { getMultipleSentryEnvelopeRequests } from '../../../../../utils/helpers'; | ||
|
||
sentryTest( | ||
'should NOT catch an exception already caught [but rethrown] via Sentry.captureException', | ||
async ({ getLocalTestPath, page }) => { | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
const events = await getMultipleSentryEnvelopeRequests<Event>(page, 2, { url }); | ||
|
||
expect(events[0].exception?.values).toHaveLength(1); | ||
expect(events[0].exception?.values?.[0]).toMatchObject({ | ||
type: 'ReferenceError', | ||
// this exact error message varies between browsers, but they should all reference 'foo' | ||
value: expect.stringContaining('foo'), | ||
mechanism: { | ||
type: 'generic', | ||
handled: true, | ||
}, | ||
stacktrace: { | ||
frames: expect.any(Array), | ||
}, | ||
}); | ||
|
||
// This is not a refernece error, but another generic error | ||
expect(events[1].exception?.values).toHaveLength(1); | ||
expect(events[1].exception?.values?.[0]).toMatchObject({ | ||
type: 'Error', | ||
value: 'error 2', | ||
mechanism: { | ||
type: 'generic', | ||
handled: true, | ||
}, | ||
stacktrace: { | ||
frames: expect.any(Array), | ||
}, | ||
}); | ||
}, | ||
); |
10 changes: 10 additions & 0 deletions
10
...wser-integration-tests/suites/public-api/instrumentation/onError/syntax-errors/subject.js
This file contains hidden or 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,10 @@ | ||
function run() { | ||
try { | ||
eval('foo{};'); | ||
} catch (e) { | ||
// simulate window.onerror without generating a Script error | ||
window.onerror('error', 'file.js', 1, 1, e); | ||
} | ||
} | ||
|
||
run(); |
24 changes: 24 additions & 0 deletions
24
...browser-integration-tests/suites/public-api/instrumentation/onError/syntax-errors/test.ts
This file contains hidden or 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,24 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../../utils/fixtures'; | ||
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers'; | ||
|
||
sentryTest('should catch syntax errors', async ({ getLocalTestPath, page }) => { | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
|
||
expect(eventData.exception?.values).toHaveLength(1); | ||
expect(eventData.exception?.values?.[0]).toMatchObject({ | ||
type: 'SyntaxError', | ||
value: "Unexpected token '{'", | ||
mechanism: { | ||
type: 'onerror', | ||
handled: false, | ||
}, | ||
stacktrace: { | ||
frames: expect.any(Array), | ||
}, | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
...wser-integration-tests/suites/public-api/instrumentation/onError/thrown-errors/subject.js
This file contains hidden or 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,10 @@ | ||
function run() { | ||
try { | ||
throw new Error('realError'); | ||
} catch (e) { | ||
// simulate window.onerror without generating a Script error | ||
window.onerror('error', 'file.js', 1, 1, e); | ||
} | ||
} | ||
|
||
run(); |
24 changes: 24 additions & 0 deletions
24
...browser-integration-tests/suites/public-api/instrumentation/onError/thrown-errors/test.ts
This file contains hidden or 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,24 @@ | ||
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 errors', async ({ getLocalTestPath, page }) => { | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
|
||
expect(eventData.exception?.values).toHaveLength(1); | ||
expect(eventData.exception?.values?.[0]).toMatchObject({ | ||
type: 'Error', | ||
value: 'realError', | ||
mechanism: { | ||
type: 'onerror', | ||
handled: false, | ||
}, | ||
stacktrace: { | ||
frames: expect.any(Array), | ||
}, | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
...ser-integration-tests/suites/public-api/instrumentation/onError/thrown-objects/subject.js
This file contains hidden or 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,10 @@ | ||
function run() { | ||
try { | ||
throw { error: 'stuff is broken', somekey: 'ok' }; | ||
} catch (e) { | ||
// simulate window.onerror without generating a Script error | ||
window.onerror('error', 'file.js', 1, 1, e); | ||
} | ||
} | ||
|
||
run(); |
24 changes: 24 additions & 0 deletions
24
...rowser-integration-tests/suites/public-api/instrumentation/onError/thrown-objects/test.ts
This file contains hidden or 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,24 @@ | ||
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 objects', async ({ getLocalTestPath, page }) => { | ||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
|
||
expect(eventData.exception?.values).toHaveLength(1); | ||
expect(eventData.exception?.values?.[0]).toMatchObject({ | ||
type: 'Error', | ||
value: 'Object captured as exception with keys: error, somekey', | ||
mechanism: { | ||
type: 'onerror', | ||
handled: false, | ||
}, | ||
stacktrace: { | ||
frames: expect.any(Array), | ||
}, | ||
}); | ||
}); |
10 changes: 10 additions & 0 deletions
10
...ser-integration-tests/suites/public-api/instrumentation/onError/thrown-strings/subject.js
This file contains hidden or 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,10 @@ | ||
function run() { | ||
try { | ||
throw 'stringError'; | ||
} catch (e) { | ||
// simulate window.onerror without generating a Script error | ||
window.onerror('error', 'file.js', 1, 1, e); | ||
} | ||
} | ||
|
||
run(); |
26 changes: 26 additions & 0 deletions
26
...rowser-integration-tests/suites/public-api/instrumentation/onError/thrown-strings/test.ts
This file contains hidden or 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,26 @@ | ||
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<Event>(page, url); | ||
|
||
expect(eventData.exception?.values).toHaveLength(1); | ||
expect(eventData.exception?.values?.[0]).toMatchObject({ | ||
type: 'Error', | ||
value: 'stringError', | ||
mechanism: { | ||
type: 'onerror', | ||
handled: false, | ||
}, | ||
stacktrace: { | ||
frames: expect.any(Array), | ||
}, | ||
}); | ||
|
||
expect(eventData.exception?.values?.[0].stacktrace?.frames).toHaveLength(1); | ||
}); |
13 changes: 0 additions & 13 deletions
13
packages/browser/test/integration/subjects/console-logs.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.