Skip to content

Commit a2067d1

Browse files
committed
Better test logs
1 parent 93e5bf1 commit a2067d1

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

packages/common/src/client/ConnectionManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ class ActiveSubscription {
355355
}
356356

357357
class SyncStreamSubscriptionHandle implements SyncStreamSubscription {
358-
private active: boolean = false;
358+
private active: boolean = true;
359359

360360
constructor(readonly subscription: ActiveSubscription) {
361361
subscription.refcount++;

packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Logger, { ILogger } from 'js-logger';
22

3-
import { FULL_SYNC_PRIORITY, InternalProgressInformation } from '../../../db/crud/SyncProgress.js';
4-
import * as sync_status from '../../../db/crud/SyncStatus.js';
3+
import { InternalProgressInformation } from '../../../db/crud/SyncProgress.js';
54
import { SyncStatus, SyncStatusOptions } from '../../../db/crud/SyncStatus.js';
65
import { AbortOperation } from '../../../utils/AbortOperation.js';
76
import { BaseListener, BaseObserver, BaseObserverInterface, Disposable } from '../../../utils/BaseObserver.js';
@@ -1017,6 +1016,14 @@ The next upload iteration will be delayed.`);
10171016

10181017
async function control(op: PowerSyncControlCommand, payload?: Uint8Array | string) {
10191018
const rawResponse = await adapter.control(op, payload ?? null);
1019+
const logger = syncImplementation.logger;
1020+
logger.trace(
1021+
'powersync_control',
1022+
op,
1023+
payload == null || typeof payload == 'string' ? payload : '<bytes>',
1024+
rawResponse
1025+
);
1026+
10201027
await handleInstructions(JSON.parse(rawResponse));
10211028
}
10221029

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, vi, expect } from 'vitest';
1+
import { describe, vi, expect, onTestFinished } from 'vitest';
22
import { PowerSyncConnectionOptions, SyncClientImplementation, SyncStreamConnectionMethod } from '@powersync/common';
33
import Logger from 'js-logger';
44
import { bucket, checkpoint, mockSyncServiceTest, nextStatus, stream, TestConnector } from './utils';
@@ -30,6 +30,10 @@ describe('Sync streams', () => {
3030
const database = await syncService.createDatabase();
3131
const a = await database.syncStream('stream', { foo: 'a' }).subscribe();
3232
const b = await database.syncStream('stream', { foo: 'b' }).subscribe({ priority: 1 });
33+
onTestFinished(() => {
34+
a.unsubscribe();
35+
b.unsubscribe();
36+
});
3337

3438
await database.connect(new TestConnector(), defaultOptions);
3539

packages/node/tests/sync.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import {
1515
} from '@powersync/common';
1616
import Logger from 'js-logger';
1717

18-
Logger.useDefaults({ defaultLevel: Logger.WARN });
19-
2018
describe('Sync', () => {
2119
describe('js client', () => {
2220
defineSyncTests(SyncClientImplementation.JAVASCRIPT);

packages/node/tests/utils.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import {
1414
PowerSyncDatabase,
1515
Schema,
1616
StreamingSyncCheckpoint,
17-
StreamingSyncCheckpointComplete,
1817
StreamingSyncLine,
1918
SyncStatus,
2019
Table
2120
} from '../lib';
21+
import { createLogger } from '@powersync/common';
22+
import Logger from 'js-logger';
2223

2324
export async function createTempDir() {
2425
const ostmpdir = os.tmpdir();
@@ -57,12 +58,18 @@ export async function createDatabase(
5758
tmpdir: string,
5859
options: Partial<NodePowerSyncDatabaseOptions> = {}
5960
): Promise<PowerSyncDatabase> {
61+
const defaultLogger = createLogger('PowerSyncTest', { logLevel: Logger.TRACE });
62+
(defaultLogger as any).invoke = (_, args) => {
63+
console.log(...args);
64+
};
65+
6066
const database = new PowerSyncDatabase({
6167
schema: AppSchema,
6268
database: {
6369
dbFilename: 'test.db',
6470
dbLocation: tmpdir
6571
},
72+
logger: defaultLogger,
6673
...options
6774
});
6875
await database.init();

packages/node/vitest.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { defineConfig } from 'vitest/config';
22

33
// We need to define an empty config to be part of the vitest works
4-
export default defineConfig({});
4+
export default defineConfig({
5+
test: {
6+
silent: false
7+
}
8+
});

0 commit comments

Comments
 (0)