// 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. // @dart = 2.8 import 'dart:async'; import 'package:dds/dds.dart' as dds; import 'package:file/memory.dart'; import 'package:file_testing/file_testing.dart'; import 'package:flutter_tools/src/application_package.dart'; import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/asset.dart'; import 'package:flutter_tools/src/base/command_help.dart'; import 'package:flutter_tools/src/base/common.dart'; import 'package:flutter_tools/src/base/dds.dart'; import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/io.dart' as io; import 'package:flutter_tools/src/base/logger.dart'; import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/compile.dart'; import 'package:flutter_tools/src/convert.dart'; import 'package:flutter_tools/src/devfs.dart'; import 'package:flutter_tools/src/device.dart'; import 'package:flutter_tools/src/device_port_forwarder.dart'; import 'package:flutter_tools/src/features.dart'; import 'package:flutter_tools/src/globals_null_migrated.dart' as globals; import 'package:flutter_tools/src/reporting/reporting.dart'; import 'package:flutter_tools/src/resident_devtools_handler.dart'; import 'package:flutter_tools/src/resident_runner.dart'; import 'package:flutter_tools/src/run_cold.dart'; import 'package:flutter_tools/src/run_hot.dart'; import 'package:flutter_tools/src/version.dart'; import 'package:flutter_tools/src/vmservice.dart'; import 'package:meta/meta.dart'; import 'package:mockito/mockito.dart'; import 'package:package_config/package_config.dart'; import 'package:vm_service/vm_service.dart' as vm_service; import '../src/common.dart'; import '../src/context.dart'; import '../src/fake_vm_services.dart'; import '../src/fakes.dart'; import '../src/testbed.dart'; final vm_service.Isolate fakeUnpausedIsolate = vm_service.Isolate( id: '1', pauseEvent: vm_service.Event( kind: vm_service.EventKind.kResume, timestamp: 0 ), breakpoints: [], exceptionPauseMode: null, extensionRPCs: [], libraries: [ vm_service.LibraryRef( id: '1', uri: 'file:///hello_world/main.dart', name: '', ), ], livePorts: 0, name: 'test', number: '1', pauseOnExit: false, runnable: true, startTime: 0, isSystemIsolate: false, isolateFlags: [], ); final vm_service.Isolate fakePausedIsolate = vm_service.Isolate( id: '1', pauseEvent: vm_service.Event( kind: vm_service.EventKind.kPauseException, timestamp: 0 ), breakpoints: [ vm_service.Breakpoint( breakpointNumber: 123, id: 'test-breakpoint', location: vm_service.SourceLocation( tokenPos: 0, script: vm_service.ScriptRef(id: 'test-script', uri: 'foo.dart'), ), resolved: true, ), ], exceptionPauseMode: null, libraries: [], livePorts: 0, name: 'test', number: '1', pauseOnExit: false, runnable: true, startTime: 0, isSystemIsolate: false, isolateFlags: [], ); final vm_service.VM fakeVM = vm_service.VM( isolates: [fakeUnpausedIsolate], pid: 1, hostCPU: '', isolateGroups: [], targetCPU: '', startTime: 0, name: 'dart', architectureBits: 64, operatingSystem: '', version: '', systemIsolateGroups: [], systemIsolates: [], ); final FlutterView fakeFlutterView = FlutterView( id: 'a', uiIsolate: fakeUnpausedIsolate, ); final FakeVmServiceRequest listViews = FakeVmServiceRequest( method: kListViewsMethod, jsonResponse: { 'views': [ fakeFlutterView.toJson(), ], }, ); const FakeVmServiceRequest setAssetBundlePath = FakeVmServiceRequest( method: '_flutter.setAssetBundlePath', args: { 'viewId': 'a', 'assetDirectory': 'build/flutter_assets', 'isolateId': '1', } ); final Uri testUri = Uri.parse('foo://bar'); void main() { Testbed testbed; MockFlutterDevice mockFlutterDevice; MockVMService mockVMService; FakeDevFS mockDevFS; ResidentRunner residentRunner; FakeDevice mockDevice; FakeVmServiceHost fakeVmServiceHost; setUp(() { testbed = Testbed(setup: () { globals.fs.file('.packages') .writeAsStringSync('\n'); globals.fs.file(globals.fs.path.join('build', 'app.dill')) ..createSync(recursive: true) ..writeAsStringSync('ABC'); residentRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); }); mockFlutterDevice = MockFlutterDevice(); mockDevice = FakeDevice(); mockVMService = MockVMService(); mockDevFS = FakeDevFS(); // FlutterDevice Mocks. when(mockFlutterDevice.updateDevFS( invalidatedFiles: anyNamed('invalidatedFiles'), mainUri: anyNamed('mainUri'), target: anyNamed('target'), bundle: anyNamed('bundle'), firstBuildTime: anyNamed('firstBuildTime'), bundleFirstUpload: anyNamed('bundleFirstUpload'), bundleDirty: anyNamed('bundleDirty'), fullRestart: anyNamed('fullRestart'), projectRootPath: anyNamed('projectRootPath'), pathToReload: anyNamed('pathToReload'), dillOutputPath: anyNamed('dillOutputPath'), packageConfig: anyNamed('packageConfig'), )).thenAnswer((Invocation invocation) async { return UpdateFSReport( success: true, syncedBytes: 0, invalidatedSourcesCount: 1, ); }); when(mockFlutterDevice.devFS).thenReturn(mockDevFS); when(mockFlutterDevice.device).thenReturn(mockDevice); when(mockFlutterDevice.stopEchoingDeviceLog()).thenAnswer((Invocation invocation) async { }); when(mockFlutterDevice.observatoryUris).thenAnswer((_) => Stream.value(testUri)); when(mockFlutterDevice.connect( reloadSources: anyNamed('reloadSources'), restart: anyNamed('restart'), compileExpression: anyNamed('compileExpression'), getSkSLMethod: anyNamed('getSkSLMethod'), allowExistingDdsInstance: anyNamed('allowExistingDdsInstance'), )).thenAnswer((Invocation invocation) async { }); when(mockFlutterDevice.setupDevFS(any, any)) .thenAnswer((Invocation invocation) async { return testUri; }); when(mockFlutterDevice.vmService).thenAnswer((Invocation invocation) { return fakeVmServiceHost?.vmService; }); }); testUsingContext('ResidentRunner can attach to device successfully', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, ]); final Completer futureConnectionInfo = Completer.sync(); final Completer futureAppStart = Completer.sync(); final Future result = residentRunner.attach( appStartedCompleter: futureAppStart, connectionInfoCompleter: futureConnectionInfo, enableDevTools: true, ); final Future connectionInfo = futureConnectionInfo.future; expect(await result, 0); verify(mockFlutterDevice.initLogReader()).called(1); expect(futureConnectionInfo.isCompleted, true); expect((await connectionInfo).baseUri, 'foo://bar'); expect(futureAppStart.isCompleted, true); expect(fakeVmServiceHost.hasRemainingExpectations, false); })); testUsingContext('ResidentRunner suppresses errors for the initial compilation', () => testbed.run(() async { globals.fs.file(globals.fs.path.join('lib', 'main.dart')) .createSync(recursive: true); fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, ]); final MockResidentCompiler residentCompiler = MockResidentCompiler(); residentRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); when(mockFlutterDevice.generator).thenReturn(residentCompiler); when(residentCompiler.recompile( any, any, outputPath: anyNamed('outputPath'), packageConfig: anyNamed('packageConfig'), suppressErrors: true, projectRootPath: anyNamed('projectRootPath'), fs: anyNamed('fs'), )).thenAnswer((Invocation invocation) async { return const CompilerOutput('foo', 0 ,[]); }); when(mockFlutterDevice.runHot( hotRunner: anyNamed('hotRunner'), route: anyNamed('route'), )).thenAnswer((Invocation invocation) async { return 0; }); expect(await residentRunner.run(enableDevTools: true), 0); verify(residentCompiler.recompile( any, any, outputPath: anyNamed('outputPath'), packageConfig: anyNamed('packageConfig'), suppressErrors: true, projectRootPath: anyNamed('projectRootPath'), fs: anyNamed('fs'), )).called(1); expect(fakeVmServiceHost.hasRemainingExpectations, false); })); // Regression test for https://github.com/flutter/flutter/issues/60613 testUsingContext('ResidentRunner calls appFailedToStart if initial compilation fails', () => testbed.run(() async { globals.fs.file(globals.fs.path.join('lib', 'main.dart')) .createSync(recursive: true); fakeVmServiceHost = FakeVmServiceHost(requests: []); final MockResidentCompiler residentCompiler = MockResidentCompiler(); residentRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); when(mockFlutterDevice.generator).thenReturn(residentCompiler); when(residentCompiler.recompile( any, any, outputPath: anyNamed('outputPath'), packageConfig: anyNamed('packageConfig'), suppressErrors: true, projectRootPath: anyNamed('projectRootPath'), fs: anyNamed('fs'), )).thenAnswer((Invocation invocation) async { return const CompilerOutput('foo', 1 ,[]); }); when(mockFlutterDevice.runHot( hotRunner: anyNamed('hotRunner'), route: anyNamed('route'), )).thenAnswer((Invocation invocation) async { return 0; }); expect(await residentRunner.run(), 1); // Completing this future ensures that the daemon can exit correctly. expect(await residentRunner.waitForAppToFinish(), 1); })); // Regression test for https://github.com/flutter/flutter/issues/60613 testUsingContext('ResidentRunner calls appFailedToStart if initial compilation fails - cold mode', () => testbed.run(() async { globals.fs.file(globals.fs.path.join('lib', 'main.dart')) .createSync(recursive: true); fakeVmServiceHost = FakeVmServiceHost(requests: []); residentRunner = ColdRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.release), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); when(mockFlutterDevice.runCold( coldRunner: anyNamed('coldRunner'), route: anyNamed('route'), )).thenAnswer((Invocation invocation) async { return 1; }); expect(await residentRunner.run(), 1); // Completing this future ensures that the daemon can exit correctly. expect(await residentRunner.waitForAppToFinish(), 1); })); // Regression test for https://github.com/flutter/flutter/issues/60613 testUsingContext('ResidentRunner calls appFailedToStart if exception is thrown - cold mode', () => testbed.run(() async { globals.fs.file(globals.fs.path.join('lib', 'main.dart')) .createSync(recursive: true); fakeVmServiceHost = FakeVmServiceHost(requests: []); residentRunner = ColdRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.release), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); when(mockFlutterDevice.runCold( coldRunner: anyNamed('coldRunner'), route: anyNamed('route'), )).thenAnswer((Invocation invocation) async { throw Exception('BAD STUFF'); }); expect(await residentRunner.run(), 1); // Completing this future ensures that the daemon can exit correctly. expect(await residentRunner.waitForAppToFinish(), 1); })); testUsingContext('ResidentRunner does not suppressErrors if running with an applicationBinary', () => testbed.run(() async { globals.fs.file(globals.fs.path.join('lib', 'main.dart')) .createSync(recursive: true); fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, ]); final MockResidentCompiler residentCompiler = MockResidentCompiler(); residentRunner = HotRunner( [ mockFlutterDevice, ], applicationBinary: globals.fs.file('app.apk'), stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); when(mockFlutterDevice.generator).thenReturn(residentCompiler); when(residentCompiler.recompile( any, any, outputPath: anyNamed('outputPath'), packageConfig: anyNamed('packageConfig'), projectRootPath: anyNamed('projectRootPath'), fs: anyNamed('fs'), suppressErrors: false, )).thenAnswer((Invocation invocation) async { return const CompilerOutput('foo', 0, []); }); when(mockFlutterDevice.runHot( hotRunner: anyNamed('hotRunner'), route: anyNamed('route'), )).thenAnswer((Invocation invocation) async { return 0; }); expect(await residentRunner.run(enableDevTools: true), 0); verify(residentCompiler.recompile( any, any, outputPath: anyNamed('outputPath'), packageConfig: anyNamed('packageConfig'), suppressErrors: false, projectRootPath: anyNamed('projectRootPath'), fs: anyNamed('fs'), )).called(1); expect(fakeVmServiceHost.hasRemainingExpectations, false); })); testUsingContext('ResidentRunner can attach to device successfully with --fast-start', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, listViews, FakeVmServiceRequest( method: 'getIsolate', args: { 'isolateId': fakeUnpausedIsolate.id, }, jsonResponse: fakeUnpausedIsolate.toJson(), ), FakeVmServiceRequest( method: 'getVM', jsonResponse: vm_service.VM.parse({}).toJson(), ), listViews, const FakeVmServiceRequest( method: 'streamListen', args: { 'streamId': 'Isolate', } ), FakeVmServiceRequest( method: kRunInViewMethod, args: { 'viewId': fakeFlutterView.id, 'mainScript': 'main.dart.dill', 'assetDirectory': 'build/flutter_assets', } ), FakeVmServiceStreamResponse( streamId: 'Isolate', event: vm_service.Event( timestamp: 0, kind: vm_service.EventKind.kIsolateRunnable, ) ), ]); residentRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled( BuildInfo.debug, fastStart: true, startPaused: true, ), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); final Completer futureConnectionInfo = Completer.sync(); final Completer futureAppStart = Completer.sync(); final Future result = residentRunner.attach( appStartedCompleter: futureAppStart, connectionInfoCompleter: futureConnectionInfo, enableDevTools: true, ); final Future connectionInfo = futureConnectionInfo.future; expect(await result, 0); verify(mockFlutterDevice.initLogReader()).called(1); expect(futureConnectionInfo.isCompleted, true); expect((await connectionInfo).baseUri, 'foo://bar'); expect(futureAppStart.isCompleted, true); expect(fakeVmServiceHost.hasRemainingExpectations, false); })); testUsingContext('ResidentRunner can handle an RPC exception from hot reload', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, listViews, ]); final Completer futureConnectionInfo = Completer.sync(); final Completer futureAppStart = Completer.sync(); unawaited(residentRunner.attach( appStartedCompleter: futureAppStart, connectionInfoCompleter: futureConnectionInfo, enableDevTools: true, )); await futureAppStart.future; when(mockFlutterDevice.updateDevFS( mainUri: anyNamed('mainUri'), target: anyNamed('target'), bundle: anyNamed('bundle'), firstBuildTime: anyNamed('firstBuildTime'), bundleFirstUpload: anyNamed('bundleFirstUpload'), bundleDirty: anyNamed('bundleDirty'), fullRestart: anyNamed('fullRestart'), projectRootPath: anyNamed('projectRootPath'), pathToReload: anyNamed('pathToReload'), invalidatedFiles: anyNamed('invalidatedFiles'), dillOutputPath: anyNamed('dillOutputPath'), packageConfig: anyNamed('packageConfig'), )).thenThrow(vm_service.RPCError('something bad happened', 666, '')); final OperationResult result = await residentRunner.restart(fullRestart: false); expect(result.fatal, true); expect(result.code, 1); expect((globals.flutterUsage as TestUsage).events, contains( TestUsageEvent('hot', 'exception', parameters: CustomDimensions( hotEventTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm), hotEventSdkName: 'Android', hotEventEmulator: false, hotEventFullRestart: false, )), )); expect(fakeVmServiceHost.hasRemainingExpectations, false); }, overrides: { Usage: () => TestUsage(), })); testUsingContext('ResidentRunner fails its operation if the device initialization is not complete', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, ]); final Completer futureConnectionInfo = Completer.sync(); final Completer futureAppStart = Completer.sync(); unawaited(residentRunner.attach( appStartedCompleter: futureAppStart, connectionInfoCompleter: futureConnectionInfo, )); await futureAppStart.future; when(mockFlutterDevice.devFS).thenReturn(null); final OperationResult result = await residentRunner.restart(fullRestart: false); expect(result.fatal, false); expect(result.code, 1); expect(result.message, contains('Device initialization has not completed.')); expect(fakeVmServiceHost.hasRemainingExpectations, false); })); testUsingContext('ResidentRunner can handle an reload-barred exception from hot reload', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, listViews, ]); final Completer futureConnectionInfo = Completer.sync(); final Completer futureAppStart = Completer.sync(); unawaited(residentRunner.attach( appStartedCompleter: futureAppStart, connectionInfoCompleter: futureConnectionInfo, enableDevTools: true, )); await futureAppStart.future; when(mockFlutterDevice.updateDevFS( mainUri: anyNamed('mainUri'), target: anyNamed('target'), bundle: anyNamed('bundle'), firstBuildTime: anyNamed('firstBuildTime'), bundleFirstUpload: anyNamed('bundleFirstUpload'), bundleDirty: anyNamed('bundleDirty'), fullRestart: anyNamed('fullRestart'), projectRootPath: anyNamed('projectRootPath'), pathToReload: anyNamed('pathToReload'), invalidatedFiles: anyNamed('invalidatedFiles'), dillOutputPath: anyNamed('dillOutputPath'), packageConfig: anyNamed('packageConfig'), )).thenThrow(vm_service.RPCError('something bad happened', kIsolateReloadBarred, '')); final OperationResult result = await residentRunner.restart(fullRestart: false); expect(result.fatal, true); expect(result.code, kIsolateReloadBarred); expect(result.message, contains('Unable to hot reload application due to an unrecoverable error')); expect((globals.flutterUsage as TestUsage).events, contains( TestUsageEvent('hot', 'reload-barred', parameters: CustomDimensions( hotEventTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm), hotEventSdkName: 'Android', hotEventEmulator: false, hotEventFullRestart: false, )), )); expect(fakeVmServiceHost.hasRemainingExpectations, false); }, overrides: { Usage: () => TestUsage(), })); testUsingContext('ResidentRunner reports hot reload event with null safety analytics', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, listViews, ]); residentRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, target: 'main.dart', debuggingOptions: DebuggingOptions.enabled(const BuildInfo( BuildMode.debug, '', treeShakeIcons: false, extraFrontEndOptions: [ '--enable-experiment=non-nullable', ], )), devtoolsHandler: createNoOpHandler, ); final Completer futureConnectionInfo = Completer.sync(); final Completer futureAppStart = Completer.sync(); unawaited(residentRunner.attach( appStartedCompleter: futureAppStart, connectionInfoCompleter: futureConnectionInfo, enableDevTools: true, )); await futureAppStart.future; when(mockFlutterDevice.updateDevFS( mainUri: anyNamed('mainUri'), target: anyNamed('target'), bundle: anyNamed('bundle'), firstBuildTime: anyNamed('firstBuildTime'), bundleFirstUpload: anyNamed('bundleFirstUpload'), bundleDirty: anyNamed('bundleDirty'), fullRestart: anyNamed('fullRestart'), projectRootPath: anyNamed('projectRootPath'), pathToReload: anyNamed('pathToReload'), invalidatedFiles: anyNamed('invalidatedFiles'), dillOutputPath: anyNamed('dillOutputPath'), packageConfig: anyNamed('packageConfig'), )).thenThrow(vm_service.RPCError('something bad happened', 666, '')); final OperationResult result = await residentRunner.restart(fullRestart: false); expect(result.fatal, true); expect(result.code, 1); expect((globals.flutterUsage as TestUsage).events, contains( TestUsageEvent('hot', 'exception', parameters: CustomDimensions( hotEventTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm), hotEventSdkName: 'Android', hotEventEmulator: false, hotEventFullRestart: false, )), )); expect(fakeVmServiceHost.hasRemainingExpectations, false); }, overrides: { Usage: () => TestUsage(), })); testUsingContext('ResidentRunner does not reload sources if no sources changed', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, listViews, FakeVmServiceRequest( method: 'getIsolate', args: { 'isolateId': '1', }, jsonResponse: fakeUnpausedIsolate.toJson(), ), FakeVmServiceRequest( method: 'ext.flutter.reassemble', args: { 'isolateId': fakeUnpausedIsolate.id, }, ), ]); residentRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); final Completer futureConnectionInfo = Completer.sync(); final Completer futureAppStart = Completer.sync(); unawaited(residentRunner.attach( appStartedCompleter: futureAppStart, connectionInfoCompleter: futureConnectionInfo, enableDevTools: true, )); await futureAppStart.future; when(mockFlutterDevice.updateDevFS( mainUri: anyNamed('mainUri'), target: anyNamed('target'), bundle: anyNamed('bundle'), firstBuildTime: anyNamed('firstBuildTime'), bundleFirstUpload: anyNamed('bundleFirstUpload'), bundleDirty: anyNamed('bundleDirty'), fullRestart: anyNamed('fullRestart'), projectRootPath: anyNamed('projectRootPath'), pathToReload: anyNamed('pathToReload'), invalidatedFiles: anyNamed('invalidatedFiles'), dillOutputPath: anyNamed('dillOutputPath'), packageConfig: anyNamed('packageConfig'), )).thenAnswer((Invocation _) async { return UpdateFSReport(success: true, invalidatedSourcesCount: 0); }); final OperationResult result = await residentRunner.restart(fullRestart: false); expect(result.code, 0); expect(fakeVmServiceHost.hasRemainingExpectations, false); })); testUsingContext('ResidentRunner reports error with missing entrypoint file', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, listViews, FakeVmServiceRequest( method: 'getVM', jsonResponse: vm_service.VM.parse({ 'isolates': [ fakeUnpausedIsolate.toJson(), ], }).toJson(), ), const FakeVmServiceRequest( method: 'reloadSources', args: { 'isolateId': '1', 'pause': false, 'rootLibUri': 'main.dart.incremental.dill' }, jsonResponse: { 'type': 'ReloadReport', 'success': true, 'details': { 'loadedLibraryCount': 1, }, }, ), FakeVmServiceRequest( method: 'getIsolate', args: { 'isolateId': '1', }, jsonResponse: fakeUnpausedIsolate.toJson(), ), FakeVmServiceRequest( method: 'ext.flutter.reassemble', args: { 'isolateId': fakeUnpausedIsolate.id, }, ), ]); final Completer futureConnectionInfo = Completer.sync(); final Completer futureAppStart = Completer.sync(); unawaited(residentRunner.attach( appStartedCompleter: futureAppStart, connectionInfoCompleter: futureConnectionInfo, enableDevTools: true, )); await futureAppStart.future; when(mockFlutterDevice.updateDevFS( mainUri: anyNamed('mainUri'), target: anyNamed('target'), bundle: anyNamed('bundle'), firstBuildTime: anyNamed('firstBuildTime'), bundleFirstUpload: anyNamed('bundleFirstUpload'), bundleDirty: anyNamed('bundleDirty'), fullRestart: anyNamed('fullRestart'), projectRootPath: anyNamed('projectRootPath'), pathToReload: anyNamed('pathToReload'), invalidatedFiles: anyNamed('invalidatedFiles'), dillOutputPath: anyNamed('dillOutputPath'), packageConfig: anyNamed('packageConfig'), )).thenAnswer((Invocation invocation) async { return UpdateFSReport(success: true, invalidatedSourcesCount: 1); }); final OperationResult result = await residentRunner.restart(fullRestart: false); expect(globals.fs.file(globals.fs.path.join('lib', 'main.dart')), isNot(exists)); expect(testLogger.errorText, contains('The entrypoint file (i.e. the file with main())')); expect(result.fatal, false); expect(result.code, 0); })); testUsingContext('ResidentRunner resets compilation time on reload reject', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, listViews, FakeVmServiceRequest( method: 'getVM', jsonResponse: vm_service.VM.parse({ 'isolates': [ fakeUnpausedIsolate.toJson(), ], }).toJson(), ), const FakeVmServiceRequest( method: 'reloadSources', args: { 'isolateId': '1', 'pause': false, 'rootLibUri': 'main.dart.incremental.dill' }, jsonResponse: { 'type': 'ReloadReport', 'success': false, 'notices': [ { 'message': 'Failed to hot reload' } ], 'details': {}, }, ), listViews, FakeVmServiceRequest( method: 'getIsolate', args: { 'isolateId': '1', }, jsonResponse: fakeUnpausedIsolate.toJson(), ), FakeVmServiceRequest( method: 'ext.flutter.reassemble', args: { 'isolateId': fakeUnpausedIsolate.id, }, ), ]); final Completer futureConnectionInfo = Completer.sync(); final Completer futureAppStart = Completer.sync(); unawaited(residentRunner.attach( appStartedCompleter: futureAppStart, connectionInfoCompleter: futureConnectionInfo, enableDevTools: true, )); await futureAppStart.future; when(mockFlutterDevice.updateDevFS( mainUri: anyNamed('mainUri'), target: anyNamed('target'), bundle: anyNamed('bundle'), firstBuildTime: anyNamed('firstBuildTime'), bundleFirstUpload: anyNamed('bundleFirstUpload'), bundleDirty: anyNamed('bundleDirty'), fullRestart: anyNamed('fullRestart'), projectRootPath: anyNamed('projectRootPath'), pathToReload: anyNamed('pathToReload'), invalidatedFiles: anyNamed('invalidatedFiles'), dillOutputPath: anyNamed('dillOutputPath'), packageConfig: anyNamed('packageConfig'), )).thenAnswer((Invocation invocation) async { return UpdateFSReport(success: true, invalidatedSourcesCount: 1); }); final OperationResult result = await residentRunner.restart(fullRestart: false); expect(result.fatal, false); expect(result.message, contains('Reload rejected: Failed to hot reload')); // contains error message from reload report. expect(result.code, 1); expect(mockDevFS.lastCompiled, null); })); testUsingContext('ResidentRunner can send target platform to analytics from hot reload', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, listViews, FakeVmServiceRequest( method: 'getVM', jsonResponse: vm_service.VM.parse({ 'isolates': [ fakeUnpausedIsolate.toJson(), ], }).toJson(), ), const FakeVmServiceRequest( method: 'reloadSources', args: { 'isolateId': '1', 'pause': false, 'rootLibUri': 'main.dart.incremental.dill' }, jsonResponse: { 'type': 'ReloadReport', 'success': true, 'details': { 'loadedLibraryCount': 1, }, }, ), FakeVmServiceRequest( method: 'getIsolate', args: { 'isolateId': '1', }, jsonResponse: fakeUnpausedIsolate.toJson(), ), FakeVmServiceRequest( method: 'ext.flutter.reassemble', args: { 'isolateId': fakeUnpausedIsolate.id, }, ), ]); final Completer futureConnectionInfo = Completer.sync(); final Completer futureAppStart = Completer.sync(); unawaited(residentRunner.attach( appStartedCompleter: futureAppStart, connectionInfoCompleter: futureConnectionInfo, enableDevTools: true, )); await futureAppStart.future; final OperationResult result = await residentRunner.restart(fullRestart: false); expect(result.fatal, false); expect(result.code, 0); final TestUsageEvent event = (globals.flutterUsage as TestUsage).events.first; expect(event.category, 'hot'); expect(event.parameter, 'reload'); expect(event.parameters.hotEventTargetPlatform, getNameForTargetPlatform(TargetPlatform.android_arm)); }, overrides: { Usage: () => TestUsage(), })); testUsingContext('ResidentRunner can perform fast reassemble', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, FakeVmServiceRequest( method: 'getVM', jsonResponse: fakeVM.toJson(), ), listViews, setAssetBundlePath, listViews, FakeVmServiceRequest( method: 'getVM', jsonResponse: fakeVM.toJson(), ), const FakeVmServiceRequest( method: 'reloadSources', args: { 'isolateId': '1', 'pause': false, 'rootLibUri': 'main.dart.incremental.dill', }, jsonResponse: { 'type': 'ReloadReport', 'success': true, 'details': { 'loadedLibraryCount': 1, }, }, ), FakeVmServiceRequest( method: 'getIsolate', args: { 'isolateId': '1', }, jsonResponse: fakeUnpausedIsolate.toJson(), ), FakeVmServiceRequest( method: 'ext.flutter.fastReassemble', args: { 'isolateId': fakeUnpausedIsolate.id, 'className': 'FOO', }, ), ]); final FakeFlutterDevice flutterDevice = FakeFlutterDevice( mockDevice, BuildInfo.debug, FakeResidentCompiler(), mockDevFS, )..vmService = fakeVmServiceHost.vmService; residentRunner = HotRunner( [ flutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); mockDevFS.nextUpdateReport = UpdateFSReport( success: true, fastReassembleClassName: 'FOO', invalidatedSourcesCount: 1, ); final Completer futureConnectionInfo = Completer.sync(); final Completer futureAppStart = Completer.sync(); unawaited(residentRunner.attach( appStartedCompleter: futureAppStart, connectionInfoCompleter: futureConnectionInfo, enableDevTools: true, )); await futureAppStart.future; final OperationResult result = await residentRunner.restart(fullRestart: false); expect(result.fatal, false); expect(result.code, 0); final TestUsageEvent event = (globals.flutterUsage as TestUsage).events.first; expect(event.category, 'hot'); expect(event.parameter, 'reload'); expect(event.parameters.fastReassemble, true); }, overrides: { FileSystem: () => MemoryFileSystem.test(), Platform: () => FakePlatform(operatingSystem: 'linux'), ProjectFileInvalidator: () => FakeProjectFileInvalidator(), Usage: () => TestUsage(), FeatureFlags: () => TestFeatureFlags(isSingleWidgetReloadEnabled: true), })); testUsingContext('ResidentRunner can send target platform to analytics from full restart', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, listViews, setAssetBundlePath, FakeVmServiceRequest( method: 'getIsolate', args: { 'isolateId': fakeUnpausedIsolate.id, }, jsonResponse: fakeUnpausedIsolate.toJson(), ), FakeVmServiceRequest( method: 'getVM', jsonResponse: vm_service.VM.parse({}).toJson(), ), listViews, const FakeVmServiceRequest( method: 'streamListen', args: { 'streamId': 'Isolate', }, ), FakeVmServiceRequest( method: kRunInViewMethod, args: { 'viewId': fakeFlutterView.id, 'mainScript': 'main.dart.dill', 'assetDirectory': 'build/flutter_assets', }, ), FakeVmServiceStreamResponse( streamId: 'Isolate', event: vm_service.Event( timestamp: 0, kind: vm_service.EventKind.kIsolateRunnable, ) ) ]); final Completer futureConnectionInfo = Completer.sync(); final Completer futureAppStart = Completer.sync(); unawaited(residentRunner.attach( appStartedCompleter: futureAppStart, connectionInfoCompleter: futureConnectionInfo, enableDevTools: true, )); final OperationResult result = await residentRunner.restart(fullRestart: true); expect(result.fatal, false); expect(result.code, 0); final TestUsageEvent event = (globals.flutterUsage as TestUsage).events.first; expect(event.category, 'hot'); expect(event.parameter, 'restart'); expect(event.parameters.hotEventTargetPlatform, getNameForTargetPlatform(TargetPlatform.android_arm)); expect(fakeVmServiceHost.hasRemainingExpectations, false); }, overrides: { Usage: () => TestUsage(), })); testUsingContext('ResidentRunner can remove breakpoints from paused isolate during hot restart', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, listViews, setAssetBundlePath, FakeVmServiceRequest( method: 'getIsolate', args: { 'isolateId': fakeUnpausedIsolate.id, }, jsonResponse: fakePausedIsolate.toJson(), ), FakeVmServiceRequest( method: 'getVM', jsonResponse: vm_service.VM.parse({}).toJson(), ), const FakeVmServiceRequest( method: 'removeBreakpoint', args: { 'isolateId': '1', 'breakpointId': 'test-breakpoint', } ), const FakeVmServiceRequest( method: 'resume', args: { 'isolateId': '1', } ), listViews, const FakeVmServiceRequest( method: 'streamListen', args: { 'streamId': 'Isolate', }, ), FakeVmServiceRequest( method: kRunInViewMethod, args: { 'viewId': fakeFlutterView.id, 'mainScript': 'main.dart.dill', 'assetDirectory': 'build/flutter_assets', }, ), FakeVmServiceStreamResponse( streamId: 'Isolate', event: vm_service.Event( timestamp: 0, kind: vm_service.EventKind.kIsolateRunnable, ) ) ]); final Completer futureConnectionInfo = Completer.sync(); final Completer futureAppStart = Completer.sync(); unawaited(residentRunner.attach( appStartedCompleter: futureAppStart, connectionInfoCompleter: futureConnectionInfo, enableDevTools: true, )); final OperationResult result = await residentRunner.restart(fullRestart: true); expect(result.isOk, true); expect(fakeVmServiceHost.hasRemainingExpectations, false); })); testUsingContext('ResidentRunner will alternative the name of the dill file uploaded for a hot restart', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, listViews, setAssetBundlePath, FakeVmServiceRequest( method: 'getIsolate', args: { 'isolateId': fakeUnpausedIsolate.id, }, jsonResponse: fakeUnpausedIsolate.toJson(), ), FakeVmServiceRequest( method: 'getVM', jsonResponse: vm_service.VM.parse({}).toJson(), ), listViews, const FakeVmServiceRequest( method: 'streamListen', args: { 'streamId': 'Isolate', }, ), FakeVmServiceRequest( method: kRunInViewMethod, args: { 'viewId': fakeFlutterView.id, 'mainScript': 'main.dart.dill', 'assetDirectory': 'build/flutter_assets', }, ), FakeVmServiceStreamResponse( streamId: 'Isolate', event: vm_service.Event( timestamp: 0, kind: vm_service.EventKind.kIsolateRunnable, ), ), listViews, FakeVmServiceRequest( method: 'getIsolate', args: { 'isolateId': fakeUnpausedIsolate.id, }, jsonResponse: fakeUnpausedIsolate.toJson(), ), FakeVmServiceRequest( method: 'getVM', jsonResponse: vm_service.VM.parse({}).toJson(), ), listViews, const FakeVmServiceRequest( method: 'streamListen', args: { 'streamId': 'Isolate', }, ), FakeVmServiceRequest( method: kRunInViewMethod, args: { 'viewId': fakeFlutterView.id, 'mainScript': 'main.dart.swap.dill', 'assetDirectory': 'build/flutter_assets', }, ), FakeVmServiceStreamResponse( streamId: 'Isolate', event: vm_service.Event( timestamp: 0, kind: vm_service.EventKind.kIsolateRunnable, ), ), listViews, FakeVmServiceRequest( method: 'getIsolate', args: { 'isolateId': fakeUnpausedIsolate.id, }, jsonResponse: fakeUnpausedIsolate.toJson(), ), FakeVmServiceRequest( method: 'getVM', jsonResponse: vm_service.VM.parse({}).toJson(), ), listViews, const FakeVmServiceRequest( method: 'streamListen', args: { 'streamId': 'Isolate', }, ), FakeVmServiceRequest( method: kRunInViewMethod, args: { 'viewId': fakeFlutterView.id, 'mainScript': 'main.dart.dill', 'assetDirectory': 'build/flutter_assets', }, ), FakeVmServiceStreamResponse( streamId: 'Isolate', event: vm_service.Event( timestamp: 0, kind: vm_service.EventKind.kIsolateRunnable, ), ) ]); final Completer futureConnectionInfo = Completer.sync(); final Completer futureAppStart = Completer.sync(); unawaited(residentRunner.attach( appStartedCompleter: futureAppStart, connectionInfoCompleter: futureConnectionInfo, enableDevTools: true, )); await residentRunner.restart(fullRestart: true); await residentRunner.restart(fullRestart: true); await residentRunner.restart(fullRestart: true); expect(fakeVmServiceHost.hasRemainingExpectations, false); })); testUsingContext('ResidentRunner Can handle an RPC exception from hot restart', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, ]); final Completer futureConnectionInfo = Completer.sync(); final Completer futureAppStart = Completer.sync(); unawaited(residentRunner.attach( appStartedCompleter: futureAppStart, connectionInfoCompleter: futureConnectionInfo, enableDevTools: true, )); await futureAppStart.future; when(mockFlutterDevice.updateDevFS( mainUri: anyNamed('mainUri'), target: anyNamed('target'), bundle: anyNamed('bundle'), firstBuildTime: anyNamed('firstBuildTime'), bundleFirstUpload: anyNamed('bundleFirstUpload'), bundleDirty: anyNamed('bundleDirty'), fullRestart: anyNamed('fullRestart'), projectRootPath: anyNamed('projectRootPath'), pathToReload: anyNamed('pathToReload'), invalidatedFiles: anyNamed('invalidatedFiles'), dillOutputPath: anyNamed('dillOutputPath'), packageConfig: anyNamed('packageConfig'), )).thenThrow(vm_service.RPCError('something bad happened', 666, '')); final OperationResult result = await residentRunner.restart(fullRestart: true); expect(result.fatal, true); expect(result.code, 1); expect((globals.flutterUsage as TestUsage).events, contains( TestUsageEvent('hot', 'exception', parameters: CustomDimensions( hotEventTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm), hotEventSdkName: 'Android', hotEventEmulator: false, hotEventFullRestart: true, )), )); expect(fakeVmServiceHost.hasRemainingExpectations, false); }, overrides: { Usage: () => TestUsage(), })); testUsingContext('ResidentRunner uses temp directory when there is no output dill path', () => testbed.run(() { fakeVmServiceHost = FakeVmServiceHost(requests: []); expect(residentRunner.artifactDirectory.path, contains('flutter_tool.')); final ResidentRunner otherRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), dillOutputPath: globals.fs.path.join('foobar', 'app.dill'), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); expect(otherRunner.artifactDirectory.path, contains('foobar')); })); testUsingContext('ResidentRunner deletes artifact directory on preExit', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: []); residentRunner.artifactDirectory.childFile('app.dill').createSync(); await residentRunner.preExit(); expect(residentRunner.artifactDirectory, isNot(exists)); })); testUsingContext('ResidentRunner can run source generation', () => testbed.run(() async { final File arbFile = globals.fs.file(globals.fs.path.join('lib', 'l10n', 'app_en.arb')) ..createSync(recursive: true); arbFile.writeAsStringSync(''' { "helloWorld": "Hello, World!", "@helloWorld": { "description": "Sample description" } }'''); globals.fs.file('l10n.yaml').createSync(); globals.fs.file('pubspec.yaml').writeAsStringSync('flutter:\n generate: true\n'); // Create necessary files for [DartPluginRegistrantTarget] final File packageConfig = globals.fs.directory('.dart_tool') .childFile('package_config.json'); packageConfig.createSync(recursive: true); packageConfig.writeAsStringSync(''' { "configVersion": 2, "packages": [ { "name": "path_provider_linux", "rootUri": "../../../path_provider_linux", "packageUri": "lib/", "languageVersion": "2.12" } ] } '''); // Start from an empty generated_main.dart file. globals.fs.directory('.dart_tool').childDirectory('flutter_build').childFile('generated_main.dart').createSync(recursive: true); await residentRunner.runSourceGenerators(); expect(testLogger.errorText, isEmpty); expect(testLogger.statusText, isEmpty); })); testUsingContext('ResidentRunner can run source generation - generation fails', () => testbed.run(() async { // Intentionally define arb file with wrong name. generate_localizations defaults // to app_en.arb. final File arbFile = globals.fs.file(globals.fs.path.join('lib', 'l10n', 'foo.arb')) ..createSync(recursive: true); arbFile.writeAsStringSync(''' { "helloWorld": "Hello, World!", "@helloWorld": { "description": "Sample description" } }'''); globals.fs.file('l10n.yaml').createSync(); globals.fs.file('pubspec.yaml').writeAsStringSync('flutter:\n generate: true\n'); await residentRunner.runSourceGenerators(); expect(testLogger.errorText, allOf(contains('Exception'))); expect(testLogger.statusText, isEmpty); })); testUsingContext('ResidentRunner printHelpDetails hot runner', () => testbed.run(() { fakeVmServiceHost = FakeVmServiceHost(requests: []); residentRunner.printHelp(details: true); final CommandHelp commandHelp = residentRunner.commandHelp; // supports service protocol expect(residentRunner.supportsServiceProtocol, true); // isRunningDebug expect(residentRunner.isRunningDebug, true); // does support SkSL expect(residentRunner.supportsWriteSkSL, true); // commands expect(testLogger.statusText, equals( [ 'Flutter run key commands.', commandHelp.r, commandHelp.R, commandHelp.v, commandHelp.s, commandHelp.w, commandHelp.t, commandHelp.L, commandHelp.S, commandHelp.U, commandHelp.i, commandHelp.p, commandHelp.I, commandHelp.o, commandHelp.b, commandHelp.z, commandHelp.P, commandHelp.a, commandHelp.M, commandHelp.g, commandHelp.hWithDetails, commandHelp.c, commandHelp.q, '', '💪 Running with sound null safety 💪', '', 'An Observatory debugger and profiler on FakeDevice is available at: null', '', ].join('\n') )); })); testUsingContext('ResidentRunner printHelp hot runner', () => testbed.run(() { fakeVmServiceHost = FakeVmServiceHost(requests: []); residentRunner.printHelp(details: false); final CommandHelp commandHelp = residentRunner.commandHelp; // supports service protocol expect(residentRunner.supportsServiceProtocol, true); // isRunningDebug expect(residentRunner.isRunningDebug, true); // does support SkSL expect(residentRunner.supportsWriteSkSL, true); // commands expect(testLogger.statusText, equals( [ 'Flutter run key commands.', commandHelp.r, commandHelp.R, commandHelp.hWithoutDetails, commandHelp.c, commandHelp.q, '', '💪 Running with sound null safety 💪', '', 'An Observatory debugger and profiler on FakeDevice is available at: null', '', ].join('\n') )); })); testUsingContext('ResidentRunner printHelpDetails cold runner', () => testbed.run(() { fakeVmServiceHost = null; residentRunner = ColdRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); residentRunner.printHelp(details: true); final CommandHelp commandHelp = residentRunner.commandHelp; // does not supports service protocol expect(residentRunner.supportsServiceProtocol, false); // isRunningDebug expect(residentRunner.isRunningDebug, false); // does support SkSL expect(residentRunner.supportsWriteSkSL, false); // commands expect(testLogger.statusText, equals( [ 'Flutter run key commands.', commandHelp.v, commandHelp.s, commandHelp.hWithDetails, commandHelp.c, commandHelp.q, '' ].join('\n') )); })); testUsingContext('ResidentRunner printHelp cold runner', () => testbed.run(() { fakeVmServiceHost = null; residentRunner = ColdRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); residentRunner.printHelp(details: false); final CommandHelp commandHelp = residentRunner.commandHelp; // does not supports service protocol expect(residentRunner.supportsServiceProtocol, false); // isRunningDebug expect(residentRunner.isRunningDebug, false); // does support SkSL expect(residentRunner.supportsWriteSkSL, false); // commands expect(testLogger.statusText, equals( [ 'Flutter run key commands.', commandHelp.hWithoutDetails, commandHelp.c, commandHelp.q, '' ].join('\n') )); })); testUsingContext('ResidentRunner handles writeSkSL returning no data', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, FakeVmServiceRequest( method: kGetSkSLsMethod, args: { 'viewId': fakeFlutterView.id, }, jsonResponse: { 'SkSLs': {} } ), ]); await residentRunner.writeSkSL(); expect(testLogger.statusText, contains('No data was received')); expect(fakeVmServiceHost.hasRemainingExpectations, false); })); testUsingContext('ResidentRunner can write SkSL data to a unique file with engine revision, platform, and device name', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, FakeVmServiceRequest( method: kGetSkSLsMethod, args: { 'viewId': fakeFlutterView.id, }, jsonResponse: { 'SkSLs': { 'A': 'B', } } ) ]); await residentRunner.writeSkSL(); expect(testLogger.statusText, contains('flutter_01.sksl.json')); expect(globals.fs.file('flutter_01.sksl.json'), exists); expect(json.decode(globals.fs.file('flutter_01.sksl.json').readAsStringSync()), { 'platform': 'android', 'name': 'FakeDevice', 'engineRevision': 'abcdefg', 'data': {'A': 'B'} }); expect(fakeVmServiceHost.hasRemainingExpectations, false); }, overrides: { FileSystemUtils: () => FileSystemUtils( fileSystem: globals.fs, platform: globals.platform, ), FlutterVersion: () => FakeFlutterVersion(engineRevision: 'abcdefg') })); testUsingContext('ResidentRunner ignores DevtoolsLauncher when attaching with enableDevTools: false - cold mode', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, ]); residentRunner = ColdRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile, vmserviceOutFile: 'foo'), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); when(mockFlutterDevice.runCold( coldRunner: anyNamed('coldRunner'), route: anyNamed('route'), )).thenAnswer((Invocation invocation) async { return 0; }); final Future result = residentRunner.attach(enableDevTools: false); expect(await result, 0); })); testUsingContext('FlutterDevice will not exit a paused isolate', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ FakeVmServiceRequest( method: '_flutter.listViews', jsonResponse: { 'views': [ fakeFlutterView.toJson(), ], }, ), FakeVmServiceRequest( method: 'getIsolate', args: { 'isolateId': fakeUnpausedIsolate.id, }, jsonResponse: fakePausedIsolate.toJson(), ), ]); final TestFlutterDevice flutterDevice = TestFlutterDevice( mockDevice, ); flutterDevice.vmService = fakeVmServiceHost.vmService; await flutterDevice.exitApps(); expect(mockDevice.appStopped, true); expect(fakeVmServiceHost.hasRemainingExpectations, false); })); testUsingContext('FlutterDevice will exit an isolate that did not register the exit extension method', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ FakeVmServiceRequest( method: '_flutter.listViews', jsonResponse: { 'views': [ fakeFlutterView.toJson(), ], }, ), FakeVmServiceRequest( method: 'getIsolate', args: { 'isolateId': fakeUnpausedIsolate.id, }, jsonResponse: fakeUnpausedIsolate.toJson(), ), FakeVmServiceRequest( method: 'ext.flutter.exit', args: { 'isolateId': fakeUnpausedIsolate.id, }, errorCode: RPCErrorCodes.kMethodNotFound, ), ]); final TestFlutterDevice flutterDevice = TestFlutterDevice( mockDevice, ); flutterDevice.vmService = fakeVmServiceHost.vmService; await flutterDevice.exitApps(timeoutDelay: Duration.zero); expect(mockDevice.appStopped, true); expect(fakeVmServiceHost.hasRemainingExpectations, false); })); testUsingContext('FlutterDevice can exit from a release mode isolate with no VmService', () => testbed.run(() async { final TestFlutterDevice flutterDevice = TestFlutterDevice( mockDevice, ); await flutterDevice.exitApps(); expect(mockDevice.appStopped, true); })); testUsingContext('FlutterDevice will call stopApp if the exit request times out', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ FakeVmServiceRequest( method: '_flutter.listViews', jsonResponse: { 'views': [ fakeFlutterView.toJson(), ], }, ), FakeVmServiceRequest( method: 'getIsolate', args: { 'isolateId': fakeUnpausedIsolate.id, }, jsonResponse: fakeUnpausedIsolate.toJson(), ), FakeVmServiceRequest( method: 'ext.flutter.exit', args: { 'isolateId': fakeUnpausedIsolate.id, }, // Intentionally do not close isolate. close: false, ) ]); final TestFlutterDevice flutterDevice = TestFlutterDevice( mockDevice, ); flutterDevice.vmService = fakeVmServiceHost.vmService; await flutterDevice.exitApps( timeoutDelay: Duration.zero, ); expect(mockDevice.appStopped, true); expect(fakeVmServiceHost.hasRemainingExpectations, false); })); testUsingContext('FlutterDevice will exit an un-paused isolate', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ FakeVmServiceRequest( method: kListViewsMethod, jsonResponse: { 'views': [ fakeFlutterView.toJson(), ], }, ), FakeVmServiceRequest( method: 'getIsolate', args: { 'isolateId': fakeUnpausedIsolate.id }, jsonResponse: fakeUnpausedIsolate.toJson(), ), FakeVmServiceRequest( method: 'ext.flutter.exit', args: { 'isolateId': fakeUnpausedIsolate.id, }, close: true, ) ]); final TestFlutterDevice flutterDevice = TestFlutterDevice( mockDevice, ); flutterDevice.vmService = fakeVmServiceHost.vmService; final Future exitFuture = flutterDevice.exitApps(); await expectLater(exitFuture, completes); expect(fakeVmServiceHost.hasRemainingExpectations, false); })); testUsingContext('HotRunner writes vm service file when providing debugging option', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, ], wsAddress: testUri); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); residentRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); when(mockFlutterDevice.runHot( hotRunner: anyNamed('hotRunner'), route: anyNamed('route'), )).thenAnswer((Invocation invocation) async { return 0; }); await residentRunner.run(enableDevTools: true); expect(fakeVmServiceHost.hasRemainingExpectations, false); expect(await globals.fs.file('foo').readAsString(), testUri.toString()); })); testUsingContext('HotRunner copies compiled app.dill to cache during startup', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, ], wsAddress: testUri); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); residentRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); when(mockFlutterDevice.runHot( hotRunner: anyNamed('hotRunner'), route: anyNamed('route'), )).thenAnswer((Invocation invocation) async { return 0; }); await residentRunner.run(enableDevTools: true); expect(await globals.fs.file(globals.fs.path.join('build', 'cache.dill')).readAsString(), 'ABC'); })); testUsingContext('HotRunner copies compiled app.dill to cache during startup with dart defines', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, ], wsAddress: testUri); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); residentRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled( const BuildInfo( BuildMode.debug, '', treeShakeIcons: false, dartDefines: ['a', 'b'], ) ), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); when(mockFlutterDevice.runHot( hotRunner: anyNamed('hotRunner'), route: anyNamed('route'), )).thenAnswer((Invocation invocation) async { return 0; }); await residentRunner.run(enableDevTools: true); expect(await globals.fs.file(globals.fs.path.join( 'build', '187ef4436122d1cc2f40dc2b92f0eba0.cache.dill')).readAsString(), 'ABC'); })); testUsingContext('HotRunner copies compiled app.dill to cache during startup with null safety', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, ], wsAddress: testUri); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); residentRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled( const BuildInfo( BuildMode.debug, '', treeShakeIcons: false, extraFrontEndOptions: ['--enable-experiment=non-nullable>'] ) ), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); when(mockFlutterDevice.runHot( hotRunner: anyNamed('hotRunner'), route: anyNamed('route'), )).thenAnswer((Invocation invocation) async { return 0; }); await residentRunner.run(enableDevTools: true); expect(await globals.fs.file(globals.fs.path.join( 'build', '3416d3007730479552122f01c01e326d.cache.dill')).readAsString(), 'ABC'); })); testUsingContext('HotRunner does not copy app.dill if a dillOutputPath is given', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, ], wsAddress: testUri); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); residentRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, dillOutputPath: 'test', debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); when(mockFlutterDevice.runHot( hotRunner: anyNamed('hotRunner'), route: anyNamed('route'), )).thenAnswer((Invocation invocation) async { return 0; }); await residentRunner.run(enableDevTools: true); expect(globals.fs.file(globals.fs.path.join('build', 'cache.dill')), isNot(exists)); })); testUsingContext('HotRunner copies compiled app.dill to cache during startup with --track-widget-creation', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, ], wsAddress: testUri); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); residentRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(const BuildInfo( BuildMode.debug, '', treeShakeIcons: false, trackWidgetCreation: true, )), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); when(mockFlutterDevice.runHot( hotRunner: anyNamed('hotRunner'), route: anyNamed('route'), )).thenAnswer((Invocation invocation) async { return 0; }); await residentRunner.run(enableDevTools: true); expect(await globals.fs.file(globals.fs.path.join('build', 'cache.dill.track.dill')).readAsString(), 'ABC'); })); testUsingContext('HotRunner calls device dispose', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, ], wsAddress: testUri); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); residentRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); when(mockFlutterDevice.runHot( hotRunner: anyNamed('hotRunner'), route: anyNamed('route'), )).thenAnswer((Invocation invocation) async { return 0; }); await residentRunner.run(); expect(mockDevice.disposed, true); })); testUsingContext('HotRunner handles failure to write vmservice file', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, listViews, setAssetBundlePath, ]); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); residentRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); when(mockFlutterDevice.runHot( hotRunner: anyNamed('hotRunner'), route: anyNamed('route'), )).thenAnswer((Invocation invocation) async { return 0; }); await residentRunner.run(enableDevTools: true); expect(testLogger.errorText, contains('Failed to write vmservice-out-file at foo')); expect(fakeVmServiceHost.hasRemainingExpectations, false); }, overrides: { FileSystem: () => ThrowingForwardingFileSystem(MemoryFileSystem.test()), })); testUsingContext('ColdRunner writes vm service file when providing debugging option', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, ], wsAddress: testUri); globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); residentRunner = ColdRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile, vmserviceOutFile: 'foo'), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); when(mockFlutterDevice.runCold( coldRunner: anyNamed('coldRunner'), route: anyNamed('route'), )).thenAnswer((Invocation invocation) async { return 0; }); await residentRunner.run(enableDevTools: true); expect(await globals.fs.file('foo').readAsString(), testUri.toString()); expect(fakeVmServiceHost.hasRemainingExpectations, false); })); testUsingContext('FlutterDevice uses dartdevc configuration when targeting web', () async { fakeVmServiceHost = FakeVmServiceHost(requests: []); final FakeDevice mockDevice = FakeDevice(targetPlatform: TargetPlatform.web_javascript); final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create( mockDevice, buildInfo: const BuildInfo( BuildMode.debug, '', treeShakeIcons: false, nullSafetyMode: NullSafetyMode.unsound, ), target: null, platform: FakePlatform(operatingSystem: 'linux'), )).generator as DefaultResidentCompiler; expect(residentCompiler.initializeFromDill, globals.fs.path.join(getBuildDirectory(), 'fbbe6a61fb7a1de317d381f8df4814e5.cache.dill')); expect(residentCompiler.librariesSpec, globals.fs.file(globals.artifacts.getHostArtifact(HostArtifact.flutterWebLibrariesJson)) .uri.toString()); expect(residentCompiler.targetModel, TargetModel.dartdevc); expect(residentCompiler.sdkRoot, globals.artifacts.getHostArtifact(HostArtifact.flutterWebSdk).path + '/'); expect(residentCompiler.platformDill, 'file:///HostArtifact.webPlatformKernelDill'); }, overrides: { Artifacts: () => Artifacts.test(), FileSystem: () => MemoryFileSystem.test(), ProcessManager: () => FakeProcessManager.any(), }); testUsingContext('FlutterDevice uses dartdevc configuration when targeting web with null-safety autodetected', () async { fakeVmServiceHost = FakeVmServiceHost(requests: []); final FakeDevice mockDevice = FakeDevice(targetPlatform: TargetPlatform.web_javascript); final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create( mockDevice, buildInfo: const BuildInfo( BuildMode.debug, '', treeShakeIcons: false, extraFrontEndOptions: ['--enable-experiment=non-nullable'], ), target: null, platform: FakePlatform(operatingSystem: 'linux'), )).generator as DefaultResidentCompiler; expect(residentCompiler.initializeFromDill, globals.fs.path.join(getBuildDirectory(), '825b8f791aa86c5057fff6f064542c54.cache.dill')); expect(residentCompiler.librariesSpec, globals.fs.file(globals.artifacts.getHostArtifact(HostArtifact.flutterWebLibrariesJson)) .uri.toString()); expect(residentCompiler.targetModel, TargetModel.dartdevc); expect(residentCompiler.sdkRoot, globals.artifacts.getHostArtifact(HostArtifact.flutterWebSdk).path + '/'); expect(residentCompiler.platformDill, 'file:///HostArtifact.webPlatformSoundKernelDill'); }, overrides: { Artifacts: () => Artifacts.test(), FileSystem: () => MemoryFileSystem.test(), ProcessManager: () => FakeProcessManager.any(), }); testUsingContext('FlutterDevice passes flutter-widget-cache flag when feature is enabled', () async { fakeVmServiceHost = FakeVmServiceHost(requests: []); final FakeDevice mockDevice = FakeDevice(targetPlatform: TargetPlatform.android_arm); final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create( mockDevice, buildInfo: const BuildInfo( BuildMode.debug, '', treeShakeIcons: false, extraFrontEndOptions: [], ), target: null, platform: null, )).generator as DefaultResidentCompiler; expect(residentCompiler.extraFrontEndOptions, contains('--flutter-widget-cache')); }, overrides: { Artifacts: () => Artifacts.test(), FileSystem: () => MemoryFileSystem.test(), ProcessManager: () => FakeProcessManager.any(), FeatureFlags: () => TestFeatureFlags(isSingleWidgetReloadEnabled: true) }); testUsingContext('FlutterDevice passes alternative-invalidation-strategy flag when feature is enabled', () async { fakeVmServiceHost = FakeVmServiceHost(requests: []); final FakeDevice mockDevice = FakeDevice(targetPlatform: TargetPlatform.android_arm); final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create( mockDevice, buildInfo: const BuildInfo( BuildMode.debug, '', treeShakeIcons: false, extraFrontEndOptions: [], ), target: null, platform: null, )).generator as DefaultResidentCompiler; expect(residentCompiler.extraFrontEndOptions, contains('--enable-experiment=alternative-invalidation-strategy')); }, overrides: { Artifacts: () => Artifacts.test(), FileSystem: () => MemoryFileSystem.test(), ProcessManager: () => FakeProcessManager.any(), FeatureFlags: () => TestFeatureFlags(isExperimentalInvalidationStrategyEnabled: true) }); testUsingContext('Handle existing VM service clients DDS error', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: []); final FakeDevice mockDevice = FakeDevice() ..dds = DartDevelopmentService(); ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri}) { throw FakeDartDevelopmentServiceException(message: 'Existing VM service clients prevent DDS from taking control.', ); }; final TestFlutterDevice flutterDevice = TestFlutterDevice( mockDevice, observatoryUris: Stream.value(testUri), ); bool caught = false; final Completerdone = Completer(); runZonedGuarded(() { flutterDevice.connect(allowExistingDdsInstance: true).then((_) => done.complete()); }, (Object e, StackTrace st) { expect(e is ToolExit, true); expect((e as ToolExit).message, contains('Existing VM service clients prevent DDS from taking control.', )); done.complete(); caught = true; }); await done.future; if (!caught) { fail('Expected ToolExit to be thrown.'); } }, overrides: { VMServiceConnector: () => (Uri httpUri, { ReloadSources reloadSources, Restart restart, CompileExpression compileExpression, GetSkSLMethod getSkSLMethod, PrintStructuredErrorLogMethod printStructuredErrorLogMethod, io.CompressionOptions compression, Device device, Logger logger, }) async => mockVMService, })); testUsingContext('Failed DDS start outputs error message', () => testbed.run(() async { // See https://github.com/flutter/flutter/issues/72385 for context. fakeVmServiceHost = FakeVmServiceHost(requests: []); final FakeDevice mockDevice = FakeDevice() ..dds = DartDevelopmentService(); ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri}) { throw FakeDartDevelopmentServiceException(message: 'No URI'); }; final TestFlutterDevice flutterDevice = TestFlutterDevice( mockDevice, observatoryUris: Stream.value(testUri), ); bool caught = false; final Completerdone = Completer(); runZonedGuarded(() { flutterDevice.connect(allowExistingDdsInstance: true).then((_) => done.complete()); }, (Object e, StackTrace st) { expect(e is StateError, true); expect((e as StateError).message, contains('No URI')); expect(testLogger.errorText, contains( 'DDS has failed to start and there is not an existing DDS instance', )); done.complete(); caught = true; }); await done.future; if (!caught) { fail('Expected a StateError to be thrown.'); } }, overrides: { VMServiceConnector: () => (Uri httpUri, { ReloadSources reloadSources, Restart restart, CompileExpression compileExpression, GetSkSLMethod getSkSLMethod, PrintStructuredErrorLogMethod printStructuredErrorLogMethod, io.CompressionOptions compression, Device device, Logger logger, }) async => mockVMService, })); testUsingContext('nextPlatform moves through expected platforms', () { expect(nextPlatform('android'), 'iOS'); expect(nextPlatform('iOS'), 'fuchsia'); expect(nextPlatform('fuchsia'), 'macOS'); expect(nextPlatform('macOS'), 'android'); expect(() => nextPlatform('unknown'), throwsAssertionError); }); testUsingContext('cleanupAtFinish shuts down resident devtools handler', () => testbed.run(() async { residentRunner = HotRunner( [ mockFlutterDevice, ], stayResident: false, debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); await residentRunner.cleanupAtFinish(); expect((residentRunner.residentDevtoolsHandler as NoOpDevtoolsHandler).wasShutdown, true); })); } class MockFlutterDevice extends Mock implements FlutterDevice {} class MockVMService extends Mock implements FlutterVmService {} class MockDevFS extends Mock implements DevFS {} class MockResidentCompiler extends Mock implements ResidentCompiler {} class FakeDartDevelopmentServiceException implements dds.DartDevelopmentServiceException { FakeDartDevelopmentServiceException({this.message = defaultMessage}); @override final int errorCode = dds.DartDevelopmentServiceException.existingDdsInstanceError; @override final String message; static const String defaultMessage = 'A DDS instance is already connected at http://localhost:8181'; } class TestFlutterDevice extends FlutterDevice { TestFlutterDevice(Device device, { Stream observatoryUris }) : super(device, buildInfo: BuildInfo.debug) { _observatoryUris = observatoryUris; } @override Stream get observatoryUris => _observatoryUris; Stream _observatoryUris; } class ThrowingForwardingFileSystem extends ForwardingFileSystem { ThrowingForwardingFileSystem(FileSystem delegate) : super(delegate); @override File file(dynamic path) { if (path == 'foo') { throw const FileSystemException(); } return delegate.file(path); } } class FakeFlutterDevice extends FlutterDevice { FakeFlutterDevice( Device device, BuildInfo buildInfo, ResidentCompiler residentCompiler, this.fakeDevFS, ) : super(device, buildInfo: buildInfo, generator: residentCompiler); @override Future connect({ ReloadSources reloadSources, Restart restart, bool enableDds = true, bool disableServiceAuthCodes = false, bool ipv6 = false, CompileExpression compileExpression, GetSkSLMethod getSkSLMethod, int hostVmServicePort, int ddsPort, PrintStructuredErrorLogMethod printStructuredErrorLogMethod, bool allowExistingDdsInstance = false, }) async { } final DevFS fakeDevFS; @override DevFS get devFS => fakeDevFS; @override set devFS(DevFS value) {} } class FakeResidentCompiler extends Fake implements ResidentCompiler { @override Future recompile( Uri mainUri, List invalidatedFiles, { @required String outputPath, @required PackageConfig packageConfig, @required String projectRootPath, @required FileSystem fs, bool suppressErrors = false, }) async { return const CompilerOutput('foo.dill', 0, []); } @override void accept() { } @override void reset() { } } class FakeProjectFileInvalidator extends Fake implements ProjectFileInvalidator { @override Future findInvalidated({ @required DateTime lastCompiled, @required List urisToMonitor, @required String packagesPath, @required PackageConfig packageConfig, bool asyncScanning = false, }) async { return InvalidationResult( packageConfig: packageConfig ?? PackageConfig.empty, uris: [Uri.parse('file:///hello_world/main.dart'), ]); } } class FakeDevice extends Fake implements Device { FakeDevice({ String sdkNameAndVersion = 'Android', TargetPlatform targetPlatform = TargetPlatform.android_arm, bool isLocalEmulator = false, this.supportsHotRestart = true, this.supportsScreenshot = true, this.supportsFlutterExit = true, }) : _isLocalEmulator = isLocalEmulator, _targetPlatform = targetPlatform, _sdkNameAndVersion = sdkNameAndVersion; final bool _isLocalEmulator; final TargetPlatform _targetPlatform; final String _sdkNameAndVersion; bool disposed = false; bool appStopped = false; bool failScreenshot = false; @override bool supportsHotRestart; @override bool supportsScreenshot; @override bool supportsFlutterExit; @override PlatformType get platformType => _targetPlatform == TargetPlatform.web_javascript ? PlatformType.web : PlatformType.android; @override Future get sdkNameAndVersion async => _sdkNameAndVersion; @override Future get targetPlatform async => _targetPlatform; @override Future get isLocalEmulator async => _isLocalEmulator; @override String get name => 'FakeDevice'; @override DartDevelopmentService dds; @override Future dispose() async { disposed = true; } @override Future stopApp(covariant ApplicationPackage app, {String userIdentifier}) async { appStopped = true; return true; } @override Future takeScreenshot(File outputFile) async { if (failScreenshot) { throw Exception(); } outputFile.writeAsBytesSync(List.generate(1024, (int i) => i)); } @override FutureOr getLogReader({ covariant ApplicationPackage app, bool includePastLogs = false, }) => NoOpDeviceLogReader(name); @override DevicePortForwarder portForwarder = const NoOpDevicePortForwarder(); } class FakeDevFS extends Fake implements DevFS { @override DateTime lastCompiled = DateTime(2000); @override PackageConfig lastPackageConfig = PackageConfig.empty; @override List sources = []; @override Uri baseUri = Uri(); @override Future destroy() async { } @override Set assetPathsToEvict = {}; UpdateFSReport nextUpdateReport = UpdateFSReport(success: true); @override Future create() async { return Uri(); } @override void resetLastCompiled() { lastCompiled = null; } @override Future update({ @required Uri mainUri, @required ResidentCompiler generator, @required bool trackWidgetCreation, @required String pathToReload, @required List invalidatedFiles, @required PackageConfig packageConfig, @required String dillOutputPath, DevFSWriter devFSWriter, String target, AssetBundle bundle, DateTime firstBuildTime, bool bundleFirstUpload = false, bool fullRestart = false, String projectRootPath, }) async { return nextUpdateReport; } }