Skip to content

Commit

Permalink
test: logger is dummy by default in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Merrit committed Jan 18, 2023
1 parent bece195 commit f1b385d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
7 changes: 7 additions & 0 deletions lib/logs/logging_manager.dart
Expand Up @@ -26,6 +26,13 @@ class LoggingManager {
}

static Future<LoggingManager> initialize({required bool verbose}) async {
final testing = Platform.environment.containsKey('FLUTTER_TEST');
if (testing) {
// Set the logger to a dummy logger during unit tests.
log = Logger(level: Level.nothing);
return LoggingManager._(File(''));
}

final dataDir = await getApplicationSupportDirectory();
final logFile = File('${dataDir.path}${Platform.pathSeparator}log.txt');
if (await logFile.exists()) await logFile.delete();
Expand Down
12 changes: 2 additions & 10 deletions test/active_window/src/active_window_test.dart
@@ -1,5 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:logger/logger.dart';
import 'package:mocktail/mocktail.dart';
import 'package:nyrna/active_window/active_window.dart';
import 'package:nyrna/logs/logs.dart';
Expand All @@ -12,8 +11,6 @@ const kActiveWindowStorageArea = 'activeWindow';

class MockArgParser extends Mock implements ArgumentParser {}

class MockLoggingManager extends Mock implements LoggingManager {}

class MockNativePlatform extends Mock implements NativePlatform {}

class MockProcessRepository extends Mock implements ProcessRepository {}
Expand All @@ -33,22 +30,17 @@ const testWindow = Window(
);

void main() {
LoggingManager loggingManager = MockLoggingManager();

late NativePlatform nativePlatform;
late ProcessRepository processRepository;
late StorageRepository storageRepository;

late ActiveWindow activeWindow;

setUpAll(() {
setUpAll(() async {
argParser = MockArgParser();
when(() => argParser.minimize).thenReturn(null);

// Set the logger to a dummy logger.
log = Logger(level: Level.nothing);
LoggingManager.instance = loggingManager;
when(() => loggingManager.close()).thenReturn(null);
await LoggingManager.initialize(verbose: false);
});

setUp(() {
Expand Down

0 comments on commit f1b385d

Please sign in to comment.