-
-
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
181 additions
and
1 deletion.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...-integration-tests/suites/replay/extendNetworkBreadcrumbs/fetch/captureTimestamps/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, | ||
}); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
sampleRate: 1, | ||
// We ensure to sample for errors, so by default nothing is sent | ||
replaysSessionSampleRate: 0.0, | ||
replaysOnErrorSampleRate: 1.0, | ||
|
||
integrations: [window.Replay], | ||
}); |
67 changes: 67 additions & 0 deletions
67
...-integration-tests/suites/replay/extendNetworkBreadcrumbs/fetch/captureTimestamps/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,67 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../../../utils/fixtures'; | ||
import { envelopeRequestParser, waitForErrorRequest } from '../../../../../utils/helpers'; | ||
import { | ||
getCustomRecordingEvents, | ||
shouldSkipReplayTest, | ||
waitForReplayRequest, | ||
} from '../../../../../utils/replayHelpers'; | ||
|
||
sentryTest('captures correct timestamps', async ({ getLocalTestPath, page, browserName }) => { | ||
// These are a bit flaky on non-chromium browsers | ||
if (shouldSkipReplayTest() || browserName !== 'chromium') { | ||
sentryTest.skip(); | ||
} | ||
|
||
await page.route('**/foo', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
}); | ||
}); | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', async route => { | ||
await new Promise(resolve => setTimeout(resolve, 10)); | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
const requestPromise = waitForErrorRequest(page); | ||
const replayRequestPromise1 = waitForReplayRequest(page, 0); | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
await page.goto(url); | ||
|
||
await page.evaluate(() => { | ||
/* eslint-disable */ | ||
fetch('http://localhost:7654/foo', { | ||
method: 'POST', | ||
body: '{"foo":"bar"}', | ||
}).then(() => { | ||
// @ts-expect-error Sentry is a global | ||
Sentry.captureException('test error'); | ||
}); | ||
/* eslint-enable */ | ||
}); | ||
|
||
const request = await requestPromise; | ||
const eventData = envelopeRequestParser(request); | ||
|
||
const replayReq1 = await replayRequestPromise1; | ||
const { performanceSpans: performanceSpans1 } = getCustomRecordingEvents(replayReq1); | ||
|
||
const xhrSpan = performanceSpans1.find(span => span.op === 'resource.fetch')!; | ||
|
||
expect(xhrSpan).toBeDefined(); | ||
|
||
const { startTimestamp, endTimestamp } = xhrSpan; | ||
|
||
expect(startTimestamp).toEqual(expect.any(Number)); | ||
expect(endTimestamp).toEqual(expect.any(Number)); | ||
expect(endTimestamp).toBeGreaterThan(startTimestamp); | ||
|
||
expect(eventData!.breadcrumbs![0].timestamp).toBeGreaterThan(startTimestamp); | ||
}); |
18 changes: 18 additions & 0 deletions
18
...er-integration-tests/suites/replay/extendNetworkBreadcrumbs/xhr/captureTimestamps/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, | ||
}); | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
sampleRate: 1, | ||
// We ensure to sample for errors, so by default nothing is sent | ||
replaysSessionSampleRate: 0.0, | ||
replaysOnErrorSampleRate: 1.0, | ||
|
||
integrations: [window.Replay], | ||
}); |
75 changes: 75 additions & 0 deletions
75
...er-integration-tests/suites/replay/extendNetworkBreadcrumbs/xhr/captureTimestamps/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,75 @@ | ||
import { expect } from '@playwright/test'; | ||
|
||
import { sentryTest } from '../../../../../utils/fixtures'; | ||
import { envelopeRequestParser, waitForErrorRequest } from '../../../../../utils/helpers'; | ||
import { | ||
getCustomRecordingEvents, | ||
shouldSkipReplayTest, | ||
waitForReplayRequest, | ||
} from '../../../../../utils/replayHelpers'; | ||
|
||
sentryTest('captures correct timestamps', async ({ getLocalTestPath, page, browserName }) => { | ||
// These are a bit flaky on non-chromium browsers | ||
if (shouldSkipReplayTest() || browserName !== 'chromium') { | ||
sentryTest.skip(); | ||
} | ||
|
||
await page.route('**/foo', route => { | ||
return route.fulfill({ | ||
status: 200, | ||
}); | ||
}); | ||
|
||
await page.route('https://dsn.ingest.sentry.io/**/*', async route => { | ||
await new Promise(resolve => setTimeout(resolve, 10)); | ||
return route.fulfill({ | ||
status: 200, | ||
contentType: 'application/json', | ||
body: JSON.stringify({ id: 'test-id' }), | ||
}); | ||
}); | ||
|
||
const requestPromise = waitForErrorRequest(page); | ||
const replayRequestPromise1 = waitForReplayRequest(page, 0); | ||
|
||
const url = await getLocalTestPath({ testDir: __dirname }); | ||
await page.goto(url); | ||
|
||
void page.evaluate(() => { | ||
/* eslint-disable */ | ||
const xhr = new XMLHttpRequest(); | ||
|
||
xhr.open('POST', 'http://localhost:7654/foo'); | ||
xhr.setRequestHeader('Accept', 'application/json'); | ||
xhr.setRequestHeader('Content-Type', 'application/json'); | ||
xhr.setRequestHeader('Cache', 'no-cache'); | ||
xhr.setRequestHeader('X-Test-Header', 'test-value'); | ||
xhr.send(); | ||
|
||
xhr.addEventListener('readystatechange', function () { | ||
if (xhr.readyState === 4) { | ||
// @ts-expect-error Sentry is a global | ||
setTimeout(() => Sentry.captureException('test error', 0)); | ||
} | ||
}); | ||
/* eslint-enable */ | ||
}); | ||
|
||
const request = await requestPromise; | ||
const eventData = envelopeRequestParser(request); | ||
|
||
const replayReq1 = await replayRequestPromise1; | ||
const { performanceSpans: performanceSpans1 } = getCustomRecordingEvents(replayReq1); | ||
|
||
const xhrSpan = performanceSpans1.find(span => span.op === 'resource.xhr')!; | ||
|
||
expect(xhrSpan).toBeDefined(); | ||
|
||
const { startTimestamp, endTimestamp } = xhrSpan; | ||
|
||
expect(startTimestamp).toEqual(expect.any(Number)); | ||
expect(endTimestamp).toEqual(expect.any(Number)); | ||
expect(endTimestamp).toBeGreaterThan(startTimestamp); | ||
|
||
expect(eventData!.breadcrumbs![0].timestamp).toBeGreaterThan(startTimestamp); | ||
}); |
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