-
-
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.
test(replay): Add test for fetch and XHR performance spans (#7224)
- Loading branch information
Showing
5 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
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,17 @@ | ||
import * as Sentry from '@sentry/browser'; | ||
|
||
window.Sentry = Sentry; | ||
window.Replay = new Sentry.Replay({ | ||
flushMinDelay: 500, | ||
flushMaxDelay: 500, | ||
useCompression: true, | ||
}); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
sampleRate: 0, | ||
replaysSessionSampleRate: 1.0, | ||
replaysOnErrorSampleRate: 0.0, | ||
|
||
integrations: [window.Replay], | ||
}); |
16 changes: 16 additions & 0 deletions
16
packages/integration-tests/suites/replay/requests/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,16 @@ | ||
document.getElementById('go-background').addEventListener('click', () => { | ||
Object.defineProperty(document, 'hidden', { value: true, writable: true }); | ||
const ev = document.createEvent('Event'); | ||
ev.initEvent('visibilitychange'); | ||
document.dispatchEvent(ev); | ||
}); | ||
|
||
document.getElementById('fetch').addEventListener('click', () => { | ||
fetch('https://example.com'); | ||
}); | ||
|
||
document.getElementById('xhr').addEventListener('click', () => { | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('GET', 'https://example.com'); | ||
xhr.send(); | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/integration-tests/suites/replay/requests/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,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
</head> | ||
<body> | ||
<button id="go-background">Go to background</button> | ||
<button id="fetch">New Fetch Request</button> | ||
<button id="xhr">New Fetch Request</button> | ||
</body> | ||
</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,79 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../utils/fixtures'; | ||
import { expectedFetchPerformanceSpan, expectedXHRPerformanceSpan } from '../../../utils/replayEventTemplates'; | ||
import { getReplayRecordingContent, shouldSkipReplayTest, waitForReplayRequest } from '../../../utils/replayHelpers'; | ||
|
||
sentryTest('replay recording should contain fetch request span', async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipReplayTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const reqPromise0 = waitForReplayRequest(page, 0); | ||
const reqPromise1 = waitForReplayRequest(page, 1); | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
await page.route('https://example.com', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: 'hello world', | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
await page.click('#fetch'); | ||
await page.click('#go-background'); | ||
|
||
const { performanceSpans: spans0 } = getReplayRecordingContent(await reqPromise0); | ||
const { performanceSpans: spans1 } = getReplayRecordingContent(await reqPromise1); | ||
const performanceSpans = [...spans0, ...spans1]; | ||
|
||
expect(performanceSpans).toContainEqual(expectedFetchPerformanceSpan); | ||
}); | ||
|
||
sentryTest('replay recording should contain XHR request span', async ({ getLocalTestPath, page }) => { | ||
if (shouldSkipReplayTest()) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const reqPromise0 = waitForReplayRequest(page, 0); | ||
const reqPromise1 = waitForReplayRequest(page, 1); | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
await page.route('https://example.com', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: 'hello world', | ||
}); | ||
}); | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
|
||
await page.goto(url); | ||
await page.click('#xhr'); | ||
await page.click('#go-background'); | ||
|
||
const { performanceSpans: spans0 } = getReplayRecordingContent(await reqPromise0); | ||
const { performanceSpans: spans1 } = getReplayRecordingContent(await reqPromise1); | ||
const performanceSpans = [...spans0, ...spans1]; | ||
|
||
expect(performanceSpans).toContainEqual(expectedXHRPerformanceSpan); | ||
}); |
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