@powersync/service-module-mongodb 0.13.2 → 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.
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) {