Skip to content

Commit 1903747

Browse files
authored
Override default macOS SQLite for tests (#99)
* Override default macOS sqlite db for tests * Update to use flutter test rather than dart test * Added documentation
1 parent 4739f71 commit 1903747

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

melos.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ scripts:
3131

3232
test:
3333
description: Run tests in a specific package.
34-
run: dart test
34+
run: flutter test
3535
exec:
3636
concurrency: 1
3737
packageFilters:

packages/powersync/lib/src/open_factory.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,22 @@ class PowerSyncOpenFactory extends DefaultSqliteOpenFactory {
7979
}
8080

8181
void enableExtension() {
82-
var powersyncLib = Platform.isIOS || Platform.isMacOS
83-
? DynamicLibrary.process()
84-
: DynamicLibrary.open(getLibraryForPlatform());
82+
var powersyncLib = _getDynamicLibraryForPlatform();
8583
sqlite.sqlite3.ensureExtensionLoaded(
8684
SqliteExtension.inLibrary(powersyncLib, 'sqlite3_powersync_init'));
8785
}
8886

87+
/// Returns the dynamic library for the current platform.
88+
DynamicLibrary _getDynamicLibraryForPlatform() {
89+
/// When running tests, we need to load the library for all platforms.
90+
if (Platform.environment.containsKey('FLUTTER_TEST')) {
91+
return DynamicLibrary.open(getLibraryForPlatform());
92+
}
93+
return (Platform.isIOS || Platform.isMacOS)
94+
? DynamicLibrary.process()
95+
: DynamicLibrary.open(getLibraryForPlatform());
96+
}
97+
8998
void setupFunctions(sqlite.Database db) {
9099
db.createFunction(
91100
functionName: 'powersync_sleep',

packages/powersync/test/util.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class TestOpenFactory extends PowerSyncOpenFactory {
3535
sqlite_open.open.overrideFor(sqlite_open.OperatingSystem.linux, () {
3636
return DynamicLibrary.open('libsqlite3.so.0');
3737
});
38+
sqlite_open.open.overrideFor(sqlite_open.OperatingSystem.macOS, () {
39+
return DynamicLibrary.open('libsqlite3.dylib');
40+
});
3841
return super.open(options);
3942
}
4043

0 commit comments

Comments
 (0)