From 02e248734d9ea05db5eb5777712468fd74e7ecbb Mon Sep 17 00:00:00 2001 From: Mugi Khan Date: Tue, 18 Jun 2024 11:23:21 +0200 Subject: [PATCH 1/3] Override default macOS sqlite db for tests --- packages/powersync/lib/src/open_factory.dart | 3 +++ packages/powersync/test/util.dart | 3 +++ 2 files changed, 6 insertions(+) diff --git a/packages/powersync/lib/src/open_factory.dart b/packages/powersync/lib/src/open_factory.dart index a9165e50..37ce505f 100644 --- a/packages/powersync/lib/src/open_factory.dart +++ b/packages/powersync/lib/src/open_factory.dart @@ -82,6 +82,9 @@ class PowerSyncOpenFactory extends DefaultSqliteOpenFactory { var powersyncLib = Platform.isIOS || Platform.isMacOS ? DynamicLibrary.process() : DynamicLibrary.open(getLibraryForPlatform()); + if (Platform.environment.containsKey('FLUTTER_TEST')) { + powersyncLib = DynamicLibrary.open(getLibraryForPlatform()); + } sqlite.sqlite3.ensureExtensionLoaded( SqliteExtension.inLibrary(powersyncLib, 'sqlite3_powersync_init')); } diff --git a/packages/powersync/test/util.dart b/packages/powersync/test/util.dart index ff16b6e6..3582a555 100644 --- a/packages/powersync/test/util.dart +++ b/packages/powersync/test/util.dart @@ -35,6 +35,9 @@ class TestOpenFactory extends PowerSyncOpenFactory { sqlite_open.open.overrideFor(sqlite_open.OperatingSystem.linux, () { return DynamicLibrary.open('libsqlite3.so.0'); }); + sqlite_open.open.overrideFor(sqlite_open.OperatingSystem.macOS, () { + return DynamicLibrary.open('libsqlite3.dylib'); + }); return super.open(options); } From cda0aec1116d1100133f23206cec2c81b87e3693 Mon Sep 17 00:00:00 2001 From: Mugi Khan Date: Tue, 18 Jun 2024 14:06:13 +0200 Subject: [PATCH 2/3] Update to use flutter test rather than dart test --- melos.yaml | 2 +- packages/powersync/lib/src/open_factory.dart | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/melos.yaml b/melos.yaml index 576d92cd..aa282e5f 100644 --- a/melos.yaml +++ b/melos.yaml @@ -31,7 +31,7 @@ scripts: test: description: Run tests in a specific package. - run: dart test + run: flutter test exec: concurrency: 1 packageFilters: diff --git a/packages/powersync/lib/src/open_factory.dart b/packages/powersync/lib/src/open_factory.dart index 37ce505f..18b190a7 100644 --- a/packages/powersync/lib/src/open_factory.dart +++ b/packages/powersync/lib/src/open_factory.dart @@ -79,16 +79,20 @@ class PowerSyncOpenFactory extends DefaultSqliteOpenFactory { } void enableExtension() { - var powersyncLib = Platform.isIOS || Platform.isMacOS - ? DynamicLibrary.process() - : DynamicLibrary.open(getLibraryForPlatform()); - if (Platform.environment.containsKey('FLUTTER_TEST')) { - powersyncLib = DynamicLibrary.open(getLibraryForPlatform()); - } + var powersyncLib = _getDynamicLibraryForPlatform(); sqlite.sqlite3.ensureExtensionLoaded( SqliteExtension.inLibrary(powersyncLib, 'sqlite3_powersync_init')); } + DynamicLibrary _getDynamicLibraryForPlatform() { + if (Platform.environment.containsKey('FLUTTER_TEST')) { + return DynamicLibrary.open(getLibraryForPlatform()); + } + return (Platform.isIOS || Platform.isMacOS) + ? DynamicLibrary.process() + : DynamicLibrary.open(getLibraryForPlatform()); + } + void setupFunctions(sqlite.Database db) { db.createFunction( functionName: 'powersync_sleep', From aee72aefa10845534aff21def854d1283d7af92c Mon Sep 17 00:00:00 2001 From: Mugi Khan Date: Tue, 18 Jun 2024 14:07:58 +0200 Subject: [PATCH 3/3] Added documentation --- packages/powersync/lib/src/open_factory.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/powersync/lib/src/open_factory.dart b/packages/powersync/lib/src/open_factory.dart index 18b190a7..12b22c28 100644 --- a/packages/powersync/lib/src/open_factory.dart +++ b/packages/powersync/lib/src/open_factory.dart @@ -84,7 +84,9 @@ class PowerSyncOpenFactory extends DefaultSqliteOpenFactory { SqliteExtension.inLibrary(powersyncLib, 'sqlite3_powersync_init')); } + /// Returns the dynamic library for the current platform. DynamicLibrary _getDynamicLibraryForPlatform() { + /// When running tests, we need to load the library for all platforms. if (Platform.environment.containsKey('FLUTTER_TEST')) { return DynamicLibrary.open(getLibraryForPlatform()); }