Unverified Commit 7912cbea authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove mocks from cold test (#81550)

parent 50ace38c
...@@ -16,7 +16,7 @@ import 'package:flutter_tools/src/run_cold.dart'; ...@@ -16,7 +16,7 @@ import 'package:flutter_tools/src/run_cold.dart';
import 'package:flutter_tools/src/tracing.dart'; import 'package:flutter_tools/src/tracing.dart';
import 'package:flutter_tools/src/vmservice.dart'; import 'package:flutter_tools/src/vmservice.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:mockito/mockito.dart'; import 'package:test/fake.dart';
import 'package:vm_service/vm_service.dart'; import 'package:vm_service/vm_service.dart';
import '../src/common.dart'; import '../src/common.dart';
...@@ -26,15 +26,13 @@ void main() { ...@@ -26,15 +26,13 @@ void main() {
testUsingContext('Exits with code 2 when when HttpException is thrown ' testUsingContext('Exits with code 2 when when HttpException is thrown '
'during VM service connection', () async { 'during VM service connection', () async {
final FakeResidentCompiler residentCompiler = FakeResidentCompiler(); final FakeResidentCompiler residentCompiler = FakeResidentCompiler();
final MockDevice mockDevice = MockDevice(); final FakeDevice device = FakeDevice()
when(mockDevice.supportsHotReload).thenReturn(true); ..supportsHotReload = true
when(mockDevice.supportsHotRestart).thenReturn(false); ..supportsHotRestart = false;
when(mockDevice.targetPlatform).thenAnswer((Invocation _) async => TargetPlatform.tester);
when(mockDevice.sdkNameAndVersion).thenAnswer((Invocation _) async => 'Android 10');
final List<FlutterDevice> devices = <FlutterDevice>[ final List<FlutterDevice> devices = <FlutterDevice>[
TestFlutterDevice( TestFlutterDevice(
device: mockDevice, device: device,
generator: residentCompiler, generator: residentCompiler,
exception: const HttpException('Connection closed before full header was received, ' exception: const HttpException('Connection closed before full header was received, '
'uri = http://127.0.0.1:63394/5ZmLv8A59xY=/ws'), 'uri = http://127.0.0.1:63394/5ZmLv8A59xY=/ws'),
...@@ -51,29 +49,23 @@ void main() { ...@@ -51,29 +49,23 @@ void main() {
}); });
group('cleanupAtFinish()', () { group('cleanupAtFinish()', () {
MockFlutterDevice mockFlutterDeviceFactory(Device device) {
final MockFlutterDevice mockFlutterDevice = MockFlutterDevice();
when(mockFlutterDevice.device).thenReturn(device);
return mockFlutterDevice;
}
testUsingContext('disposes each device', () async { testUsingContext('disposes each device', () async {
final MockDevice mockDevice1 = MockDevice(); final FakeDevice device1 = FakeDevice();
final MockDevice mockDevice2 = MockDevice(); final FakeDevice device2 = FakeDevice();
final MockFlutterDevice mockFlutterDevice1 = mockFlutterDeviceFactory(mockDevice1); final FakeFlutterDevice flutterDevice1 = FakeFlutterDevice(device1);
final MockFlutterDevice mockFlutterDevice2 = mockFlutterDeviceFactory(mockDevice2); final FakeFlutterDevice flutterDevice2 = FakeFlutterDevice(device2);
final List<FlutterDevice> devices = <FlutterDevice>[mockFlutterDevice1, mockFlutterDevice2]; final List<FlutterDevice> devices = <FlutterDevice>[flutterDevice1, flutterDevice2];
await ColdRunner(devices, await ColdRunner(devices,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart', target: 'main.dart',
).cleanupAtFinish(); ).cleanupAtFinish();
verify(mockDevice1.dispose()); expect(flutterDevice1.stopEchoingDeviceLogCount, 1);
expect(mockFlutterDevice1.stopEchoingDeviceLogCount, 1); expect(flutterDevice2.stopEchoingDeviceLogCount, 1);
verify(mockDevice2.dispose()); expect(device2.wasDisposed, true);
expect(mockFlutterDevice2.stopEchoingDeviceLogCount, 1); expect(device1.wasDisposed, true);
}); });
}); });
...@@ -86,14 +78,10 @@ void main() { ...@@ -86,14 +78,10 @@ void main() {
}); });
testUsingContext('calls runCold on attached device', () async { testUsingContext('calls runCold on attached device', () async {
final MockDevice mockDevice = MockDevice(); final FakeDevice device = FakeDevice();
final MockFlutterDevice mockFlutterDevice = MockFlutterDevice(); final FakeFlutterDevice flutterDevice = FakeFlutterDevice(device)
when(mockFlutterDevice.device).thenReturn(mockDevice); ..runColdCode = 1;
when(mockFlutterDevice.runCold( final List<FlutterDevice> devices = <FlutterDevice>[flutterDevice];
coldRunner: anyNamed('coldRunner'),
route: anyNamed('route')
)).thenAnswer((Invocation invocation) => Future<int>.value(1));
final List<FlutterDevice> devices = <FlutterDevice>[mockFlutterDevice];
final File applicationBinary = MemoryFileSystem.test().file('binary'); final File applicationBinary = MemoryFileSystem.test().file('binary');
final int result = await ColdRunner( final int result = await ColdRunner(
devices, devices,
...@@ -105,21 +93,12 @@ void main() { ...@@ -105,21 +93,12 @@ void main() {
); );
expect(result, 1); expect(result, 1);
verify(mockFlutterDevice.runCold(
coldRunner: anyNamed('coldRunner'),
route: anyNamed('route'),
));
}); });
testUsingContext('with traceStartup, no env variable', () async { testUsingContext('with traceStartup, no env variable', () async {
final MockDevice mockDevice = MockDevice(); final FakeDevice device = FakeDevice();
final MockFlutterDevice mockFlutterDevice = MockFlutterDevice(); final FakeFlutterDevice flutterDevice = FakeFlutterDevice(device);
when(mockFlutterDevice.device).thenReturn(mockDevice); final List<FlutterDevice> devices = <FlutterDevice>[flutterDevice];
when(mockFlutterDevice.runCold(
coldRunner: anyNamed('coldRunner'),
route: anyNamed('route')
)).thenAnswer((Invocation invocation) => Future<int>.value(0));
final List<FlutterDevice> devices = <FlutterDevice>[mockFlutterDevice];
final File applicationBinary = MemoryFileSystem.test().file('binary'); final File applicationBinary = MemoryFileSystem.test().file('binary');
final int result = await ColdRunner( final int result = await ColdRunner(
devices, devices,
...@@ -142,14 +121,9 @@ void main() { ...@@ -142,14 +121,9 @@ void main() {
testUsingContext('with traceStartup, env variable', () async { testUsingContext('with traceStartup, env variable', () async {
fakePlatform.environment[kFlutterTestOutputsDirEnvName] = 'test_output_dir'; fakePlatform.environment[kFlutterTestOutputsDirEnvName] = 'test_output_dir';
final MockDevice mockDevice = MockDevice(); final FakeDevice device = FakeDevice();
final MockFlutterDevice mockFlutterDevice = MockFlutterDevice(); final FakeFlutterDevice flutterDevice = FakeFlutterDevice(device);
when(mockFlutterDevice.device).thenReturn(mockDevice); final List<FlutterDevice> devices = <FlutterDevice>[flutterDevice];
when(mockFlutterDevice.runCold(
coldRunner: anyNamed('coldRunner'),
route: anyNamed('route')
)).thenAnswer((Invocation invocation) => Future<int>.value(0));
final List<FlutterDevice> devices = <FlutterDevice>[mockFlutterDevice];
final File applicationBinary = MemoryFileSystem.test().file('binary'); final File applicationBinary = MemoryFileSystem.test().file('binary');
final int result = await ColdRunner( final int result = await ColdRunner(
devices, devices,
...@@ -171,7 +145,15 @@ void main() { ...@@ -171,7 +145,15 @@ void main() {
}); });
} }
class MockFlutterDevice extends Mock implements FlutterDevice { class FakeFlutterDevice extends Fake implements FlutterDevice {
FakeFlutterDevice(this.device);
@override
Stream<Uri> get observatoryUris => const Stream<Uri>.empty();
@override
final Device device;
int stopEchoingDeviceLogCount = 0; int stopEchoingDeviceLogCount = 0;
@override @override
...@@ -181,10 +163,42 @@ class MockFlutterDevice extends Mock implements FlutterDevice { ...@@ -181,10 +163,42 @@ class MockFlutterDevice extends Mock implements FlutterDevice {
@override @override
FlutterVmService get vmService => FakeFlutterVmService(); FlutterVmService get vmService => FakeFlutterVmService();
int runColdCode = 0;
@override
Future<int> runCold({ColdRunner coldRunner, String route}) async {
return runColdCode;
}
@override
Future<void> initLogReader() async { }
} }
class MockDevice extends Mock implements Device {
MockDevice() { class FakeDevice extends Fake implements Device {
when(isSupported()).thenReturn(true); @override
bool isSupported() => true;
@override
bool supportsHotReload;
@override
bool supportsHotRestart;
@override
Future<String> get sdkNameAndVersion async => 'Android 10';
@override
String get name => 'test';
@override
Future<TargetPlatform> get targetPlatform async => TargetPlatform.tester;
bool wasDisposed = false;
@override
Future<void> dispose() async {
wasDisposed = true;
} }
} }
......
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