Skip to content

Commit 40aad2b

Browse files
committed
Node: Properly wait for connection
1 parent 207c2a5 commit 40aad2b

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

packages/node/tests/stream.test.ts renamed to packages/node/tests/sync-stream.test.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { describe, vi, expect, beforeEach } from 'vitest';
2-
import { SyncClientImplementation, SyncStreamConnectionMethod } from '@powersync/common';
1+
import { describe, vi, expect } from 'vitest';
2+
import { PowerSyncConnectionOptions, SyncClientImplementation, SyncStreamConnectionMethod } from '@powersync/common';
33
import Logger from 'js-logger';
44
import { bucket, checkpoint, mockSyncServiceTest, nextStatus, stream, TestConnector } from './utils';
55

@@ -9,16 +9,15 @@ describe('Sync streams', () => {
99
const defaultOptions = {
1010
clientImplementation: SyncClientImplementation.RUST,
1111
connectionMethod: SyncStreamConnectionMethod.HTTP
12-
};
12+
} satisfies PowerSyncConnectionOptions;
1313

1414
mockSyncServiceTest('can disable default streams', async ({ syncService }) => {
1515
const database = await syncService.createDatabase();
16-
database.connect(new TestConnector(), {
16+
await database.connect(new TestConnector(), {
1717
includeDefaultStreams: false,
1818
...defaultOptions
1919
});
2020

21-
await vi.waitFor(() => expect(syncService.connectedListeners).toHaveLength(1));
2221
expect(syncService.connectedListeners[0]).toMatchObject({
2322
streams: {
2423
include_defaults: false,
@@ -32,8 +31,7 @@ describe('Sync streams', () => {
3231
const a = await database.syncStream('stream', { foo: 'a' }).subscribe();
3332
const b = await database.syncStream('stream', { foo: 'b' }).subscribe({ priority: 1 });
3433

35-
database.connect(new TestConnector(), defaultOptions);
36-
await vi.waitFor(() => expect(syncService.connectedListeners).toHaveLength(1));
34+
await database.connect(new TestConnector(), defaultOptions);
3735

3836
expect(syncService.connectedListeners[0]).toMatchObject({
3937
streams: {
@@ -84,8 +82,7 @@ describe('Sync streams', () => {
8482

8583
mockSyncServiceTest('reports default streams', async ({ syncService }) => {
8684
const database = await syncService.createDatabase();
87-
database.connect(new TestConnector(), defaultOptions);
88-
await vi.waitFor(() => expect(syncService.connectedListeners).toHaveLength(1));
85+
await database.connect(new TestConnector(), defaultOptions);
8986

9087
let statusPromise = nextStatus(database);
9188
syncService.pushLine(
@@ -110,8 +107,7 @@ describe('Sync streams', () => {
110107

111108
mockSyncServiceTest('changes subscriptions dynamically', async ({ syncService }) => {
112109
const database = await syncService.createDatabase();
113-
database.connect(new TestConnector(), defaultOptions);
114-
await vi.waitFor(() => expect(syncService.connectedListeners).toHaveLength(1));
110+
await database.connect(new TestConnector(), defaultOptions);
115111

116112
syncService.pushLine(
117113
checkpoint({

0 commit comments

Comments
 (0)