traceAction method

Future<void> traceAction(
  1. Future action(), {
  2. List<String> streams = const <String>['all'],
  3. bool retainPriorEvents = false,
  4. String reportKey = 'timeline',
})

This is a convenience method that calls traceTimeline and sends the result back to the host for the flutter_driver style tests.

This records the timeline during action and adds the result to reportData with reportKey. The reportData contains extra information from the test other than test success/fail. It will be passed back to the host and be processed by the ResponseDataCallback defined in integrationDriver. By default it will be written to build/integration_response_data.json with the key timeline.

For tests with multiple calls of this method, reportKey needs to be a unique key, otherwise the later result will override earlier one. Tests that call this multiple times must also provide a custom ResponseDataCallback to decide where and how to write the output timelines. For example,

import 'package:integration_test/integration_test_driver.dart';

Future<void> main() {
  return integrationDriver(
    responseDataCallback: (Map<String, dynamic>? data) async {
      if (data != null) {
        for (final MapEntry<String, dynamic> entry in data.entries) {
          print('Writing ${entry.key} to the disk.');
          await writeResponseData(
            entry.value as Map<String, dynamic>,
            testOutputFilename: entry.key,
          );
        }
      }
    },
  );
}

The streams and retainPriorEvents parameters are passed as-is to traceTimeline.

Implementation

Future<void> traceAction(
  Future<dynamic> Function() action, {
  List<String> streams = const <String>['all'],
  bool retainPriorEvents = false,
  String reportKey = 'timeline',
}) async {
  final vm.Timeline timeline = await traceTimeline(
    action,
    streams: streams,
    retainPriorEvents: retainPriorEvents,
  );
  reportData ??= <String, dynamic>{};
  reportData![reportKey] = timeline.toJson();
}