Skip to content

Commit 419abb1

Browse files
committed
Fix multiple instances test
1 parent e095c7f commit 419abb1

2 files changed

Lines changed: 18 additions & 17 deletions

File tree

packages/web/src/db/sync/SharedWebStreamingSyncImplementation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class SharedSyncClientProvider extends AbstractSharedSyncClientProvider {
6868
}
6969

7070
log(level: number, ...message: any[]): void {
71-
this.logger?.log(level, message);
71+
this.logger?.log(level, ...message);
7272
}
7373
}
7474

packages/web/tests/multiple_instances.test.ts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,19 @@ describe('Multiple Instances', { sequential: true }, () => {
4646
'should broadcast logs from shared sync worker',
4747
{ timeout: 10_000 },
4848
async ({ context: { openDatabase, mockService } }) => {
49-
const logFn = vi.fn();
50-
const logger: PowerSyncLogger = { log: logFn };
49+
const logLines: string[] = [];
50+
const logger: PowerSyncLogger = {
51+
log(_level, ...message) {
52+
logLines.push(message[0]);
53+
}
54+
};
5155

5256
// Open an additional database which we can spy on the logs.
5357
const powersync = openDatabase({
54-
logger
58+
logger,
59+
sync: {
60+
logLevel: LogLevels.trace
61+
}
5562
});
5663

5764
powersync.connect({
@@ -78,22 +85,16 @@ describe('Multiple Instances', { sequential: true }, () => {
7885

7986
// Asserting that powersync_control logs exists verifies that some connection attempt was made.
8087
await vi.waitFor(
81-
() =>
82-
expect(
83-
logFn.mock.calls
84-
.flat(1)
85-
.find((argument) => typeof argument == 'string' && argument.includes('powersync_control'))
86-
).exist,
87-
{ timeout: 2000 }
88+
() => expect(logLines).toEqual(expect.arrayContaining([expect.stringContaining('powersync_control')])),
89+
{
90+
timeout: 2000
91+
}
8892
);
8993

9094
// The connection should fail with an error
91-
await vi.waitFor(
92-
() =>
93-
expect(logFn.mock.calls.flat(1).find((argument) => typeof argument == 'string' && argument.includes('error')))
94-
.exist,
95-
{ timeout: 2000 }
96-
);
95+
await vi.waitFor(() => expect(logLines).toEqual(expect.arrayContaining([expect.any(Error)])), {
96+
timeout: 2000
97+
});
9798
}
9899
);
99100

0 commit comments

Comments
 (0)