1- import { describe , it , expect , beforeEach , vi , afterEach } from 'vitest ' ;
2- import { AbstractPowerSyncDatabase , PowerSyncDatabase , SyncStreamConnectionMethod } from '@powersync/web ' ;
1+ import { createBaseLogger , PowerSyncDatabase } from '@powersync/web ' ;
2+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest ' ;
33import { testSchema } from '../../utils/testDb' ;
44
55describe ( 'PowerSyncDatabase' , ( ) => {
@@ -9,9 +9,10 @@ describe('PowerSyncDatabase', () => {
99 let mockSyncImplementation : any ;
1010
1111 beforeEach ( ( ) => {
12+ const logger = createBaseLogger ( ) ;
1213 mockLogger = {
13- debug : vi . fn ( ) ,
14- warn : vi . fn ( )
14+ debug : vi . spyOn ( logger , 'debug' ) ,
15+ warn : vi . spyOn ( logger , 'warn' )
1516 } ;
1617
1718 // Initialize with minimal required options
@@ -20,12 +21,8 @@ describe('PowerSyncDatabase', () => {
2021 database : {
2122 dbFilename : 'test.db'
2223 } ,
23- logger : mockLogger
24+ logger
2425 } ) ;
25-
26- vi . spyOn ( db as any , 'runExclusive' ) . mockImplementation ( ( cb : any ) => cb ( ) ) ;
27-
28- vi . spyOn ( AbstractPowerSyncDatabase . prototype , 'connect' ) . mockResolvedValue ( undefined ) ;
2926 } ) ;
3027
3128 afterEach ( ( ) => {
@@ -36,27 +33,6 @@ describe('PowerSyncDatabase', () => {
3633 it ( 'should log debug message when attempting to connect' , async ( ) => {
3734 await db . connect ( mockConnector ) ;
3835 expect ( mockLogger . debug ) . toHaveBeenCalledWith ( 'Attempting to connect to PowerSync instance' ) ;
39- expect ( db [ 'runExclusive' ] ) . toHaveBeenCalled ( ) ;
40- } ) ;
41-
42- it ( 'should use connect with correct options' , async ( ) => {
43- await db . connect ( mockConnector , {
44- retryDelayMs : 1000 ,
45- crudUploadThrottleMs : 2000 ,
46- params : {
47- param1 : 1
48- } ,
49- connectionMethod : SyncStreamConnectionMethod . HTTP
50- } ) ;
51-
52- expect ( AbstractPowerSyncDatabase . prototype . connect ) . toHaveBeenCalledWith ( mockConnector , {
53- retryDelayMs : 1000 ,
54- crudUploadThrottleMs : 2000 ,
55- connectionMethod : 'http' ,
56- params : {
57- param1 : 1
58- }
59- } ) ;
6036 } ) ;
6137 } ) ;
6238} ) ;
0 commit comments