diff --git a/dev-packages/browser-integration-tests/suites/transport/offline/flush/subject.js b/dev-packages/browser-integration-tests/suites/transport/offline/flush/subject.js deleted file mode 100644 index 27ce1c0c0b52..000000000000 --- a/dev-packages/browser-integration-tests/suites/transport/offline/flush/subject.js +++ /dev/null @@ -1,7 +0,0 @@ -setTimeout(() => { - Sentry.captureMessage(`foo ${Math.random()}`); -}, 500); - -setTimeout(() => { - Sentry.flush(); -}, 2000); diff --git a/dev-packages/browser-integration-tests/suites/transport/offline/flush/test.ts b/dev-packages/browser-integration-tests/suites/transport/offline/flush/test.ts deleted file mode 100644 index b7feab8a6448..000000000000 --- a/dev-packages/browser-integration-tests/suites/transport/offline/flush/test.ts +++ /dev/null @@ -1,47 +0,0 @@ -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 => { - abortedCount += 1; - return route.abort(); - }); - await page.goto(url); - await delay(1_000); - await page.unroute(/ingest\.sentry\.io/); - - expect(abortedCount).toBe(1); - - // The previous event should now be queued - - // It should get flushed after a few seconds - const eventData = await getMultipleSentryEnvelopeRequests(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')); -}); diff --git a/packages/browser/test/transports/offline.test.ts b/packages/browser/test/transports/offline.test.ts index a9a396949588..070d6623f967 100644 --- a/packages/browser/test/transports/offline.test.ts +++ b/packages/browser/test/transports/offline.test.ts @@ -64,6 +64,7 @@ describe('makeOfflineTransport', () => { await deleteDatabase('sentry'); (global as any).TextEncoder = TextEncoder; (global as any).TextDecoder = TextDecoder; + (global as any).addEventListener = () => {}; }); it('indexedDb wrappers push, unshift and pop', async () => { @@ -115,4 +116,32 @@ describe('makeOfflineTransport', () => { expect(queuedCount).toEqual(1); expect(getSendCount()).toEqual(2); }); + + it('flush forces retry', async () => { + const { getSendCount, baseTransport } = createTestTransport(new Error(), { statusCode: 200 }, { statusCode: 200 }); + let queuedCount = 0; + const transport = makeBrowserOfflineTransport(baseTransport)({ + ...transportOptions, + shouldStore: () => { + queuedCount += 1; + return true; + }, + url: 'http://localhost', + }); + const result = await transport.send(ERROR_ENVELOPE); + + expect(result).toEqual({}); + + await delay(MIN_DELAY * 2); + + expect(getSendCount()).toEqual(0); + expect(queuedCount).toEqual(1); + + await transport.flush(); + + await delay(MIN_DELAY * 2); + + expect(queuedCount).toEqual(1); + expect(getSendCount()).toEqual(1); + }); });