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 e3e45a2 commit 1c7c64f
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 @@ -11,6 +11,9 @@ import { Context, ContextCancelation } from '../../context'
import { Plugin } from '../../plugin'
import { EventQueue } from '../event-queue'
import { pTimeout } from '../../callback'
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 @@ -148,7 +151,8 @@ describe('Flushing', () => {
return Promise.resolve(ctx)
},
},
ajs
ajs,
storage
)

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

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

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

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

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

const fruitBasketDelivery = eq.dispatch(fruitBasket)
Expand Down Expand Up @@ -428,9 +437,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 @@ -461,9 +470,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 @@ -495,9 +504,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 @@ -529,9 +538,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 @@ -562,9 +571,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 @@ -597,8 +606,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 @@ -628,9 +637,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 @@ -649,7 +658,8 @@ describe('Flushing', () => {
await eq.register(
Context.system(),
sourceMiddlewarePlugin(skipAmplitudeAndSegment, {}),
ajs
ajs,
storage
)

await eq.dispatch(ctx)
Expand All @@ -667,7 +677,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 @@ -680,7 +692,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 @@ -743,7 +757,8 @@ describe('dispatchSingle', () => {
return Promise.resolve(ctx)
},
},
ajs
ajs,
storage
)

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

0 comments on commit 1c7c64f

Please sign in to comment.