Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pooyaj committed Oct 28, 2022
1 parent 0e2d442 commit 11a9258
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 32 deletions.
9 changes: 7 additions & 2 deletions packages/browser/src/browser/__tests__/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import {
} from '../../test-helpers/test-writekeys'
import { PriorityQueue } from '../../lib/priority-queue'
import { getCDN, setGlobalCDNUrl } from '../../lib/parse-cdn'
import { UniversalStorage } from '../../core/user'

const storage = {} as UniversalStorage

// eslint-disable-next-line @typescript-eslint/no-explicit-any
let fetchCalls: Array<any>[] = []
Expand Down Expand Up @@ -847,7 +850,8 @@ describe('retries', () => {
throw new Error('aaay')
},
},
ajs
ajs,
storage
)

// Dispatching an event will push it into the priority queue.
Expand Down Expand Up @@ -875,7 +879,8 @@ describe('retries', () => {
ready: () => Promise.resolve(true),
track: (ctx) => ctx,
},
ajs
ajs,
storage
)

// @ts-ignore ignore reassining function
Expand Down
75 changes: 45 additions & 30 deletions packages/browser/src/core/queue/__tests__/event-queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { Plugin } from '../../plugin'
import { EventQueue } from '../event-queue'
import { pTimeout } from '../../callback'
import { ActionDestination } from '../../../plugins/remote-loader'
import { UniversalStorage } from '../../user'

const storage = {} as UniversalStorage

async function flushAll(eq: EventQueue): Promise<Context[]> {
const flushSpy = jest.spyOn(eq, 'flush')
Expand Down Expand Up @@ -149,7 +152,8 @@ describe('Flushing', () => {
return Promise.resolve(ctx)
},
},
ajs
ajs,
storage
)

eq.dispatch(fruitBasket)
Expand Down Expand Up @@ -219,7 +223,8 @@ describe('Flushing', () => {
return Promise.resolve(ctx)
},
},
ajs
ajs,
storage
)

eq.dispatch(fruitBasket)
Expand Down Expand Up @@ -257,7 +262,8 @@ describe('Flushing', () => {
return ctx
},
},
ajs
ajs,
storage
)

const dispatches = [
Expand Down Expand Up @@ -294,7 +300,8 @@ describe('Flushing', () => {
return ctx
},
},
ajs
ajs,
storage
)

const context = await eq.dispatchSingle(fruitBasket)
Expand All @@ -321,7 +328,8 @@ describe('Flushing', () => {
return Promise.resolve(ctx)
},
},
ajs
ajs,
storage
)

eq.dispatch(fruitBasket)
Expand Down Expand Up @@ -362,7 +370,8 @@ describe('Flushing', () => {
return Promise.resolve(ctx)
},
},
ajs
ajs,
storage
)

