File tree Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Expand file tree Collapse file tree 2 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import {
2929import { getGlobalAnalytics } from '../../lib/global-analytics-helper'
3030import { NullAnalytics } from '../../core/analytics'
3131import { recordIntegrationMetric } from '../../core/stats/metric-helpers'
32+ import { waitForCondition } from '../../test-helpers/helpers'
3233
3334let 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 } ,
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments