Skip to content

Commit

Permalink
PatrolBinding: improve and standarize logging
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Sep 21, 2023
1 parent 561439b commit 1359386
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
37 changes: 20 additions & 17 deletions packages/patrol/lib/src/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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,
Expand All @@ -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',
);
}
});
Expand Down
3 changes: 3 additions & 0 deletions packages/patrol/lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 2 additions & 3 deletions packages/patrol/lib/src/native/patrol_app_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,7 +29,7 @@ Future<void> runAppService(PatrolAppService service) async {

final server = await shelf_io.serve(
pipeline,
InternetAddress.anyIPv4,
io.InternetAddress.anyIPv4,
_port,
poweredByHeader: null,
);
Expand Down

0 comments on commit 1359386

Please sign in to comment.