@powersync/service-module-mongodb 0.13.1 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,19 +2,21 @@ import { setTimeout } from 'node:timers/promises';
2
2
  import { describe, expect, test } from 'vitest';
3
3
 
4
4
  import { mongo } from '@powersync/lib-service-mongodb';
5
- import { storage } from '@powersync/service-core';
6
-
7
5
  import { ChangeStreamTestContext, setSnapshotHistorySeconds } from './change_stream_utils.js';
8
6
  import { env } from './env.js';
9
- import { describeWithStorage } from './util.js';
7
+ import { describeWithStorage, StorageVersionTestContext } from './util.js';
10
8
 
11
9
  describe.runIf(env.CI || env.SLOW_TESTS)('change stream slow tests', { timeout: 60_000 }, function () {
12
10
  describeWithStorage({}, defineSlowTests);
13
11
  });
14
12
 
15
- function defineSlowTests(factory: storage.TestStorageFactory) {
13
+ function defineSlowTests({ factory, storageVersion }: StorageVersionTestContext) {
14
+ const openContext = (options?: Parameters<typeof ChangeStreamTestContext.open>[1]) => {
15
+ return ChangeStreamTestContext.open(factory, { ...options, storageVersion });
16
+ };
17
+
16
18
  test('replicating snapshot with lots of data', async () => {
17
- await using context = await ChangeStreamTestContext.open(factory);
19
+ await using context = await openContext();
18
20
  // Test with low minSnapshotHistoryWindowInSeconds, to trigger:
19
21
  // > Read timestamp .. is older than the oldest available timestamp.
20
22
  // This happened when we had {snapshot: true} in the initial
@@ -52,7 +54,7 @@ bucket_definitions:
52
54
  // changestream), we may miss updates, which this test would
53
55
  // hopefully catch.
54
56
 
55
- await using context = await ChangeStreamTestContext.open(factory);
57
+ await using context = await openContext();
56
58
  const { db } = context;
57
59
  await context.updateSyncRules(`
58
60
  bucket_definitions:
package/test/src/util.ts CHANGED
@@ -3,9 +3,14 @@ import * as mongo_storage from '@powersync/service-module-mongodb-storage';
3
3
  import * as postgres_storage from '@powersync/service-module-postgres-storage';
4
4
 
5
5
  import * as types from '@module/types/types.js';
6
- import { env } from './env.js';
7
- import { BSON_DESERIALIZE_DATA_OPTIONS, TestStorageFactory } from '@powersync/service-core';
6
+ import {
7
+ BSON_DESERIALIZE_DATA_OPTIONS,
8
+ CURRENT_STORAGE_VERSION,
9
+ LEGACY_STORAGE_VERSION,
10
+ TestStorageFactory
11
+ } from '@powersync/service-core';
8
12
  import { describe, TestOptions } from 'vitest';
13
+ import { env } from './env.js';
9
14
 
10
15
  export const TEST_URI = env.MONGO_TEST_DATA_URL;
11
16
 
@@ -23,14 +28,34 @@ export const INITIALIZED_POSTGRES_STORAGE_FACTORY = postgres_storage.test_utils.
23
28
  url: env.PG_STORAGE_TEST_URL
24
29
  });
25
30
 
26
- export function describeWithStorage(options: TestOptions, fn: (factory: TestStorageFactory) => void) {
27
- describe.skipIf(!env.TEST_MONGO_STORAGE)(`mongodb storage`, options, function () {
28
- fn(INITIALIZED_MONGO_STORAGE_FACTORY);
29
- });
31
+ const TEST_STORAGE_VERSIONS = [LEGACY_STORAGE_VERSION, CURRENT_STORAGE_VERSION];
30
32
 
31
- describe.skipIf(!env.TEST_POSTGRES_STORAGE)(`postgres storage`, options, function () {
32
- fn(INITIALIZED_POSTGRES_STORAGE_FACTORY);
33
- });
33
+ export interface StorageVersionTestContext {
34
+ factory: TestStorageFactory;
35
+ storageVersion: number;
36
+ }
37
+
38
+ export function describeWithStorage(options: TestOptions, fn: (context: StorageVersionTestContext) => void) {
39
+ const describeFactory = (storageName: string, factory: TestStorageFactory) => {
40
+ describe(`${storageName} storage`, options, function () {
41
+ for (const storageVersion of TEST_STORAGE_VERSIONS) {
42
+ describe(`storage v${storageVersion}`, function () {
43
+ fn({
44
+ factory,
45
+ storageVersion
46
+ });
47
+ });
48
+ }
49
+ });
50
+ };
51
+
52
+ if (env.TEST_MONGO_STORAGE) {
53
+ describeFactory('mongodb', INITIALIZED_MONGO_STORAGE_FACTORY);
54
+ }
55
+
56
+ if (env.TEST_POSTGRES_STORAGE) {
57
+ describeFactory('postgres', INITIALIZED_POSTGRES_STORAGE_FACTORY);
58
+ }
34
59
  }
35
60
 
36
61
  export async function clearTestDb(db: mongo.Db) {
@@ -1,17 +1,13 @@
1
1
  {
2
- "extends": "../../../tsconfig.base.json",
2
+ "extends": "../../../tsconfig.tests.json",
3
3
  "compilerOptions": {
4
- "rootDir": "src",
5
4
  "baseUrl": "./",
6
- "noEmit": true,
7
- "esModuleInterop": true,
8
- "skipLibCheck": true,
9
- "sourceMap": true,
10
5
  "paths": {
11
6
  "@/*": ["../../../packages/service-core/src/*"],
12
7
  "@module/*": ["../src/*"],
13
8
  "@core-tests/*": ["../../../packages/service-core/test/src/*"]
14
- }
9
+ },
10
+ "rootDir": "src"
15
11
  },
16
12
  "include": ["src"],
17
13
  "references": [