From 1359386f34131bbb7191c63fabd438b90c24e8d6 Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Thu, 21 Sep 2023 15:14:25 +0200 Subject: [PATCH] PatrolBinding: improve and standarize logging --- packages/patrol/lib/src/binding.dart | 37 ++++++++++--------- packages/patrol/lib/src/extensions.dart | 3 ++ .../lib/src/native/patrol_app_service.dart | 5 +-- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/packages/patrol/lib/src/binding.dart b/packages/patrol/lib/src/binding.dart index 1c1988b86..881a7cd4f 100644 --- a/packages/patrol/lib/src/binding.dart +++ b/packages/patrol/lib/src/binding.dart @@ -44,6 +44,7 @@ class PatrolBinding extends IntegrationTestWidgetsFlutterBinding { /// /// You most likely don't want to call it yourself. PatrolBinding() { + logger('created'); final oldTestExceptionReporter = reportTestException; reportTestException = (details, testDescription) { final currentDartTest = _currentDartTest; @@ -60,7 +61,13 @@ class PatrolBinding extends IntegrationTestWidgetsFlutterBinding { return; } + if (Invoker.current!.currentTestName == 'patrol_test_explorer') { + // Ignore the fake test. + return; + } + _currentDartTest = Invoker.current!.fullCurrentTestName(); + logger('setUp(): called with current Dart test = "$_currentDartTest"'); }); tearDown(() async { @@ -69,29 +76,25 @@ class PatrolBinding extends IntegrationTestWidgetsFlutterBinding { return; } - final testName = Invoker.current!.liveTest.individualName; - final isTestExplorer = testName == 'patrol_test_explorer'; - if (isTestExplorer) { + if (Invoker.current!.currentTestName == 'patrol_test_explorer') { + // Ignore the fake test. return; - } else { - logger( - 'tearDown(): count: ${_testResults.length}, results: $_testResults', - ); } - final invoker = Invoker.current!; - - final nameOfRequestedTest = await patrolAppService.testExecutionRequested; + logger('tearDown(): called with current Dart test = "$_currentDartTest"'); + logger('tearDown(): there are ${_testResults.length} test results:'); + _testResults.forEach((dartTestName, result) { + logger('tearDown(): test "$dartTestName": "$result"'); + }); - if (nameOfRequestedTest == _currentDartTest) { + final requestedDartTest = await patrolAppService.testExecutionRequested; + if (requestedDartTest == _currentDartTest) { logger( - 'finished test $_currentDartTest. Will report its status back to the native side', + 'tearDown(): finished test "$_currentDartTest". Will report its status back to the native side', ); - final passed = invoker.liveTest.state.result.isPassing; - logger( - 'tearDown(): test "$testName" in group "$_currentDartTest", passed: $passed', - ); + final passed = Invoker.current!.liveTest.state.result.isPassing; + logger('tearDown(): test "$_currentDartTest", passed: $passed'); await patrolAppService.markDartTestAsCompleted( dartFileName: _currentDartTest!, passed: passed, @@ -101,7 +104,7 @@ class PatrolBinding extends IntegrationTestWidgetsFlutterBinding { ); } else { logger( - 'finished test $_currentDartTest, but it was not requested, so its status will not be reported back to the native side', + 'tearDown(): finished test "$_currentDartTest", but it was not requested, so its status will not be reported back to the native side', ); } }); diff --git a/packages/patrol/lib/src/extensions.dart b/packages/patrol/lib/src/extensions.dart index 0f241bec9..701b7b959 100644 --- a/packages/patrol/lib/src/extensions.dart +++ b/packages/patrol/lib/src/extensions.dart @@ -13,4 +13,7 @@ extension InvokerX on Invoker { return '$parentGroupName $testName'; } + + /// Returns the name of the current test only. No group prefixes. + String get currentTestName => liveTest.individualName; } diff --git a/packages/patrol/lib/src/native/patrol_app_service.dart b/packages/patrol/lib/src/native/patrol_app_service.dart index a4aa6699e..f67806ff7 100644 --- a/packages/patrol/lib/src/native/patrol_app_service.dart +++ b/packages/patrol/lib/src/native/patrol_app_service.dart @@ -3,12 +3,11 @@ // TODO: Use a logger instead of print import 'dart:async'; -import 'dart:io'; +import 'dart:io' as io; import 'package:patrol/src/common.dart'; import 'package:patrol/src/native/contracts/contracts.dart'; import 'package:patrol/src/native/contracts/patrol_app_service_server.dart'; - import 'package:shelf/shelf.dart' as shelf; import 'package:shelf/shelf_io.dart' as shelf_io; @@ -30,7 +29,7 @@ Future runAppService(PatrolAppService service) async { final server = await shelf_io.serve( pipeline, - InternetAddress.anyIPv4, + io.InternetAddress.anyIPv4, _port, poweredByHeader: null, );