// Copyright 2014 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import 'dart:async'; import 'dart:convert'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/common.dart'; import 'package:integration_test/integration_test.dart'; import 'package:integration_test/src/constants.dart'; const String failureExcerpt = 'Expected: '; dynamic isSuccess(String methodName) => isA() .having((Success s) => s.methodName, 'methodName', methodName); dynamic isFailure(String methodName) => isA() .having((Failure e) => e.methodName, 'methodName', methodName) .having((Failure e) => e.error.toString(), 'error', contains(failureExcerpt)); Future> runAndCollectResults( FutureOr Function() testMain, ) async { final _TestReporter reporter = _TestReporter(); await run(testMain, reporter: reporter); return reporter.results; } class _TestReporter implements Reporter { final Completer> _resultsCompleter = Completer>(); Future> get results => _resultsCompleter.future; @override Future report(List results) async => _resultsCompleter.complete(results); } String testResultsToJson(Map results) { return jsonEncode({ for (TestResult result in results.values) result.methodName: result is Failure ? result : success }); }