Skip to content

Commit c9f81ac

Browse files
authored
Add extra test for integrations object on ajs (#1221)
1 parent 4828c79 commit c9f81ac

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

packages/browser/src/browser/__tests__/integration.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
import { getGlobalAnalytics } from '../../lib/global-analytics-helper'
3030
import { NullAnalytics } from '../../core/analytics'
3131
import { recordIntegrationMetric } from '../../core/stats/metric-helpers'
32+
import { waitForCondition } from '../../test-helpers/helpers'
3233

3334
let fetchCalls: ReturnType<typeof parseFetchCall>[] = []
3435

@@ -386,6 +387,38 @@ describe('Initialization', () => {
386387
describe('options.integrations permutations', () => {
387388
const settings = { writeKey }
388389

390+
it('proxies integration options', async () => {
391+
const analytics = AnalyticsBrowser.load(settings)
392+
analytics.track(
393+
'foo',
394+
{},
395+
{
396+
integrations: {
397+
Warehouses: {
398+
warehouseIds: ['3dasf42dd'],
399+
all: true,
400+
},
401+
},
402+
}
403+
)
404+
await waitForCondition(() => {
405+
return fetchCalls.some((el) => el.url.toString().includes('/v1/t'))
406+
})
407+
const trackCall = fetchCalls.find((el) =>
408+
el.url.toString().includes('/v1/t')
409+
)
410+
expect(trackCall?.body.integrations).toMatchInlineSnapshot(`
411+
{
412+
"Warehouses": {
413+
"all": true,
414+
"warehouseIds": [
415+
"3dasf42dd",
416+
],
417+
},
418+
}
419+
`)
420+
})
421+
389422
it('does not load Segment.io if integrations.All is false and Segment.io is not listed', async () => {
390423
const options: { integrations: { [key: string]: boolean } } = {
391424
integrations: { All: false },
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { sleep } from '@segment/analytics-core'
2+
3+
export const waitForCondition = async (
4+
condition: () => boolean,
5+
timeout = 1000
6+
): Promise<void> => {
7+
const start = Date.now()
8+
while (!condition()) {
9+
if (Date.now() - start > timeout) {
10+
throw new Error(`Timeout of ${timeout}ms exceeded!`)
11+
}
12+
await sleep(10)
13+
}
14+
}

0 commit comments

Comments
 (0)