-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
test: Port breadcrumb tests from karma runner #11436
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
10 changes: 10 additions & 0 deletions
10
...ages/browser-integration-tests/suites/integrations/Breadcrumbs/console/capture/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,10 @@ | ||
console.log('One'); | ||
console.warn('Two', { a: 1 }); | ||
console.error('Error 2', { b: { c: [] } }); | ||
|
||
// Passed assertions _should not_ be captured | ||
console.assert(1 + 1 === 2, 'math works'); | ||
// Failed assertions _should_ be captured | ||
console.assert(1 + 1 === 3, 'math broke'); | ||
|
||
Sentry.captureException('test exception'); |
45 changes: 45 additions & 0 deletions
45
...ackages/browser-integration-tests/suites/integrations/Breadcrumbs/console/capture/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,45 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/browser'; | ||
|
||
import { sentryTest } from '../../../../../utils/fixtures'; | ||
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers'; | ||
|
||
sentryTest('should capture console breadcrumbs', async ({ getLocalTestUrl, page }) => { | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
|
||
expect(eventData.breadcrumbs).toEqual([ | ||
{ | ||
category: 'console', | ||
data: { arguments: ['One'], logger: 'console' }, | ||
level: 'log', | ||
message: 'One', | ||
timestamp: expect.any(Number), | ||
}, | ||
{ | ||
category: 'console', | ||
data: { arguments: ['Two', { a: 1 }], logger: 'console' }, | ||
level: 'warning', | ||
message: 'Two [object Object]', | ||
timestamp: expect.any(Number), | ||
}, | ||
{ | ||
category: 'console', | ||
data: { arguments: ['Error 2', { b: '[Object]' }], logger: 'console' }, | ||
level: 'error', | ||
message: 'Error 2 [object Object]', | ||
timestamp: expect.any(Number), | ||
}, | ||
{ | ||
category: 'console', | ||
data: { | ||
arguments: ['math broke'], | ||
logger: 'console', | ||
}, | ||
level: 'log', | ||
message: 'Assertion failed: math broke', | ||
timestamp: expect.any(Number), | ||
}, | ||
]); | ||
}); |
10 changes: 10 additions & 0 deletions
10
dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/console/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,10 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
defaultIntegrations: false, | ||
integrations: [Sentry.breadcrumbsIntegration()], | ||
sampleRate: 1, | ||
}); |
7 changes: 7 additions & 0 deletions
7
...s/browser-integration-tests/suites/integrations/Breadcrumbs/dom/clickWithError/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,7 @@ | ||
const click = new MouseEvent('click'); | ||
function kaboom() { | ||
throw new Error('lol'); | ||
} | ||
Object.defineProperty(click, 'target', { get: kaboom }); | ||
const input = document.getElementById('input1'); | ||
input.dispatchEvent(click); |
10 changes: 10 additions & 0 deletions
10
...rowser-integration-tests/suites/integrations/Breadcrumbs/dom/clickWithError/template.html
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,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title></title> | ||
</head> | ||
<body> | ||
<input id="input1" type="text" /> | ||
</body> | ||
</html> |
32 changes: 32 additions & 0 deletions
32
...ages/browser-integration-tests/suites/integrations/Breadcrumbs/dom/clickWithError/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,32 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/browser'; | ||
|
||
import { sentryTest } from '../../../../../utils/fixtures'; | ||
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers'; | ||
|
||
// see: https://github.com/getsentry/sentry-javascript/issues/768 | ||
sentryTest( | ||
'should record breadcrumb if accessing the target property of an event throws an exception', | ||
async ({ getLocalTestUrl, page }) => { | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
|
||
const promise = getFirstSentryEnvelopeRequest<Event>(page); | ||
|
||
await page.locator('#input1').pressSequentially('test', { delay: 1 }); | ||
|
||
await page.evaluate('Sentry.captureException("test exception")'); | ||
|
||
const eventData = await promise; | ||
|
||
expect(eventData.breadcrumbs).toHaveLength(1); | ||
expect(eventData.breadcrumbs).toEqual([ | ||
{ | ||
category: 'ui.input', | ||
message: 'body > input#input1[type="text"]', | ||
timestamp: expect.any(Number), | ||
}, | ||
]); | ||
}, | ||
); |
9 changes: 9 additions & 0 deletions
9
...ages/browser-integration-tests/suites/integrations/Breadcrumbs/dom/customEvent/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,9 @@ | ||
const input = document.getElementsByTagName('input')[0]; | ||
input.addEventListener('build', function (evt) { | ||
evt.stopPropagation(); | ||
}); | ||
|
||
const customEvent = new CustomEvent('build', { detail: 1 }); | ||
input.dispatchEvent(customEvent); | ||
|
||
Sentry.captureException('test exception'); |
12 changes: 12 additions & 0 deletions
12
...s/browser-integration-tests/suites/integrations/Breadcrumbs/dom/customEvent/template.html
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,12 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title></title> | ||
</head> | ||
<body> | ||
<input id="input1" type="text" /> | ||
<input id="input2" type="text" /> | ||
<input id="annotated-input" data-sentry-component="AnnotatedInput" type="text" /> | ||
</body> | ||
</html> |
19 changes: 19 additions & 0 deletions
19
...ackages/browser-integration-tests/suites/integrations/Breadcrumbs/dom/customEvent/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 { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers'; | ||
|
||
sentryTest('breadcrumbs listener should not fail with custom event', async ({ getLocalTestUrl, page }) => { | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
let error = undefined; | ||
page.on('pageerror', err => { | ||
error = err; | ||
}); | ||
|
||
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
expect(eventData.exception?.values).toHaveLength(1); | ||
expect(eventData.breadcrumbs).toBeUndefined(); | ||
expect(error).toBeUndefined(); | ||
}); |
10 changes: 10 additions & 0 deletions
10
...browser-integration-tests/suites/integrations/Breadcrumbs/dom/multipleTypes/template.html
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,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title></title> | ||
</head> | ||
<body> | ||
<input id="input1" type="text" /> | ||
</body> | ||
</html> |
50 changes: 50 additions & 0 deletions
50
...kages/browser-integration-tests/suites/integrations/Breadcrumbs/dom/multipleTypes/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,50 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/browser'; | ||
|
||
import { sentryTest } from '../../../../../utils/fixtures'; | ||
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers'; | ||
|
||
sentryTest( | ||
'should correctly capture multiple consecutive breadcrumbs if they are of different type', | ||
async ({ getLocalTestUrl, page }) => { | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
|
||
const promise = getFirstSentryEnvelopeRequest<Event>(page); | ||
|
||
// These inputs will be debounced | ||
await page.locator('#input1').pressSequentially('abc', { delay: 1 }); | ||
await page.locator('#input1').pressSequentially('def', { delay: 1 }); | ||
await page.locator('#input1').pressSequentially('ghi', { delay: 1 }); | ||
|
||
await page.locator('#input1').click(); | ||
await page.locator('#input1').click(); | ||
await page.locator('#input1').click(); | ||
|
||
// This input should not be debounced | ||
await page.locator('#input1').pressSequentially('jkl', { delay: 1 }); | ||
|
||
await page.evaluate('Sentry.captureException("test exception")'); | ||
|
||
const eventData = await promise; | ||
|
||
expect(eventData.breadcrumbs).toEqual([ | ||
{ | ||
category: 'ui.input', | ||
message: 'body > input#input1[type="text"]', | ||
timestamp: expect.any(Number), | ||
}, | ||
{ | ||
category: 'ui.click', | ||
message: 'body > input#input1[type="text"]', | ||
timestamp: expect.any(Number), | ||
}, | ||
{ | ||
category: 'ui.input', | ||
message: 'body > input#input1[type="text"]', | ||
timestamp: expect.any(Number), | ||
}, | ||
]); | ||
}, | ||
); |
2 changes: 0 additions & 2 deletions
2
dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/fetch/get/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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
const xhr = new XMLHttpRequest(); | ||
|
||
fetch('http://localhost:7654/foo').then(() => { | ||
Sentry.captureException('test error'); | ||
}); |
3 changes: 3 additions & 0 deletions
3
...wser-integration-tests/suites/integrations/Breadcrumbs/fetch/getWithRequestObj/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,3 @@ | ||
fetch(new Request('http://localhost:7654/foo')).then(() => { | ||
Sentry.captureException('test error'); | ||
}); |
37 changes: 37 additions & 0 deletions
37
...browser-integration-tests/suites/integrations/Breadcrumbs/fetch/getWithRequestObj/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,37 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/types'; | ||
|
||
import { sentryTest } from '../../../../../utils/fixtures'; | ||
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers'; | ||
|
||
sentryTest('captures Breadcrumb for basic GET request that uses request object', async ({ getLocalTestUrl, page }) => { | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
await page.route('**/foo', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
body: JSON.stringify({ | ||
userNames: ['John', 'Jane'], | ||
}), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}); | ||
|
||
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
|
||
expect(eventData.exception?.values).toHaveLength(1); | ||
|
||
expect(eventData?.breadcrumbs?.length).toBe(1); | ||
expect(eventData!.breadcrumbs![0]).toEqual({ | ||
timestamp: expect.any(Number), | ||
category: 'fetch', | ||
type: 'http', | ||
data: { | ||
method: 'GET', | ||
status_code: 200, | ||
url: 'http://localhost:7654/foo', | ||
}, | ||
}); | ||
}); |
2 changes: 0 additions & 2 deletions
2
dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/fetch/post/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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
const xhr = new XMLHttpRequest(); | ||
|
||
fetch('http://localhost:7654/foo', { | ||
method: 'POST', | ||
body: '{"my":"body"}', | ||
|
10 changes: 10 additions & 0 deletions
10
dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/history/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,10 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
defaultIntegrations: false, | ||
integrations: [Sentry.breadcrumbsIntegration()], | ||
sampleRate: 1, | ||
}); |
7 changes: 7 additions & 0 deletions
7
...s/browser-integration-tests/suites/integrations/Breadcrumbs/history/navigation/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,7 @@ | ||
history.pushState({}, '', '/foo'); | ||
history.pushState({}, '', '/bar?a=1#fragment'); | ||
history.pushState({}, '', {}); | ||
history.pushState({}, '', null); | ||
history.replaceState({}, '', '/bar?a=1#fragment'); | ||
|
||
Sentry.captureException('test exception'); |
46 changes: 46 additions & 0 deletions
46
...ages/browser-integration-tests/suites/integrations/Breadcrumbs/history/navigation/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,46 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/browser'; | ||
|
||
import { sentryTest } from '../../../../../utils/fixtures'; | ||
import { getFirstSentryEnvelopeRequest } from '../../../../../utils/helpers'; | ||
|
||
sentryTest('should record history changes as navigation breadcrumbs', async ({ getLocalTestUrl, page }) => { | ||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url); | ||
|
||
expect(eventData.breadcrumbs).toEqual([ | ||
{ | ||
category: 'navigation', | ||
data: { | ||
from: '/index.html', | ||
to: '/foo', | ||
}, | ||
timestamp: expect.any(Number), | ||
}, | ||
{ | ||
category: 'navigation', | ||
data: { | ||
from: '/foo', | ||
to: '/bar?a=1#fragment', | ||
}, | ||
timestamp: expect.any(Number), | ||
}, | ||
{ | ||
category: 'navigation', | ||
data: { | ||
from: '/bar?a=1#fragment', | ||
to: '[object Object]', | ||
}, | ||
timestamp: expect.any(Number), | ||
}, | ||
{ | ||
category: 'navigation', | ||
data: { | ||
from: '[object Object]', | ||
to: '/bar?a=1#fragment', | ||
}, | ||
timestamp: expect.any(Number), | ||
}, | ||
]); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: Can we check for the breadcrumb content?