Skip to content

Commit f34f3ba

Browse files
committed
Fix web tests
1 parent 9c3cad4 commit f34f3ba

17 files changed

Lines changed: 40 additions & 29 deletions

packages/common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
233233
constructor(options: PowerSyncDatabaseOptions); // Note this is important for extending this class and maintaining API compatibility
234234
constructor(protected options: PowerSyncDatabaseOptions) {
235235
super();
236+
this.logger = options.logger ?? createPowerSyncLogger();
236237

237238
const { database, schema } = options;
238239

@@ -250,8 +251,6 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
250251
throw new Error('The provided `database` option is invalid.');
251252
}
252253

253-
this.logger = options.logger ?? createPowerSyncLogger({ prefix: `PowerSyncDatabase[${this._database.name}]` });
254-
255254
this.bucketStorageAdapter = this.generateBucketStorageAdapter();
256255
this.closed = false;
257256
this.currentStatus = new SyncStatus({});

packages/web/src/worker/db/MultiDatabaseServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class MultiDatabaseServer {
2222
async handleConnection(options: WorkerDBOpenerOptions): Promise<ClientConnectionView> {
2323
const logger: PowerSyncLogger = {
2424
log: (record) => {
25-
if (record.level >= options.logLevel) logger.log(record);
25+
if (record.level >= options.logLevel) this.logger.log(record);
2626
}
2727
};
2828

packages/web/tests/encryption.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { v4 as uuid } from 'uuid';
99
import { describe, expect, it } from 'vitest';
1010
import { TEST_SCHEMA } from './utils/test-schema.js';
11-
import { defaultLoggerConfig } from './utils/testDb.js';
11+
import { defaultLoggerConfig } from './utils/logger.js';
1212

1313
describe('Encryption Tests', { sequential: true }, () => {
1414
it('IDBBatchAtomicVFS encryption', async () => {

packages/web/tests/main.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { PowerSyncDatabase, WASQLiteOpenFactory, WASQLiteVFS } from '@powersync/
22
import { v4 as uuid } from 'uuid';
33
import { describe, expect, it } from 'vitest';
44
import { TEST_SCHEMA, TestDatabase } from './utils/test-schema.js';
5-
import { defaultLoggerConfig, generateTestDb } from './utils/testDb.js';
5+
import { generateTestDb } from './utils/testDb.js';
6+
import { defaultLoggerConfig } from './utils/logger.js';
67
// TODO import tests from a common package
78

89
describe(

packages/web/tests/multiple_instances.test.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
createPowerSyncLogger,
44
DBAdapterDefaultMixin,
55
LogLevels,
6+
LogRecord,
67
PowerSyncLogger
78
} from '@powersync/common';
89
import * as Comlink from 'comlink';
@@ -46,10 +47,10 @@ describe('Multiple Instances', { sequential: true }, () => {
4647
'should broadcast logs from shared sync worker',
4748
{ timeout: 10_000 },
4849
async ({ context: { openDatabase, mockService } }) => {
49-
const logLines: string[] = [];
50+
const logLines: LogRecord[] = [];
5051
const logger: PowerSyncLogger = {
51-
log({ message }) {
52-
logLines.push(message);
52+
log(msg) {
53+
logLines.push(msg);
5354
}
5455
};
5556

@@ -85,16 +86,22 @@ describe('Multiple Instances', { sequential: true }, () => {
8586

8687
// Asserting that powersync_control logs exists verifies that some connection attempt was made.
8788
await vi.waitFor(
88-
() => expect(logLines).toEqual(expect.arrayContaining([expect.stringContaining('powersync_control')])),
89+
() =>
90+
expect(logLines.map((l) => l.message)).toEqual(
91+
expect.arrayContaining([expect.stringContaining('powersync_control')])
92+
),
8993
{
9094
timeout: 2000
9195
}
9296
);
9397

9498
// The connection should fail with an error
95-
await vi.waitFor(() => expect(logLines).toEqual(expect.arrayContaining([expect.any(Error)])), {
96-
timeout: 2000
97-
});
99+
await vi.waitFor(
100+
() => expect(logLines.map((l) => l.error)).toEqual(expect.arrayContaining([expect.any(Error)])),
101+
{
102+
timeout: 2000
103+
}
104+
);
98105
}
99106
);
100107

packages/web/tests/open.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
1111
import { TEST_SCHEMA } from './utils/test-schema.js';
1212
import { MultiDatabaseServer } from '../src/worker/db/MultiDatabaseServer.js';
1313
import { DatabaseClient } from '../src/db/adapters/wa-sqlite/DatabaseClient.js';
14-
import { defaultLoggerConfig } from './utils/testDb.js';
14+
import { defaultLoggerConfig } from './utils/logger.js';
1515

1616
const testId = '2290de4f-0488-4e50-abed-f8e8eb1d0b42';
1717

packages/web/tests/src/db/write_ahead_log_opfs.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { expect, test } from 'vitest';
2-
import { defaultLoggerConfig, generateTestDb } from '../../utils/testDb.js';
2+
import { generateTestDb } from '../../utils/testDb.js';
33
import { WASQLiteOpenFactory, WASQLiteVFS } from '@powersync/web';
44
import { TEST_SCHEMA } from '../../utils/test-schema.js';
5+
import { defaultLoggerConfig } from '../../utils/logger.js';
56

67
test('supports concurrent reads', async () => {
78
const db = generateTestDb({

packages/web/tests/stream.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { describe, expect, it, onTestFinished, vi } from 'vitest';
1414
import { TestConnector } from './utils/MockStreamOpenFactory.js';
1515
import { ConnectedDatabaseUtils, generateConnectedDatabase } from './utils/generateConnectedDatabase.js';
1616
import { BucketChecksum } from '@powersync/common/internal/sync_protocol';
17-
import { defaultLoggerConfig } from './utils/testDb.js';
17+
import { defaultLoggerConfig } from './utils/logger.js';
1818

1919
const UPLOAD_TIMEOUT_MS = 3000;
2020

packages/web/tests/triggers.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { DiffTriggerOperation } from '@powersync/common';
22
import { WASQLiteOpenFactory, WASQLiteVFS } from '@powersync/web';
33
import { describe, expect, it, onTestFinished, vi } from 'vitest';
44
import { TEST_SCHEMA } from './utils/test-schema.js';
5-
import { defaultLoggerConfig, generateTestDb } from './utils/testDb.js';
5+
import { generateTestDb } from './utils/testDb.js';
6+
import { defaultLoggerConfig } from './utils/logger.js';
67

78
// Shared helper to spin up an iframe that creates a persisted trigger table
89
const createTriggerInIframe = () => {

packages/web/tests/uploads.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function describeCrudUploadTests(getDatabaseOptions: () => WebPowerSyncDatabaseO
7979

8080
await vi.waitFor(
8181
() => {
82-
expect(logLines).contains(expect.stringContaining(PARTIAL_WARNING));
82+
expect(logLines).toEqual(expect.arrayContaining([expect.stringContaining(PARTIAL_WARNING)]));
8383
},
8484
{
8585
timeout: 500,
@@ -143,7 +143,7 @@ function describeCrudUploadTests(getDatabaseOptions: () => WebPowerSyncDatabaseO
143143
}
144144
);
145145

146-
expect(logLines).not.contains(expect.stringContaining(PARTIAL_WARNING));
146+
expect(logLines).not.toEqual(expect.arrayContaining([expect.stringContaining(PARTIAL_WARNING)]));
147147
});
148148
};
149149
}

0 commit comments

Comments
 (0)