main function

void main(
  1. dynamic testMain
)

Implementation

void main(testMain) {
  enableFlutterDriverExtension(handler: (data) async {
    if (_pendingEvents.isEmpty) return '';
    return json.encode(_pendingEvents.removeAt(0));
  });

  runZonedGuarded(() {
    flutter_test.setUpAll(() {
      Invoker.current!.liveTest.groups.forEach((group) {
        if (_testingGroups[group] == null) {
          _testingGroups[group] = {
            kId: (_testingGroups.length + 1).toString(),
            kName: group.name,
          };
        }
        group.entries.forEach((entry) {
          _iterateGroupEntries(entry, group);
        });
      });
      _pendingEvents.add({
        kAction: EventActionSuiteStart,
        kData: {
          kTests: _testingTests.values.toList(),
          kGroups: _testingGroups.values.toList(),
          kWeb: kIsWeb,
        }
      });
    });

    flutter_test.tearDownAll(() => _pendingEvents.add({
          kAction: EventActionSuiteComplete,
          kData: {},
        }));

    flutter_test.setUp(() {
      Map<String, String?> currentTest =
          _testingTests[Invoker.current!.liveTest.test]!;
      _currentTestId = currentTest[kId]!;
      _pendingEvents.add({
        kAction: EventActionTestStart,
        kData: {
          kId: _currentTestId,
        }
      });
    });

    flutter_test.tearDown(() {
      final currentLiveTest = Invoker.current!.liveTest;
      Map eventData = {
        kId: _currentTestId.toString(),
        'result': currentLiveTest.state.result.toString(),
        kPassed: currentLiveTest.state.result.isPassing,
      };
      if (eventData[kPassed] == false) {
        AsyncError errorForTest =
            currentLiveTest.errors[currentLiveTest.errors.length - 1];
        eventData[kError] = errorForTest.error.toString();
        eventData[kStacktrace] = errorForTest.stackTrace.toString();
      }
      _pendingEvents.add({
        kAction: EventActionTestComplete,
        kData: eventData,
      });
    });

    testMain();
  }, (e, stacktrace) {
    _pendingEvents.add({
      kAction: EventActionError,
      kData: {
        kError: e.toString(),
        kStacktrace: stacktrace.toString(),
        kWeb: kIsWeb,
      },
    });
    _pendingEvents.add({
      kAction: EventActionSuiteComplete,
      kData: {},
    });
  }, zoneSpecification: _zoneSpecification);
}