Skip to content

Commit

Permalink
use test name in logs for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
stevensJourney committed Oct 30, 2024
1 parent 0d557cb commit b771349
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/powersync/test/utils/abstract_test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ final testLogger = _makeTestLogger();

final testWarningLogger = _makeTestLogger(level: Level.WARNING);

Logger _makeTestLogger({Level level = Level.ALL}) {
final logger = Logger.detached('PowerSync Tests');
Logger _makeTestLogger({Level level = Level.ALL, String? name}) {
final logger = Logger.detached(name ?? 'PowerSync Tests');
logger.level = level;
logger.onRecord.listen((record) {
print(
Expand All @@ -53,11 +53,11 @@ Logger _makeTestLogger({Level level = Level.ALL}) {
}

abstract class AbstractTestUtils {
String get _testName => Invoker.current!.liveTest.test.name;

String dbPath() {
final test = Invoker.current!.liveTest;
var testName = test.test.name;
var testShortName =
testName.replaceAll(RegExp(r'[\s\./]'), '_').toLowerCase();
_testName.replaceAll(RegExp(r'[\s\./]'), '_').toLowerCase();
var dbName = "test-db/$testShortName.db";
return dbName;
}
Expand All @@ -74,7 +74,8 @@ abstract class AbstractTestUtils {
Future<PowerSyncDatabase> setupPowerSync(
{String? path, Schema? schema, Logger? logger}) async {
final db = PowerSyncDatabase.withFactory(await testFactory(path: path),
schema: schema ?? defaultSchema, logger: logger ?? testLogger);
schema: schema ?? defaultSchema,
logger: logger ?? _makeTestLogger(name: _testName));
await db.initialize();
return db;
}
Expand Down

0 comments on commit b771349

Please sign in to comment.