import 'dart:ffi'; import 'dart:io'; import 'package:drift/drift.dart'; import 'package:drift/native.dart'; import 'package:sqlite3/open.dart'; import 'package:zenxercise/src/database/database.dart'; /// An in-memory database for tests. On Windows hosts the sqlite3 library comes /// from ZENXERCISE_SQLITE_DLL if set, otherwise from the system's winsqlite3.dll. AppDatabase testDatabase() { if (Platform.isWindows) { open.overrideFor(OperatingSystem.windows, () { final custom = Platform.environment['ZENXERCISE_SQLITE_DLL']; return DynamicLibrary.open(custom ?? 'winsqlite3.dll'); }); } driftRuntimeOptions.dontWarnAboutMultipleDatabases = true; // Synchronous stream teardown keeps widget tests from hanging on pending timers. return AppDatabase(DatabaseConnection(NativeDatabase.memory(), closeStreamsSynchronously: true)); }