diff --git a/packages/browser/src/browser/__tests__/integration.test.ts b/packages/browser/src/browser/__tests__/integration.test.ts index 222573a65..95bd97f30 100644 --- a/packages/browser/src/browser/__tests__/integration.test.ts +++ b/packages/browser/src/browser/__tests__/integration.test.ts @@ -29,6 +29,7 @@ import { import { getGlobalAnalytics } from '../../lib/global-analytics-helper' import { NullAnalytics } from '../../core/analytics' import { recordIntegrationMetric } from '../../core/stats/metric-helpers' +import { waitForCondition } from '../../test-helpers/helpers' let fetchCalls: ReturnType[] = [] @@ -386,6 +387,38 @@ describe('Initialization', () => { describe('options.integrations permutations', () => { const settings = { writeKey } + it('proxies integration options', async () => { + const analytics = AnalyticsBrowser.load(settings) + analytics.track( + 'foo', + {}, + { + integrations: { + Warehouses: { + warehouseIds: ['3dasf42dd'], + all: true, + }, + }, + } + ) + await waitForCondition(() => { + return fetchCalls.some((el) => el.url.toString().includes('/v1/t')) + }) + const trackCall = fetchCalls.find((el) => + el.url.toString().includes('/v1/t') + ) + expect(trackCall?.body.integrations).toMatchInlineSnapshot(` + { + "Warehouses": { + "all": true, + "warehouseIds": [ + "3dasf42dd", + ], + }, + } + `) + }) + it('does not load Segment.io if integrations.All is false and Segment.io is not listed', async () => { const options: { integrations: { [key: string]: boolean } } = { integrations: { All: false }, diff --git a/packages/browser/src/test-helpers/helpers.ts b/packages/browser/src/test-helpers/helpers.ts new file mode 100644 index 000000000..4b04dda37 --- /dev/null +++ b/packages/browser/src/test-helpers/helpers.ts @@ -0,0 +1,14 @@ +import { sleep } from '@segment/analytics-core' + +export const waitForCondition = async ( + condition: () => boolean, + timeout = 1000 +): Promise => { + const start = Date.now() + while (!condition()) { + if (Date.now() - start > timeout) { + throw new Error(`Timeout of ${timeout}ms exceeded!`) + } + await sleep(10) + } +}