runScenario method

  1. @protected
void runScenario(
  1. String name,
  2. Iterable<String>? tags,
  3. Future<void> runTest(
    1. TestDependencies dependencies
    ), {
  4. Future<void> onBefore()?,
  5. Future<void> onAfter()?,
})

Implementation

@protected
void runScenario(
  String name,
  Iterable<String>? tags,
  Future<void> Function(TestDependencies dependencies) runTest, {
  Future<void> Function()? onBefore,
  Future<void> Function()? onAfter,
}) {
  if (_evaluateTagFilterExpression(configuration.tagExpression, tags)) {
    testWidgets(
      name,
      (WidgetTester tester) async {
        if (onBefore != null) {
          await onBefore();
        }

        final debugInformation = RunnableDebugInformation('', 0, name);
        final scenarioTags =
            (tags ?? Iterable<Tag>.empty()).map((t) => Tag(t.toString(), 0));
        final dependencies = await createTestDependencies(
          configuration,
          tester,
        );

        try {
          await hook.onBeforeScenario(
            configuration,
            name,
            scenarioTags,
          );

          await startApp(
            tester,
            dependencies.world,
          );

          await hook.onAfterScenarioWorldCreated(
            dependencies.world,
            name,
            scenarioTags,
          );

          await reporter.onScenarioStarted(
            StartedMessage(
              Target.scenario,
              name,
              debugInformation,
              scenarioTags,
            ),
          );

          await runTest(dependencies);
        } finally {
          await reporter.onScenarioFinished(
            ScenarioFinishedMessage(
              name,
              debugInformation,
              true,
            ),
          );

          await hook.onAfterScenario(
            configuration,
            name,
            scenarioTags,
          );

          if (onAfter != null) {
            await onAfter();
          }

          cleanupScenarioRun(dependencies);
        }
      },
      timeout: scenarioExecutionTimeout,
      semanticsEnabled: configuration is FlutterTestConfiguration
          ? (configuration as FlutterTestConfiguration).semanticsEnabled
          : true,
    );
  } else {
    _safeInvokeFuture(
      () async => reporter.message(
        'Ignoring scenario `$name` as tag expression `${configuration.tagExpression}` not satisfied',
        MessageLevel.info,
      ),
    );
  }
}