Unverified Commit fa83fefa authored by Dan Field's avatar Dan Field Committed by GitHub

Write timelines to separate files (#88473)

parent 17f0d2e5
...@@ -297,12 +297,19 @@ https://flutter.dev/docs/testing/integration-tests#testing-on-firebase-test-lab ...@@ -297,12 +297,19 @@ https://flutter.dev/docs/testing/integration-tests#testing-on-firebase-test-lab
/// ///
/// The `streams` and `retainPriorEvents` parameters are passed as-is to /// The `streams` and `retainPriorEvents` parameters are passed as-is to
/// [traceTimeline]. /// [traceTimeline].
///
/// The `reportKey` must not be `'screenshots'`, which is reserved for
/// screenshots created by
/// [IntegrationTestWidgetsFlutterBinding.takeScreenshot].
Future<void> traceAction( Future<void> traceAction(
Future<dynamic> Function() action, { Future<dynamic> Function() action, {
List<String> streams = const <String>['all'], List<String> streams = const <String>['all'],
bool retainPriorEvents = false, bool retainPriorEvents = false,
String reportKey = 'timeline', String reportKey = 'timeline',
}) async { }) async {
if (reportKey == 'screenshots') {
throw ArgumentError('The "screenshots" reportKey is reserved.');
}
final vm.Timeline timeline = await traceTimeline( final vm.Timeline timeline = await traceTimeline(
action, action,
streams: streams, streams: streams,
......
...@@ -24,7 +24,8 @@ String testOutputsDirectory = ...@@ -24,7 +24,8 @@ String testOutputsDirectory =
typedef ResponseDataCallback = FutureOr<void> Function(Map<String, dynamic>?); typedef ResponseDataCallback = FutureOr<void> Function(Map<String, dynamic>?);
/// Writes a json-serializable data to /// Writes a json-serializable data to
/// [testOutputsDirectory]/`testOutputFilename.json`. /// [testOutputsDirectory]/`testOutputFilename_<key>.json`, where key is the
/// name provided as the report key for the response data.
/// ///
/// This is the default `responseDataCallback` in [integrationDriver]. /// This is the default `responseDataCallback` in [integrationDriver].
Future<void> writeResponseData( Future<void> writeResponseData(
...@@ -32,15 +33,20 @@ Future<void> writeResponseData( ...@@ -32,15 +33,20 @@ Future<void> writeResponseData(
String testOutputFilename = 'integration_response_data', String testOutputFilename = 'integration_response_data',
String? destinationDirectory, String? destinationDirectory,
}) async { }) async {
if (data == null) {
return;
}
assert(testOutputFilename != null); assert(testOutputFilename != null);
destinationDirectory ??= testOutputsDirectory; destinationDirectory ??= testOutputsDirectory;
await fs.directory(destinationDirectory).create(recursive: true); await fs.directory(destinationDirectory).create(recursive: true);
final File file = fs.file(path.join( for (final String key in data.keys.where((String key) => key != 'screenshots')) {
destinationDirectory, final File file = fs.file(path.join(
'$testOutputFilename.json', destinationDirectory,
)); '${testOutputFilename}_$key.json',
final String resultString = _encodeJson(data, true); ));
await file.writeAsString(resultString); final String resultString = _encodeJson(data[key], true);
await file.writeAsString(resultString);
}
} }
/// Adaptor to run an integration test using `flutter drive`. /// Adaptor to run an integration test using `flutter drive`.
...@@ -95,6 +101,6 @@ Future<void> integrationDriver({ ...@@ -95,6 +101,6 @@ Future<void> integrationDriver({
const JsonEncoder _prettyEncoder = JsonEncoder.withIndent(' '); const JsonEncoder _prettyEncoder = JsonEncoder.withIndent(' ');
String _encodeJson(Map<String, dynamic>? jsonObject, bool pretty) { String _encodeJson(Object? jsonObject, bool pretty) {
return pretty ? _prettyEncoder.convert(jsonObject) : json.encode(jsonObject); return pretty ? _prettyEncoder.convert(jsonObject) : json.encode(jsonObject);
} }
// 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 'package:flutter_driver/flutter_driver.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test_driver.dart';
import 'package:path/path.dart' as path;
void main() {
useMemoryFileSystemForTesting();
test('Writes multiple files for each timeline', () async {
final String outDir = fs.systemTempDirectory.path;
await writeResponseData(
<String, dynamic>{
'timeline_a': <String, dynamic>{},
'timeline_b': <String, dynamic>{},
'screenshots': <String, dynamic>{},
},
destinationDirectory: outDir,
);
expect(fs.file(path.join(outDir, 'integration_response_data_timeline_a.json')).existsSync(), true);
expect(fs.file(path.join(outDir, 'integration_response_data_timeline_b.json')).existsSync(), true);
expect(fs.file(path.join(outDir, 'integration_response_data_screenshots.json')).existsSync(), false);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment