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 a9165e50..12b22c28 100644 --- a/packages/powersync/lib/src/open_factory.dart +++ b/packages/powersync/lib/src/open_factory.dart @@ -79,13 +79,22 @@ class PowerSyncOpenFactory extends DefaultSqliteOpenFactory { } void enableExtension() { - var powersyncLib = Platform.isIOS || Platform.isMacOS - ? DynamicLibrary.process() - : DynamicLibrary.open(getLibraryForPlatform()); + var powersyncLib = _getDynamicLibraryForPlatform(); sqlite.sqlite3.ensureExtensionLoaded( 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()); + } + return (Platform.isIOS || Platform.isMacOS) + ? DynamicLibrary.process() + : DynamicLibrary.open(getLibraryForPlatform()); + } + void setupFunctions(sqlite.Database db) { db.createFunction( functionName: 'powersync_sleep', 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); }