Unverified Commit 335a3181 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove mocks from hot test (#82301)

parent f6842f78
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
// @dart = 2.8 // @dart = 2.8
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/application_package.dart';
import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
...@@ -18,7 +19,7 @@ import 'package:flutter_tools/src/resident_runner.dart'; ...@@ -18,7 +19,7 @@ import 'package:flutter_tools/src/resident_runner.dart';
import 'package:flutter_tools/src/run_hot.dart'; import 'package:flutter_tools/src/run_hot.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' as vm_service; import 'package:vm_service/vm_service.dart' as vm_service;
import '../src/common.dart'; import '../src/common.dart';
...@@ -144,30 +145,8 @@ void main() { ...@@ -144,30 +145,8 @@ void main() {
group('hotRestart', () { group('hotRestart', () {
final FakeResidentCompiler residentCompiler = FakeResidentCompiler(); final FakeResidentCompiler residentCompiler = FakeResidentCompiler();
final MockDevFs mockDevFs = MockDevFs();
FileSystem fileSystem; FileSystem fileSystem;
when(mockDevFs.update(
mainUri: anyNamed('mainUri'),
target: anyNamed('target'),
bundle: anyNamed('bundle'),
firstBuildTime: anyNamed('firstBuildTime'),
bundleFirstUpload: anyNamed('bundleFirstUpload'),
generator: anyNamed('generator'),
fullRestart: anyNamed('fullRestart'),
dillOutputPath: anyNamed('dillOutputPath'),
trackWidgetCreation: anyNamed('trackWidgetCreation'),
projectRootPath: anyNamed('projectRootPath'),
pathToReload: anyNamed('pathToReload'),
invalidatedFiles: anyNamed('invalidatedFiles'),
packageConfig: anyNamed('packageConfig'),
)).thenAnswer((Invocation _) => Future<UpdateFSReport>.value(
UpdateFSReport(success: true, syncedBytes: 1000, invalidatedSourcesCount: 1)));
when(mockDevFs.assetPathsToEvict).thenReturn(<String>{});
when(mockDevFs.baseUri).thenReturn(Uri.file('test'));
when(mockDevFs.sources).thenReturn(<Uri>[Uri.file('test')]);
when(mockDevFs.lastCompiled).thenReturn(DateTime.now());
setUp(() { setUp(() {
fileSystem = MemoryFileSystem.test(); fileSystem = MemoryFileSystem.test();
}); });
...@@ -176,12 +155,9 @@ void main() { ...@@ -176,12 +155,9 @@ void main() {
fileSystem.file('.packages') fileSystem.file('.packages')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync('\n'); ..writeAsStringSync('\n');
final MockDevice mockDevice = MockDevice(); final FakeDevice device = FakeDevice();
when(mockDevice.supportsHotReload).thenReturn(true);
when(mockDevice.supportsHotRestart).thenReturn(true);
when(mockDevice.targetPlatform).thenAnswer((Invocation _) async => TargetPlatform.tester);
final List<FlutterDevice> devices = <FlutterDevice>[ final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug)..devFS = MockDevFs(), FlutterDevice(device, generator: residentCompiler, buildInfo: BuildInfo.debug)..devFS = FakeDevFs(),
]; ];
final OperationResult result = await HotRunner( final OperationResult result = await HotRunner(
devices, devices,
...@@ -212,12 +188,9 @@ void main() { ...@@ -212,12 +188,9 @@ void main() {
fileSystem.file('.packages') fileSystem.file('.packages')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync('\n'); ..writeAsStringSync('\n');
final MockDevice mockDevice = MockDevice(); final FakeDevice device = FakeDevice();
when(mockDevice.supportsHotReload).thenReturn(true);
when(mockDevice.supportsHotRestart).thenReturn(true);
when(mockDevice.supportsFlutterExit).thenReturn(false);
final List<FlutterDevice> devices = <FlutterDevice>[ final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug), FlutterDevice(device, generator: residentCompiler, buildInfo: BuildInfo.debug),
]; ];
await HotRunner( await HotRunner(
devices, devices,
...@@ -237,12 +210,9 @@ void main() { ...@@ -237,12 +210,9 @@ void main() {
fileSystem.file('.packages') fileSystem.file('.packages')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync('\n'); ..writeAsStringSync('\n');
final MockDevice mockDevice = MockDevice(); final FakeDevice device = FakeDevice();
when(mockDevice.supportsHotReload).thenReturn(true);
when(mockDevice.supportsHotRestart).thenReturn(true);
when(mockDevice.supportsFlutterExit).thenReturn(false);
final List<FlutterDevice> devices = <FlutterDevice>[ final List<FlutterDevice> devices = <FlutterDevice>[
FlutterDevice(mockDevice, generator: residentCompiler, buildInfo: BuildInfo.debug), FlutterDevice(device, generator: residentCompiler, buildInfo: BuildInfo.debug),
]; ];
await HotRunner( await HotRunner(
devices, devices,
...@@ -274,15 +244,10 @@ void main() { ...@@ -274,15 +244,10 @@ void main() {
..writeAsStringSync('\n'); ..writeAsStringSync('\n');
final FakeResidentCompiler residentCompiler = FakeResidentCompiler(); final FakeResidentCompiler residentCompiler = FakeResidentCompiler();
final MockDevice mockDevice = MockDevice(); final FakeDevice device = FakeDevice();
when(mockDevice.supportsHotReload).thenReturn(true);
when(mockDevice.supportsHotRestart).thenReturn(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'),
...@@ -306,22 +271,15 @@ void main() { ...@@ -306,22 +271,15 @@ void main() {
}); });
group('hot cleanupAtFinish()', () { group('hot cleanupAtFinish()', () {
MockFlutterDevice mockFlutterDeviceFactory(Device device) {
final MockFlutterDevice mockFlutterDevice = MockFlutterDevice();
when(mockFlutterDevice.stopEchoingDeviceLog()).thenAnswer((Invocation invocation) => Future<void>.value(null));
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>[ final List<FlutterDevice> devices = <FlutterDevice>[
mockFlutterDevice1, flutterDevice1,
mockFlutterDevice2, flutterDevice2,
]; ];
await HotRunner(devices, await HotRunner(devices,
...@@ -329,23 +287,74 @@ void main() { ...@@ -329,23 +287,74 @@ void main() {
target: 'main.dart', target: 'main.dart',
).cleanupAtFinish(); ).cleanupAtFinish();
verify(mockDevice1.dispose()); expect(device1.disposed, true);
verify(mockFlutterDevice1.stopEchoingDeviceLog()); expect(device2.disposed, true);
verify(mockDevice2.dispose());
verify(mockFlutterDevice2.stopEchoingDeviceLog()); expect(flutterDevice1.stoppedEchoingDeviceLog, true);
expect(flutterDevice2.stoppedEchoingDeviceLog, true);
}); });
}); });
} }
class MockDevFs extends Mock implements DevFS {} class FakeDevFs extends Fake implements DevFS {
@override
Future<void> destroy() async { }
}
class FakeDevice extends Fake implements Device {
bool disposed = false;
@override
bool isSupported() => true;
@override
bool supportsHotReload = true;
@override
bool supportsHotRestart = true;
@override
bool supportsFlutterExit = true;
@override
Future<TargetPlatform> get targetPlatform async => TargetPlatform.tester;
@override
Future<String> get sdkNameAndVersion async => 'Tester';
class MockDevice extends Mock implements Device { @override
MockDevice() { Future<bool> get isLocalEmulator async => false;
when(isSupported()).thenReturn(true);
@override
Future<bool> stopApp(
covariant ApplicationPackage app, {
String userIdentifier,
}) async {
return true;
}
@override
Future<void> dispose() async {
disposed = true;
} }
} }
class MockFlutterDevice extends Mock implements FlutterDevice {} class FakeFlutterDevice extends Fake implements FlutterDevice {
FakeFlutterDevice(this.device);
bool stoppedEchoingDeviceLog = false;
@override
final FakeDevice device;
@override
Future<void> stopEchoingDeviceLog() async {
stoppedEchoingDeviceLog = true;
}
@override
DevFS devFS = FakeDevFs();
}
class TestFlutterDevice extends FlutterDevice { class TestFlutterDevice extends FlutterDevice {
TestFlutterDevice({ TestFlutterDevice({
......
...@@ -42,7 +42,6 @@ dev_dependencies: ...@@ -42,7 +42,6 @@ dev_dependencies:
sdk: flutter sdk: flutter
flutter_goldens: flutter_goldens:
sdk: flutter sdk: flutter
mockito: 4.1.1
archive: 2.0.11 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" archive: 2.0.11 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
......
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