feat(reporters): added flutter driver reporter

chore(docs): updated readme and changelog
fix(world): added missing super class to flutter world dispose method
This commit is contained in:
Jon Samwell 2019-09-24 09:49:00 +10:00
parent 04d57facb3
commit a351866646
7 changed files with 47 additions and 2 deletions

View File

@ -1,3 +1,7 @@
## [1.1.3] - 24/09/2019
* Added Flutter driver reporter - the driver logs all messages (even non-error ones) to stderr and will cause the process to be marked as failed by a CI server becuase of this. So this reporter redirect the messages to the appropiate output stream (stdout / stderr).
* FlutterWorld - added missing `super.dispose()` call
## [1.1.2] - 22/09/2019
* Fixed lint warnings

View File

@ -868,6 +868,7 @@ A reporter is a class that is able to report on the progress of the test run. In
- `ProgressReporter` - prints the result of each scenario and step to the console - colours the output.
- `TestRunSummaryReporter` - prints the results and duration of the test run once the run has completed - colours the output.
- `JsonReporter` - creates a JSON file with the results of the test run which can then be used by 'https://www.npmjs.com/package/cucumber-html-reporter.' to create a HTML report. You can pass in the file path of the json file to be created.
- `FlutterDriverReporter` - prints the output from Flutter Driver. Flutter driver logs all messages to the stderr stream by default so most CI servers would mark the process as failed if anything is logged to the stderr stream (even if the Flutter driver logs are only info messages). This reporter ensures the log messages are output to the most appropiate stream depending on their log level.
You can create your own custom reporter by inheriting from the base `Reporter` class and overriding the one or many of the methods to direct the output message. The `Reporter` defines the following methods that can be overridden. All methods must return a `Future<void>` and can be async.

View File

@ -13,7 +13,8 @@ Future<void> main() {
..reporters = [
ProgressReporter(),
TestRunSummaryReporter(),
JsonReporter(path: './report.json')
JsonReporter(path: './report.json'),
FlutterDriverReporter() // include this reporter if running on a CI server as Flutter driver logs all output to stderr
] // you can include the "StdoutReporter()" without the message level parameter for verbose log information
..hooks = [
HookExample()

View File

@ -15,3 +15,6 @@ export 'src/flutter/steps/restart_app_step.dart';
// Hooks
export 'src/flutter/hooks/attach_screenshot_on_failed_step_hook.dart';
// Reporters
export 'src/flutter/reporters/flutter_driver_reporter.dart';

View File

@ -35,6 +35,7 @@ class FlutterWorld extends World {
@override
void dispose() async {
super.dispose();
_flutterRunProcessHandler = null;
await _driver?.close();
}

View File

@ -0,0 +1,35 @@
import 'dart:async';
import 'dart:io';
import 'package:gherkin/gherkin.dart';
import 'package:flutter_driver/flutter_driver.dart';
/// The Flutter driver helpfully logs ALL messages to the stderr output
/// useless something is listening to the messages.
/// This reporter listens to the messages from the driver so nothing is logged
/// to the stderr stream unless it is actually an error.
/// This can cause problems with CI servers for example as they will mark a process as failed if it logs to the
/// stderr stream. So Flutter driver will log a normal info message to the stderr and thus make
/// the process fail from the perspective of a CI server.
class FlutterDriverReporter extends Reporter {
List<StreamSubscription> subscriptions = List<StreamSubscription>();
Future<void> onTestRunStarted() async {
subscriptions.add(
flutterDriverLog.where((log) => !isErrorLog(log.level)).listen((log) {
stdout.writeln(log.toString());
}));
subscriptions.add(
flutterDriverLog.where((log) => isErrorLog(log.level)).listen((log) {
stderr.writeln(log.toString());
}));
}
Future<void> dispose() async {
subscriptions.forEach((s) => s.cancel());
subscriptions.clear();
}
bool isErrorLog(LogLevel level) =>
level == LogLevel.error || level == LogLevel.critical;
}

View File

@ -1,6 +1,6 @@
name: flutter_gherkin
description: A Gherkin / Cucumber parser and test runner for Dart and Flutter
version: 1.1.2
version: 1.1.3
author: Jon Samwell <jonsamwell@gmail.com>
homepage: https://github.com/jonsamwell/flutter_gherkin