-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
205 additions
and
6 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
packages/browser-integration-tests/suites/replay/slowClick/error/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,18 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
window.Replay = new Sentry.Replay({ | ||
flushMinDelay: 200, | ||
flushMaxDelay: 200, | ||
minReplayDuration: 0, | ||
slowClickTimeout: 3500, | ||
}); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
sampleRate: 1, | ||
replaysSessionSampleRate: 0.0, | ||
replaysOnErrorSampleRate: 1.0, | ||
|
||
integrations: [window.Replay], | ||
}); |
22 changes: 22 additions & 0 deletions
22
packages/browser-integration-tests/suites/replay/slowClick/error/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,22 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<button id="buttonError">Trigger error</button> | ||
<button id="buttonErrorMutation">Trigger error</button> | ||
|
||
<script> | ||
document.getElementById('buttonError').addEventListener('click', () => { | ||
throw new Error('test error happened'); | ||
}); | ||
|
||
document.getElementById('buttonErrorMutation').addEventListener('click', () => { | ||
document.getElementById('buttonErrorMutation').innerText = 'Test error happened!'; | ||
|
||
throw new Error('test error happened'); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
140 changes: 140 additions & 0 deletions
140
packages/browser-integration-tests/suites/replay/slowClick/error/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,140 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { | ||
getCustomRecordingEvents, | ||
getReplayEventFromRequest, | ||
shouldSkipReplayTest, | ||
waitForReplayRequest, | ||
} from '../../../../utils/replayHelpers'; | ||
|
||
sentryTest('slow click that triggers error is captured', async ({ getLocalTestUrl, page }) => { | ||
if (shouldSkipReplayTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
|
||
const [req0] = await Promise.all([ | ||
waitForReplayRequest(page, (_event, res) => { | ||
const { breadcrumbs } = getCustomRecordingEvents(res); | ||
|
||
return breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.slowClickDetected'); | ||
}), | ||
page.click('#buttonError'), | ||
]); | ||
|
||
const { breadcrumbs } = getCustomRecordingEvents(req0); | ||
|
||
const slowClickBreadcrumbs = breadcrumbs.filter(breadcrumb => breadcrumb.category === 'ui.slowClickDetected'); | ||
|
||
expect(slowClickBreadcrumbs).toEqual([ | ||
{ | ||
category: 'ui.slowClickDetected', | ||
type: 'default', | ||
data: { | ||
endReason: 'timeout', | ||
clickCount: 1, | ||
node: { | ||
attributes: { | ||
id: 'buttonError', | ||
}, | ||
id: expect.any(Number), | ||
tagName: 'button', | ||
textContent: '******* *****', | ||
}, | ||
nodeId: expect.any(Number), | ||
timeAfterClickMs: 3500, | ||
url: 'http://sentry-test.io/index.html', | ||
}, | ||
message: 'body > button#buttonError', | ||
timestamp: expect.any(Number), | ||
}, | ||
]); | ||
}); | ||
|
||
sentryTest( | ||
'click that triggers error & mutation is not captured', | ||
async ({ getLocalTestUrl, page, forceFlushReplay }) => { | ||
if (shouldSkipReplayTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
|
||
let slowClickCount = 0; | ||
|
||
page.on('response', res => { | ||
const req = res.request(); | ||
|
||
const event = getReplayEventFromRequest(req); | ||
|
||
if (!event) { | ||
return; | ||
} | ||
|
||
const { breadcrumbs } = getCustomRecordingEvents(res); | ||
|
||
const slowClicks = breadcrumbs.filter(breadcrumb => breadcrumb.category === 'ui.slowClickDetected'); | ||
slowClickCount += slowClicks.length; | ||
}); | ||
|
||
const [req1] = await Promise.all([ | ||
waitForReplayRequest(page, (_event, res) => { | ||
const { breadcrumbs } = getCustomRecordingEvents(res); | ||
|
||
return breadcrumbs.some(breadcrumb => breadcrumb.category === 'ui.click'); | ||
}), | ||
page.click('#buttonErrorMutation'), | ||
]); | ||
|
||
const { breadcrumbs } = getCustomRecordingEvents(req1); | ||
|
||
expect(breadcrumbs).toEqual([ | ||
{ | ||
category: 'ui.click', | ||
data: { | ||
node: { | ||
attributes: { | ||
id: 'buttonErrorMutation', | ||
}, | ||
id: expect.any(Number), | ||
tagName: 'button', | ||
textContent: '******* *****', | ||
}, | ||
nodeId: expect.any(Number), | ||
}, | ||
message: 'body > button#buttonErrorMutation', | ||
timestamp: expect.any(Number), | ||
type: 'default', | ||
}, | ||
]); | ||
|
||
// Ensure we wait for timeout, to make sure no slow click is created | ||
// Waiting for 3500 + 1s rounding room | ||
await new Promise(resolve => setTimeout(resolve, 4500)); | ||
await forceFlushReplay(); | ||
|
||
expect(slowClickCount).toBe(0); | ||
}, | ||
); |
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
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