Skip to content

Commit

Permalink
implement patrolSetUp() and patrolTearDown()
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Sep 21, 2023
1 parent 9f63eeb commit 877bdae
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/patrol/lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,44 @@ import 'custom_finders/patrol_integration_tester.dart';
/// Signature for callback to [patrolTest].
typedef PatrolTesterCallback = Future<void> Function(PatrolIntegrationTester $);

// PROBLEM: PatrolBinding.ensureInitialized() adds a setUp() and tearDown()
// PROBLEM: Reporting results back to the native side depends on tearDown()
// PROBLEM: What if an exception in thrown inside setUp or tearDown?

void patrolSetUp(Future<void> Function() body) {
setUp(() async {
final currentTest = Invoker.current!.fullCurrentTestName();

final requestedToExecute = await PatrolBinding.ensureInitialized()
.patrolAppService
.waitForExecutionRequest(currentTest);

// TODO: Determine if requestedTest is inside this setUps scope?
// Hipothesis: package:test cares about this automatically!

if (requestedToExecute) {
await body();
}
});
}

void patrolTearDown(Future<void> Function() body) {
tearDown(() async {
final currentTest = Invoker.current!.fullCurrentTestName();

final requestedToExecute = await PatrolBinding.ensureInitialized()
.patrolAppService
.waitForExecutionRequest(currentTest);

// TODO: Determine if requestedTest is inside this setUps scope?
// Hipothesis: package:test cares about this automatically!

if (requestedToExecute) {
await body();
}
});
}

/// Like [testWidgets], but with support for Patrol custom finders.
///
/// To customize the Patrol-specific configuration, set [config].
Expand Down

0 comments on commit 877bdae

Please sign in to comment.