-
-
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
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
dev-packages/browser-integration-tests/suites/transport/offline/flush/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 @@ | ||
setTimeout(() => { | ||
Sentry.captureMessage(`foo ${Math.random()}`); | ||
}, 500); | ||
|
||
setTimeout(() => { | ||
Sentry.flush(); | ||
}, 2000); |
47 changes: 47 additions & 0 deletions
47
dev-packages/browser-integration-tests/suites/transport/offline/flush/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,47 @@ | ||
import { expect } from '@playwright/test'; | ||
import type { Event } from '@sentry/core'; | ||
|
||
import { sentryTest } from '../../../../utils/fixtures'; | ||
import { getMultipleSentryEnvelopeRequests } from '../../../../utils/helpers'; | ||
|
||
function delay(ms: number) { | ||
return new Promise(resolve => setTimeout(resolve, ms)); | ||
} | ||
|
||
sentryTest('should flush event', async ({ getLocalTestUrl, page }) => { | ||
// makeBrowserOfflineTransport is not included in any CDN bundles | ||
if (process.env.PW_BUNDLE && process.env.PW_BUNDLE.startsWith('bundle')) { | ||
sentryTest.skip(); | ||
} | ||
|
||
const url = await getLocalTestUrl({ testDir: __dirname }); | ||
|
||
// This would be the obvious way to test offline support but it doesn't appear to work! | ||
// await context.setOffline(true); | ||
|
||
let abortedCount = 0; | ||
|
||
// Abort all envelope requests so the event gets queued | ||
await page.route(/ingest\.sentry\.io/, route => { | ||
Check failure Code scanning / CodeQL Missing regular expression anchor High test
When this is used as a regular expression on a URL, it may match anywhere, and arbitrary hosts may come before or after it.
|
||
abortedCount += 1; | ||
return route.abort(); | ||
}); | ||
await page.goto(url); | ||
await delay(1_000); | ||
await page.unroute(/ingest\.sentry\.io/); | ||
Check failure Code scanning / CodeQL Missing regular expression anchor High test
When this is used as a regular expression on a URL, it may match anywhere, and arbitrary hosts may come before or after it.
|
||
|
||
expect(abortedCount).toBe(1); | ||
|
||
// The previous event should now be queued | ||
|
||
// It should get flushed after a few seconds | ||
const eventData = await getMultipleSentryEnvelopeRequests<Event>(page, 2, { timeout: 4_000 }); | ||
|
||
// Filter out any client reports | ||
const events = eventData.filter(e => !('discarded_events' in e)) as Event[]; | ||
|
||
expect(events).toHaveLength(1); | ||
|
||
// The next two events will be message events starting with 'foo' | ||
expect(events[0].message?.startsWith('foo')); | ||
}); |