Skip to content

Commit f64835a

Browse files
Adds integration test for action destinations in addDestinationMiddleware (#683)
1 parent 694f3aa commit f64835a

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { PriorityQueue } from '../../lib/priority-queue'
1919
import { getCDN, setGlobalCDNUrl } from '../../lib/parse-cdn'
2020
import { clearAjsBrowserStorage } from '../../test-helpers/browser-storage'
21+
import { ActionDestination } from '@/plugins/remote-loader'
2122

2223
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2324
let fetchCalls: Array<any>[] = []
@@ -711,6 +712,35 @@ describe('addDestinationMiddleware', () => {
711712
hello: 'from the other side',
712713
})
713714
})
715+
716+
it('supports registering action destination middlewares', async () => {
717+
const testPlugin: Plugin = {
718+
name: 'test',
719+
type: 'destination',
720+
version: '0.1.0',
721+
load: () => Promise.resolve(),
722+
isLoaded: () => true,
723+
}
724+
725+
const [analytics] = await AnalyticsBrowser.load({
726+
writeKey,
727+
})
728+
729+
const fullstory = new ActionDestination('fullstory', testPlugin)
730+
731+
await analytics.register(fullstory)
732+
await fullstory.ready()
733+
734+
analytics
735+
.addDestinationMiddleware('fullstory', ({ next, payload }) =>
736+
next(payload)
737+
)
738+
.catch((err) => {
739+
throw err
740+
})
741+
742+
expect(analytics.queue.plugins).toContain(fullstory)
743+
})
714744
})
715745

716746
describe('use', () => {

packages/browser/src/core/analytics/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,7 @@ export class Analytics
405405
...middlewares: DestinationMiddlewareFunction[]
406406
): Promise<Analytics> {
407407
const legacyDestinations = this.queue.plugins.filter(
408-
(xt) =>
409-
// xt instanceof LegacyDestination &&
410-
xt.name.toLowerCase() === integrationName.toLowerCase()
408+
(xt) => xt.name.toLowerCase() === integrationName.toLowerCase()
411409
) as LegacyDestination[]
412410

413411
legacyDestinations.forEach((destination) => {

0 commit comments

Comments
 (0)