1515 */
1616import { beforeEach , describe , expect , it , vi } from 'vitest' ;
1717
18+ // vitest does not handle Class mock well when transpiling to ES6 with { spy: true }.
19+ // So we provide manual mocks here.
20+ // Also importOriginal() does not work in browser mode, so we mock every export explicitly.
21+
1822vi . mock ( './default_dispatcher.browser' , ( ) => {
1923 return { default : { } } ;
2024} ) ;
2125
22- vi . mock ( './event_processor_factory' , async ( importOriginal ) => {
26+ vi . mock ( './event_processor_factory' , ( ) => {
27+ // Create a unique symbol for wrapping/unwrapping
28+ const eventProcessorSymbol = Symbol ( 'eventProcessor' ) ;
29+
2330 const getBatchEventProcessor = vi . fn ( ) . mockImplementation ( ( ) => {
2431 return { } ;
2532 } ) ;
@@ -29,25 +36,54 @@ vi.mock('./event_processor_factory', async (importOriginal) => {
2936 const getForwardingEventProcessor = vi . fn ( ) . mockImplementation ( ( ) => {
3037 return { } ;
3138 } ) ;
32- const original : any = await importOriginal ( ) ;
33- return { ...original , getBatchEventProcessor, getOpaqueBatchEventProcessor, getForwardingEventProcessor, FAILED_EVENT_RETRY_INTERVAL : 20000 } ;
39+
40+ return {
41+ INVALID_EVENT_DISPATCHER : 'Invalid event dispatcher' ,
42+ FAILED_EVENT_RETRY_INTERVAL : 20000 ,
43+ getPrefixEventStore : vi . fn ( ) ,
44+ validateEventDispatcher : vi . fn ( ) ,
45+ getBatchEventProcessor,
46+ wrapEventProcessor : vi . fn ( ( ep ) => ( { [ eventProcessorSymbol ] : ep } ) ) ,
47+ getOpaqueBatchEventProcessor,
48+ extractEventProcessor : vi . fn ( ( ep ) => ep ?. [ eventProcessorSymbol ] ) ,
49+ getForwardingEventProcessor,
50+ __platforms : [ '__universal__' ] ,
51+ } ;
3452} ) ;
3553
3654vi . mock ( '../utils/cache/local_storage_cache.browser' , ( ) => {
3755 return { LocalStorageCache : vi . fn ( ) } ;
3856} ) ;
3957
40- vi . mock ( './event_store' , async ( importOriginal ) => {
41- const actual : any = await importOriginal ( )
58+ vi . mock ( './event_store' , ( ) => {
4259 return {
43- ...actual ,
60+ DEFAULT_MAX_EVENTS_IN_STORE : 500 ,
61+ DEFAULT_STORE_TTL : 10 * 24 * 60 * 60 * 1000 ,
62+ EVENT_STORE_PREFIX : 'optly_event:' ,
4463 EventStore : vi . fn ( ) ,
45- }
64+ __platforms : [ '__universal__' ] ,
65+ } ;
4666} ) ;
4767
48- vi . mock ( '../utils/cache/store' , async ( importOriginal ) => {
49- const actual : any = await importOriginal ( )
50- return { ...actual , SyncPrefixStore : vi . fn ( ) , AsyncPrefixStore : vi . fn ( ) } ;
68+ vi . mock ( '../utils/cache/store' , ( ) => {
69+ // Create base abstract classes
70+ class SyncStoreWithBatchedGet {
71+ operation = 'sync' as const ;
72+ }
73+
74+ class AsyncStoreWithBatchedGet {
75+ operation = 'async' as const ;
76+ }
77+
78+ return {
79+ SyncStoreWithBatchedGet,
80+ AsyncStoreWithBatchedGet,
81+ getBatchedSync : vi . fn ( ) ,
82+ getBatchedAsync : vi . fn ( ) ,
83+ SyncPrefixStore : vi . fn ( ) ,
84+ AsyncPrefixStore : vi . fn ( ) ,
85+ __platforms : [ '__universal__' ] ,
86+ } ;
5187} ) ;
5288
5389
0 commit comments