NNBD integration_test (#74922)
This commit is contained in:
@@ -18,7 +18,7 @@ const String _failureExcerpt = r'Expected: <false>\n Actual: <true>';
|
||||
Future<void> main() async {
|
||||
group('Integration binding result', () {
|
||||
test('when multiple tests pass', () async {
|
||||
final Map<String, dynamic> results = await _runTest(path.join('test', 'data', 'pass_test_script.dart'));
|
||||
final Map<String, dynamic>? results = await _runTest(path.join('test', 'data', 'pass_test_script.dart'));
|
||||
|
||||
expect(
|
||||
results,
|
||||
@@ -29,7 +29,7 @@ Future<void> main() async {
|
||||
});
|
||||
|
||||
test('when multiple tests fail', () async {
|
||||
final Map<String, dynamic> results = await _runTest(path.join('test', 'data', 'fail_test_script.dart'));
|
||||
final Map<String, dynamic>? results = await _runTest(path.join('test', 'data', 'fail_test_script.dart'));
|
||||
|
||||
expect(results, hasLength(2));
|
||||
expect(results, containsPair('failing test 1', contains(_failureExcerpt)));
|
||||
@@ -37,7 +37,7 @@ Future<void> main() async {
|
||||
});
|
||||
|
||||
test('when one test passes, then another fails', () async {
|
||||
final Map<String, dynamic> results = await _runTest(path.join('test', 'data', 'pass_then_fail_test_script.dart'));
|
||||
final Map<String, dynamic>? results = await _runTest(path.join('test', 'data', 'pass_then_fail_test_script.dart'));
|
||||
|
||||
expect(results, hasLength(2));
|
||||
expect(results, containsPair('passing test', equals('success')));
|
||||
@@ -49,7 +49,7 @@ Future<void> main() async {
|
||||
/// Runs a test script and returns the [IntegrationTestWidgetsFlutterBinding.result].
|
||||
///
|
||||
/// [scriptPath] is relative to the package root.
|
||||
Future<Map<String, dynamic>> _runTest(String scriptPath) async {
|
||||
Future<Map<String, dynamic>?> _runTest(String scriptPath) async {
|
||||
final Process process =
|
||||
await Process.start(_flutterBin, <String>['test', '--machine', scriptPath]);
|
||||
|
||||
@@ -63,7 +63,7 @@ Future<Map<String, dynamic>> _runTest(String scriptPath) async {
|
||||
.expand((String text) => text.split('\n'))
|
||||
.map<dynamic>((String line) {
|
||||
try {
|
||||
return jsonDecode(line);
|
||||
return jsonDecode(line) as Map<String, dynamic>?;
|
||||
} on FormatException {
|
||||
// Only interested in test events which are JSON.
|
||||
}
|
||||
@@ -73,12 +73,12 @@ Future<Map<String, dynamic>> _runTest(String scriptPath) async {
|
||||
? json.cast()
|
||||
: <Map<String, dynamic>>[json as Map<String, dynamic>];
|
||||
})
|
||||
.where((Map<String, dynamic> testEvent) =>
|
||||
.where((Map<String, dynamic>? testEvent) =>
|
||||
testEvent != null && testEvent['type'] == 'print')
|
||||
.map((Map<String, dynamic> printEvent) => printEvent['message'] as String)
|
||||
.firstWhere((String message) =>
|
||||
message.startsWith(_integrationResultsPrefix)))
|
||||
.map((Map<String, dynamic>? printEvent) => printEvent!['message'] as String?)
|
||||
.firstWhere((String? message) =>
|
||||
message!.startsWith(_integrationResultsPrefix)))!
|
||||
.replaceAll(_integrationResultsPrefix, '');
|
||||
|
||||
return jsonDecode(testResults) as Map<String, dynamic>;
|
||||
return jsonDecode(testResults) as Map<String, dynamic>?;
|
||||
}
|
||||
|
||||
@@ -18,14 +18,14 @@ vm.Timeline _kTimelines = vm.Timeline(
|
||||
);
|
||||
|
||||
Future<void> main() async {
|
||||
Future<Map<String, dynamic>> request;
|
||||
Future<Map<String, dynamic>>? request;
|
||||
|
||||
group('Test Integration binding', () {
|
||||
final WidgetsBinding binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
assert(binding is IntegrationTestWidgetsFlutterBinding);
|
||||
final IntegrationTestWidgetsFlutterBinding integrationBinding = binding as IntegrationTestWidgetsFlutterBinding;
|
||||
|
||||
FakeVM fakeVM;
|
||||
FakeVM? fakeVM;
|
||||
|
||||
setUp(() {
|
||||
request = integrationBinding.callback(<String, String>{
|
||||
@@ -74,9 +74,9 @@ Future<void> main() async {
|
||||
await integrationBinding.enableTimeline(vmService: fakeVM);
|
||||
await integrationBinding.traceAction(() async {});
|
||||
expect(integrationBinding.reportData, isNotNull);
|
||||
expect(integrationBinding.reportData.containsKey('timeline'), true);
|
||||
expect(integrationBinding.reportData!.containsKey('timeline'), true);
|
||||
expect(
|
||||
json.encode(integrationBinding.reportData['timeline']),
|
||||
json.encode(integrationBinding.reportData!['timeline']),
|
||||
json.encode(_kTimelines),
|
||||
);
|
||||
});
|
||||
@@ -107,20 +107,20 @@ Future<void> main() async {
|
||||
// part of the `tearDownAll` registerred in the group during
|
||||
// `IntegrationTestWidgetsFlutterBinding` initialization.
|
||||
final Map<String, dynamic> response =
|
||||
(await request)['response'] as Map<String, dynamic>;
|
||||
(await request)!['response'] as Map<String, dynamic>;
|
||||
final String message = response['message'] as String;
|
||||
final Response result = Response.fromJson(message);
|
||||
assert(result.data['answer'] == 42);
|
||||
assert(result.data!['answer'] == 42);
|
||||
});
|
||||
}
|
||||
|
||||
class FakeVM extends Fake implements vm.VmService {
|
||||
FakeVM({@required this.timeline});
|
||||
FakeVM({required this.timeline});
|
||||
|
||||
vm.Timeline timeline;
|
||||
|
||||
@override
|
||||
Future<vm.Timeline> getVMTimeline({int timeOriginMicros, int timeExtentMicros}) async {
|
||||
Future<vm.Timeline> getVMTimeline({int? timeOriginMicros, int? timeExtentMicros}) async {
|
||||
return timeline;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,13 +39,13 @@ void main() {
|
||||
response = Response.allTestsPassed(data: data);
|
||||
jsonString = response.toJson();
|
||||
restored = Response.fromJson(jsonString);
|
||||
expect(restored.data.keys, <String>['aaa']);
|
||||
expect(restored.data.values, <String>['bbb']);
|
||||
expect(restored.data!.keys, <String>['aaa']);
|
||||
expect(restored.data!.values, <String>['bbb']);
|
||||
|
||||
response = Response.someTestsFailed(<Failure>[fail, fail2], data: data);
|
||||
jsonString = response.toJson();
|
||||
restored = Response.fromJson(jsonString);
|
||||
expect(restored.data.keys, <String>['aaa']);
|
||||
expect(restored.data.values, <String>['bbb']);
|
||||
expect(restored.data!.keys, <String>['aaa']);
|
||||
expect(restored.data!.values, <String>['bbb']);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user