Skip to content

Commit 27d4a32

Browse files
make node tests more stable
1 parent 86d6a20 commit 27d4a32

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

packages/node/tests/sync.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import { describe, vi, expect, beforeEach } from 'vitest';
21
import util from 'node:util';
2+
import { beforeEach, describe, expect, vi } from 'vitest';
33

4-
import { bucket, MockSyncService, mockSyncServiceTest, TestConnector, waitForSyncStatus } from './utils';
54
import {
65
AbstractPowerSyncDatabase,
76
BucketChecksum,
@@ -14,6 +13,7 @@ import {
1413
SyncStreamConnectionMethod
1514
} from '@powersync/common';
1615
import Logger from 'js-logger';
16+
import { bucket, MockSyncService, mockSyncServiceTest, TestConnector, waitForSyncStatus } from './utils';
1717

1818
describe('Sync', () => {
1919
describe('js client', () => {
@@ -821,10 +821,11 @@ function defineSyncTests(impl: SyncClientImplementation) {
821821
const powersync = await syncService.createDatabase({ schema: customSchema, logger });
822822
powersync.connect(new TestConnector(), options);
823823

824-
await vi.waitFor(() => expect(syncService.connectedListeners).toHaveLength(1));
825-
expect(logMessages).toEqual(
826-
expect.arrayContaining([expect.stringContaining('Raw tables require the Rust-based sync client')])
827-
);
824+
await vi.waitFor(() => {
825+
expect(logMessages).toEqual(
826+
expect.arrayContaining([expect.stringContaining('Raw tables require the Rust-based sync client')])
827+
);
828+
});
828829
});
829830

830831
mockSyncServiceTest(`does not warn about raw tables if they're not used`, async ({ syncService }) => {

packages/node/tests/utils.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ import { onTestFinished, test } from 'vitest';
99
import {
1010
AbstractPowerSyncDatabase,
1111
BucketChecksum,
12-
column,
1312
NodePowerSyncDatabaseOptions,
1413
PowerSyncBackendConnector,
1514
PowerSyncCredentials,
1615
PowerSyncDatabase,
17-
PowerSyncDatabaseOptions,
1816
Schema,
1917
StreamingSyncCheckpoint,
2018
StreamingSyncLine,
2119
SyncStatus,
22-
Table
20+
Table,
21+
column
2322
} from '../lib';
2423

2524
export async function createTempDir() {
@@ -67,7 +66,7 @@ export async function createDatabase(
6766
const database = new PowerSyncDatabase({
6867
schema: AppSchema,
6968
...options,
70-
logger: defaultLogger,
69+
logger: options.logger ?? defaultLogger,
7170
database: {
7271
dbFilename: 'test.db',
7372
dbLocation: tmpdir,
@@ -103,6 +102,9 @@ export const mockSyncServiceTest = tempDirectoryTest.extend<{
103102
stream: ReadableStreamDefaultController<StreamingSyncLine>;
104103
}
105104

105+
// Uses a unique database name per mockSyncServiceTest to avoid conflicts with other tests.
106+
const databaseName = `test-${crypto.randomUUID()}.db`;
107+
106108
const listeners: Listener[] = [];
107109

108110
const inMemoryFetch: typeof fetch = async (info, init?) => {
@@ -149,6 +151,10 @@ export const mockSyncServiceTest = tempDirectoryTest.extend<{
149151
const newConnection = async (options?: Partial<NodePowerSyncDatabaseOptions>) => {
150152
const db = await createDatabase(tmpdir, {
151153
...options,
154+
database: {
155+
dbFilename: databaseName,
156+
...options?.database
157+
},
152158
remoteOptions: {
153159
fetchImplementation: inMemoryFetch
154160
}

0 commit comments

Comments
 (0)