Skip to content

Commit

Permalink
Clean up bundled test (#1283)
Browse files Browse the repository at this point in the history
* add notice about generated code to `test_bundle.dart`

* tiny improvement to the "responsibilities" comment

* make surrounding comments more clear

* move the big comment to the top

* fix lint warning

* fix `configure()` not being called on the start of every test

* lock Flutter 3.10.0 because 3.10.1 formats code differently (most likely a bug)
  • Loading branch information
bartekpacia authored May 18, 2023
1 parent 28828e9 commit 549a4a0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/patrol-prepare.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ jobs:
strategy:
fail-fast: false
matrix:
flutter-version: ['3.3.x', '3.7.x', '3.10.x']
flutter-version: ['3.3.x', '3.7.x', '3.10.0']

defaults:
run:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/patrol_cli-prepare.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
flutter-version: ['3.3.x', '3.7.x', '3.10.x']
flutter-version: ['3.3.x', '3.7.x', '3.10.0']

defaults:
run:
Expand Down
17 changes: 8 additions & 9 deletions packages/patrol/lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,22 @@ void patrolTest(
tags: tags,
(widgetTester) async {
if (patrolBinding != null) {
// If Patrol's native automation feature is enabled, then the test will
// only execute if the native side requests it.

// FIXME: Too strict assumption
// If Patrol's native automation feature is enabled, then this test will
// be executed only if the native side requested it to be executed.
// Otherwise, it returns early.
//
// The assumption here is that this test doesn't have any extra parent
// groups. Every Dart test suite has an implict, unnamed, top-level
// group. An additional group is present in the bundled_test.dart, and
// its name is equal to the path to the Dart test file in the
// integration_test directory.
//
// In other words, the developer cannot use `group()` in the tests.
//
// Example: if this function is called from the Dart test file named
// "example_test.dart", and that file is located in the
// "integration_test/examples" directory, we assume that the name of the
// immediate parent group is "examples/example_test.dart".
//
// It's good enough for now.
// immediate parent group is "examples.example_test".

final parentGroupName = Invoker.current!.liveTest.groups.last.name;
final requestedToExecute = await patrolBinding.patrolAppService
Expand All @@ -107,9 +106,9 @@ void patrolTest(
if (!requestedToExecute) {
return;
}
}

// await nativeAutomator?.configure(); // TODO: Move to bundled_test.dart or add again
await nativeAutomator?.configure();
}

final patrolTester = PatrolTester(
tester: widgetTester,
Expand Down
32 changes: 16 additions & 16 deletions packages/patrol_cli/lib/src/test_bundler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class TestBundler {
}

final contents = '''
// ignore_for_file: invalid_use_of_internal_member,
// depend_on_referenced_packages, directives_ordering
// GENERATED CODE - DO NOT MODIFY BY HAND AND DO NOT COMMIT TO VERSION CONTROL
// ignore_for_file: type=lint, invalid_use_of_internal_member
import 'dart:async';
Expand All @@ -25,32 +25,30 @@ import 'package:patrol/patrol.dart';
import 'package:patrol/src/native/contracts/contracts.pbgrpc.dart';
import 'package:test_api/src/backend/invoker.dart';
// START: GENERATED CODE
// START: GENERATED TEST IMPORTS
${generateImports(testFilePaths)}
// END: GENERATED CODE
// END: GENERATED TEST IMPORTS
Future<void> main() async {
final nativeAutomator = NativeAutomator(config: NativeAutomatorConfig());
final binding = PatrolBinding.ensureInitialized();
// This is the entrypoint of the bundled Dart test.
//
// Its responsibilies are:
// * Run a special Dart test that explores the hierarchy of groups and tests,
// so it can...
// * ... host a service that the native side of Patrol uses to get the list
// of Dart tests, and to request execution of a specific Dart test.
// * Running a special Dart test that runs before all the other tests and
// explores the hierarchy of groups and tests.
// * Hosting a PatrolAppService, which the native side of Patrol uses to get
// the Dart tests, and to request execution of a specific Dart test.
//
// When running on Android, the Android Test Orchestrator, before running the
// tests, makes an initial run to gather the tests that it will later run. The
// native side of Patrol (specifically: PatrolJUnitRunner class) is hooked
// into the Android Test Orchestrator lifecycle and knows when that initial
// run happens. When it does, PatrolJUnitRunner makes an RPC call to
// PatrolAppService and asks it for the list of Dart tests.
// PatrolAppService and asks it for Dart tests.
//
// When running on iOS, the native side of Patrol (specifically: the
// PATROL_INTEGRATION_TEST_IOS_RUNNER macro) makes an RPC call to
// PatrolAppSevice and asks it for the list of Dart tests.
// PATROL_INTEGRATION_TEST_IOS_RUNNER macro) makes an initial run to gather
// the tests that it will later run (same as the Android). During that initial
// run, it makes an RPC call to PatrolAppSevice and asks it for Dart tests.
//
// Once the native runner has the list of Dart tests, it dynamically creates
// native test cases from them. On Android, this is done using the
Expand All @@ -65,6 +63,8 @@ Future<void> main() async {
// test (out of which they had been created) and wait for it to complete.
// The result of running the Dart test is the result of the native test case.
final nativeAutomator = NativeAutomator(config: NativeAutomatorConfig());
final binding = PatrolBinding.ensureInitialized();
final testExplorationCompleter = Completer<DartTestGroup>();
// A special test to expore the hierarchy of groups and tests. This is a
Expand All @@ -78,9 +78,9 @@ Future<void> main() async {
testExplorationCompleter.complete(dartTestGroup);
});
// START: GENERATED CODE
// START: GENERATED TEST GROUPS
${generateGroupsCode(testFilePaths).split('\n').map((e) => ' $e').join('\n')}
// END: GENERATED CODE
// END: GENERATED TEST GROUPS
final dartTestGroup = await testExplorationCompleter.future;
final appService = PatrolAppService(topLevelDartTestGroup: dartTestGroup);
Expand Down

0 comments on commit 549a4a0

Please sign in to comment.