const fruitBasketDelivery = eq.dispatch(fruitBasket)
Expand Down Expand Up @@ -429,9 +438,9 @@ describe('Flushing', () => {

const ctx = new Context(evt)

await eq.register(Context.system(), amplitude, ajs)
await eq.register(Context.system(), mixPanel, ajs)
await eq.register(Context.system(), segmentio, ajs)
await eq.register(Context.system(), amplitude, ajs, storage)
await eq.register(Context.system(), mixPanel, ajs, storage)
await eq.register(Context.system(), segmentio, ajs, storage)

eq.dispatch(ctx)

Expand Down Expand Up @@ -462,9 +471,9 @@ describe('Flushing', () => {

const ctx = new Context(evt)

await eq.register(Context.system(), amplitude, ajs)
await eq.register(Context.system(), mixPanel, ajs)
await eq.register(Context.system(), segmentio, ajs)
await eq.register(Context.system(), amplitude, ajs, storage)
await eq.register(Context.system(), mixPanel, ajs, storage)
await eq.register(Context.system(), segmentio, ajs, storage)

eq.dispatch(ctx)

Expand Down Expand Up @@ -496,9 +505,9 @@ describe('Flushing', () => {

const ctx = new Context(evt)

await eq.register(Context.system(), amplitude, ajs)
await eq.register(Context.system(), mixPanel, ajs)
await eq.register(Context.system(), segmentio, ajs)
await eq.register(Context.system(), amplitude, ajs, storage)
await eq.register(Context.system(), mixPanel, ajs, storage)
await eq.register(Context.system(), segmentio, ajs, storage)

eq.dispatch(ctx)

Expand Down Expand Up @@ -530,9 +539,9 @@ describe('Flushing', () => {

const ctx = new Context(evt)

await eq.register(Context.system(), amplitude, ajs)
await eq.register(Context.system(), mixPanel, ajs)
await eq.register(Context.system(), segmentio, ajs)
await eq.register(Context.system(), amplitude, ajs, storage)
await eq.register(Context.system(), mixPanel, ajs, storage)
await eq.register(Context.system(), segmentio, ajs, storage)

eq.dispatch(ctx)

Expand Down Expand Up @@ -563,9 +572,9 @@ describe('Flushing', () => {

const ctx = new Context(evt)

await eq.register(Context.system(), amplitude, ajs)
await eq.register(Context.system(), mixPanel, ajs)
await eq.register(Context.system(), segmentio, ajs)
await eq.register(Context.system(), amplitude, ajs, storage)
await eq.register(Context.system(), mixPanel, ajs, storage)
await eq.register(Context.system(), segmentio, ajs, storage)

eq.dispatch(ctx)

Expand Down Expand Up @@ -598,8 +607,8 @@ describe('Flushing', () => {

const ctx = new Context(evt)

await eq.register(Context.system(), amplitude, ajs)
await eq.register(Context.system(), segmentio, ajs)
await eq.register(Context.system(), amplitude, ajs, storage)
await eq.register(Context.system(), segmentio, ajs, storage)

eq.dispatch(ctx)

Expand Down Expand Up @@ -663,9 +672,9 @@ describe('Flushing', () => {
}

const ctx = new Context(evt)
await eq.register(Context.system(), amplitude, ajs)
await eq.register(Context.system(), mixPanel, ajs)
await eq.register(Context.system(), segmentio, ajs)
await eq.register(Context.system(), amplitude, ajs, storage)
await eq.register(Context.system(), mixPanel, ajs, storage)
await eq.register(Context.system(), segmentio, ajs, storage)
await eq.dispatch(ctx)

const skipAmplitudeAndSegment: MiddlewareFunction = ({
Expand All @@ -684,7 +693,8 @@ describe('Flushing', () => {
await eq.register(
Context.system(),
sourceMiddlewarePlugin(skipAmplitudeAndSegment, {}),
ajs
ajs,
storage
)

await eq.dispatch(ctx)
Expand All @@ -702,7 +712,9 @@ describe('deregister', () => {
const toBeRemoved = { ...testPlugin, name: 'remove-me' }
const plugins = [testPlugin, toBeRemoved]

const promises = plugins.map((p) => eq.register(Context.system(), p, ajs))
const promises = plugins.map((p) =>
eq.register(Context.system(), p, ajs, storage)
)
await Promise.all(promises)

await eq.deregister(Context.system(), toBeRemoved, ajs)
Expand All @@ -715,7 +727,9 @@ describe('deregister', () => {
const toBeRemoved = { ...testPlugin, name: 'remove-me', unload: jest.fn() }
const plugins = [testPlugin, toBeRemoved]

const promises = plugins.map((p) => eq.register(Context.system(), p, ajs))
const promises = plugins.map((p) =>
eq.register(Context.system(), p, ajs, storage)
)
await Promise.all(promises)

await eq.deregister(Context.system(), toBeRemoved, ajs)
Expand Down Expand Up @@ -778,7 +792,8 @@ describe('dispatchSingle', () => {
return Promise.resolve(ctx)
},
},
ajs
ajs,
storage
)

expect(eq.queue.length).toBe(0)
Expand Down

0 comments on commit 11a9258

Please sign in to comment.