Ian Hickson | 449f4a6 | 2019-11-27 15:04:02 -0800 | [diff] [blame] | 1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
Alexander Aprelev | 5b1e972 | 2017-05-21 15:15:44 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Jonah Williams | 74bd7b6 | 2021-01-27 15:17:53 -0800 | [diff] [blame] | 5 | // @dart = 2.8 |
| 6 | |
Alexander Aprelev | 5b1e972 | 2017-05-21 15:15:44 -0700 | [diff] [blame] | 7 | import 'dart:async'; |
Jonah Williams | adf45d1 | 2019-07-09 13:10:26 -0700 | [diff] [blame] | 8 | |
Ben Konyi | 89ef88c | 2020-12-04 17:16:30 -0800 | [diff] [blame] | 9 | import 'package:dds/dds.dart' as dds; |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 10 | import 'package:file/memory.dart'; |
Jonah Williams | 6d8ec35 | 2020-05-29 15:43:03 -0700 | [diff] [blame] | 11 | import 'package:file_testing/file_testing.dart'; |
Phil Quitslund | 61c30c4 | 2021-04-21 13:49:03 -0700 | [diff] [blame] | 12 | import 'package:flutter_tools/src/application_package.dart'; |
Jonah Williams | 79a985f | 2019-10-22 20:35:05 -0700 | [diff] [blame] | 13 | import 'package:flutter_tools/src/artifacts.dart'; |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 14 | import 'package:flutter_tools/src/asset.dart'; |
Zachary Anderson | 23ce192 | 2020-01-09 08:18:03 -0800 | [diff] [blame] | 15 | import 'package:flutter_tools/src/base/command_help.dart'; |
Jonah Williams | e3ee5c6 | 2019-07-13 16:02:09 -0700 | [diff] [blame] | 16 | import 'package:flutter_tools/src/base/common.dart'; |
Phil Quitslund | 61c30c4 | 2021-04-21 13:49:03 -0700 | [diff] [blame] | 17 | import 'package:flutter_tools/src/base/dds.dart'; |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 18 | import 'package:flutter_tools/src/base/file_system.dart'; |
Jenn Magder | 2e7d913 | 2019-11-01 14:37:17 -0700 | [diff] [blame] | 19 | import 'package:flutter_tools/src/base/io.dart' as io; |
Phil Quitslund | 61c30c4 | 2021-04-21 13:49:03 -0700 | [diff] [blame] | 20 | import 'package:flutter_tools/src/base/logger.dart'; |
| 21 | import 'package:flutter_tools/src/base/platform.dart'; |
Alexander Aprelev | d775908 | 2019-04-15 21:02:20 -0700 | [diff] [blame] | 22 | import 'package:flutter_tools/src/build_info.dart'; |
Jonah Williams | 79a985f | 2019-10-22 20:35:05 -0700 | [diff] [blame] | 23 | import 'package:flutter_tools/src/compile.dart'; |
Jonah Williams | 08fe78f | 2020-04-07 12:17:39 -0700 | [diff] [blame] | 24 | import 'package:flutter_tools/src/convert.dart'; |
Jonah Williams | adf45d1 | 2019-07-09 13:10:26 -0700 | [diff] [blame] | 25 | import 'package:flutter_tools/src/devfs.dart'; |
Alexander Aprelev | 5b1e972 | 2017-05-21 15:15:44 -0700 | [diff] [blame] | 26 | import 'package:flutter_tools/src/device.dart'; |
Phil Quitslund | 61c30c4 | 2021-04-21 13:49:03 -0700 | [diff] [blame] | 27 | import 'package:flutter_tools/src/device_port_forwarder.dart'; |
| 28 | import 'package:flutter_tools/src/features.dart'; |
Jenn Magder | 9e88fe3 | 2021-11-01 17:18:03 -0700 | [diff] [blame] | 29 | import 'package:flutter_tools/src/globals.dart' as globals; |
Zachary Anderson | ef146f6 | 2019-07-29 07:24:02 -0700 | [diff] [blame] | 30 | import 'package:flutter_tools/src/reporting/reporting.dart'; |
Phil Quitslund | 61c30c4 | 2021-04-21 13:49:03 -0700 | [diff] [blame] | 31 | import 'package:flutter_tools/src/resident_devtools_handler.dart'; |
Alexander Aprelev | 5b1e972 | 2017-05-21 15:15:44 -0700 | [diff] [blame] | 32 | import 'package:flutter_tools/src/resident_runner.dart'; |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 33 | import 'package:flutter_tools/src/run_cold.dart'; |
Jonah Williams | adf45d1 | 2019-07-09 13:10:26 -0700 | [diff] [blame] | 34 | import 'package:flutter_tools/src/run_hot.dart'; |
Phil Quitslund | 61c30c4 | 2021-04-21 13:49:03 -0700 | [diff] [blame] | 35 | import 'package:flutter_tools/src/version.dart'; |
Jonah Williams | adf45d1 | 2019-07-09 13:10:26 -0700 | [diff] [blame] | 36 | import 'package:flutter_tools/src/vmservice.dart'; |
Phil Quitslund | 61c30c4 | 2021-04-21 13:49:03 -0700 | [diff] [blame] | 37 | import 'package:meta/meta.dart'; |
Phil Quitslund | 61c30c4 | 2021-04-21 13:49:03 -0700 | [diff] [blame] | 38 | import 'package:package_config/package_config.dart'; |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 39 | import 'package:test/fake.dart'; |
Phil Quitslund | 61c30c4 | 2021-04-21 13:49:03 -0700 | [diff] [blame] | 40 | import 'package:vm_service/vm_service.dart' as vm_service; |
Alexander Aprelev | 5b1e972 | 2017-05-21 15:15:44 -0700 | [diff] [blame] | 41 | |
Ian Hickson | d919e69 | 2019-07-13 11:51:44 -0700 | [diff] [blame] | 42 | import '../src/common.dart'; |
Todd Volkert | adb2aee | 2019-07-18 15:29:06 -0700 | [diff] [blame] | 43 | import '../src/context.dart'; |
Jenn Magder | a2f6772 | 2021-04-06 22:55:03 -0700 | [diff] [blame] | 44 | import '../src/fake_vm_services.dart'; |
Jonah Williams | 2951363 | 2021-02-26 11:13:32 -0800 | [diff] [blame] | 45 | import '../src/fakes.dart'; |
Ian Hickson | d919e69 | 2019-07-13 11:51:44 -0700 | [diff] [blame] | 46 | import '../src/testbed.dart'; |
Alexander Aprelev | 5b1e972 | 2017-05-21 15:15:44 -0700 | [diff] [blame] | 47 | |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 48 | final vm_service.Isolate fakeUnpausedIsolate = vm_service.Isolate( |
| 49 | id: '1', |
| 50 | pauseEvent: vm_service.Event( |
| 51 | kind: vm_service.EventKind.kResume, |
| 52 | timestamp: 0 |
| 53 | ), |
| 54 | breakpoints: <vm_service.Breakpoint>[], |
| 55 | exceptionPauseMode: null, |
Kenzie Schmoll | c89d649 | 2021-01-25 10:40:14 -0800 | [diff] [blame] | 56 | extensionRPCs: <String>[], |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 57 | libraries: <vm_service.LibraryRef>[ |
| 58 | vm_service.LibraryRef( |
| 59 | id: '1', |
| 60 | uri: 'file:///hello_world/main.dart', |
| 61 | name: '', |
| 62 | ), |
| 63 | ], |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 64 | livePorts: 0, |
| 65 | name: 'test', |
| 66 | number: '1', |
| 67 | pauseOnExit: false, |
| 68 | runnable: true, |
| 69 | startTime: 0, |
Jonah Williams | 18f0a22 | 2020-10-27 13:55:32 -0700 | [diff] [blame] | 70 | isSystemIsolate: false, |
Ben Konyi | 4cbafda | 2020-11-17 16:03:18 -0800 | [diff] [blame] | 71 | isolateFlags: <vm_service.IsolateFlag>[], |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 72 | ); |
| 73 | |
| 74 | final vm_service.Isolate fakePausedIsolate = vm_service.Isolate( |
| 75 | id: '1', |
| 76 | pauseEvent: vm_service.Event( |
| 77 | kind: vm_service.EventKind.kPauseException, |
| 78 | timestamp: 0 |
| 79 | ), |
Jonah Williams | c6dce23 | 2020-07-24 15:34:55 -0700 | [diff] [blame] | 80 | breakpoints: <vm_service.Breakpoint>[ |
| 81 | vm_service.Breakpoint( |
| 82 | breakpointNumber: 123, |
| 83 | id: 'test-breakpoint', |
| 84 | location: vm_service.SourceLocation( |
| 85 | tokenPos: 0, |
Jonah Williams | 0afddf3 | 2020-10-12 09:47:41 -0700 | [diff] [blame] | 86 | script: vm_service.ScriptRef(id: 'test-script', uri: 'foo.dart'), |
Jonah Williams | c6dce23 | 2020-07-24 15:34:55 -0700 | [diff] [blame] | 87 | ), |
Jonah Williams | cd13c91 | 2021-06-15 11:08:57 -0700 | [diff] [blame] | 88 | enabled: true, |
Jonah Williams | c6dce23 | 2020-07-24 15:34:55 -0700 | [diff] [blame] | 89 | resolved: true, |
| 90 | ), |
| 91 | ], |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 92 | exceptionPauseMode: null, |
| 93 | libraries: <vm_service.LibraryRef>[], |
| 94 | livePorts: 0, |
| 95 | name: 'test', |
| 96 | number: '1', |
| 97 | pauseOnExit: false, |
| 98 | runnable: true, |
| 99 | startTime: 0, |
Jonah Williams | 18f0a22 | 2020-10-27 13:55:32 -0700 | [diff] [blame] | 100 | isSystemIsolate: false, |
Ben Konyi | 4cbafda | 2020-11-17 16:03:18 -0800 | [diff] [blame] | 101 | isolateFlags: <vm_service.IsolateFlag>[], |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 102 | ); |
| 103 | |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 104 | final vm_service.VM fakeVM = vm_service.VM( |
| 105 | isolates: <vm_service.IsolateRef>[fakeUnpausedIsolate], |
| 106 | pid: 1, |
| 107 | hostCPU: '', |
| 108 | isolateGroups: <vm_service.IsolateGroupRef>[], |
| 109 | targetCPU: '', |
| 110 | startTime: 0, |
| 111 | name: 'dart', |
| 112 | architectureBits: 64, |
| 113 | operatingSystem: '', |
| 114 | version: '', |
Jonah Williams | 18f0a22 | 2020-10-27 13:55:32 -0700 | [diff] [blame] | 115 | systemIsolateGroups: <vm_service.IsolateGroupRef>[], |
| 116 | systemIsolates: <vm_service.IsolateRef>[], |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 117 | ); |
| 118 | |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 119 | final FlutterView fakeFlutterView = FlutterView( |
| 120 | id: 'a', |
| 121 | uiIsolate: fakeUnpausedIsolate, |
| 122 | ); |
| 123 | |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 124 | final FakeVmServiceRequest listViews = FakeVmServiceRequest( |
| 125 | method: kListViewsMethod, |
| 126 | jsonResponse: <String, Object>{ |
| 127 | 'views': <Object>[ |
| 128 | fakeFlutterView.toJson(), |
| 129 | ], |
| 130 | }, |
| 131 | ); |
| 132 | |
Jonah Williams | 3300a1b | 2020-10-27 09:20:05 -0700 | [diff] [blame] | 133 | const FakeVmServiceRequest setAssetBundlePath = FakeVmServiceRequest( |
| 134 | method: '_flutter.setAssetBundlePath', |
| 135 | args: <String, Object>{ |
| 136 | 'viewId': 'a', |
| 137 | 'assetDirectory': 'build/flutter_assets', |
| 138 | 'isolateId': '1', |
| 139 | } |
| 140 | ); |
| 141 | |
Lau Ching Jun | af42e7d | 2021-06-28 13:16:04 -0700 | [diff] [blame] | 142 | const FakeVmServiceRequest evict = FakeVmServiceRequest( |
| 143 | method: 'ext.flutter.evict', |
| 144 | args: <String, Object>{ |
| 145 | 'value': 'asset', |
| 146 | 'isolateId': '1', |
| 147 | } |
| 148 | ); |
| 149 | |
Jonah Williams | 6efe8e9 | 2021-01-29 14:27:42 -0800 | [diff] [blame] | 150 | final Uri testUri = Uri.parse('foo://bar'); |
| 151 | |
Alexander Aprelev | 5b1e972 | 2017-05-21 15:15:44 -0700 | [diff] [blame] | 152 | void main() { |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 153 | Testbed testbed; |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 154 | FakeFlutterDevice flutterDevice; |
| 155 | FakeDevFS devFS; |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 156 | ResidentRunner residentRunner; |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 157 | FakeDevice device; |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 158 | FakeVmServiceHost fakeVmServiceHost; |
Alexander Aprelev | 5b1e972 | 2017-05-21 15:15:44 -0700 | [diff] [blame] | 159 | |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 160 | setUp(() { |
| 161 | testbed = Testbed(setup: () { |
Jonah Williams | 82a6f9b | 2020-06-25 12:52:14 -0700 | [diff] [blame] | 162 | globals.fs.file('.packages') |
| 163 | .writeAsStringSync('\n'); |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame] | 164 | globals.fs.file(globals.fs.path.join('build', 'app.dill')) |
Jonah Williams | 1fec30e | 2019-09-12 12:45:53 -0700 | [diff] [blame] | 165 | ..createSync(recursive: true) |
| 166 | ..writeAsStringSync('ABC'); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 167 | residentRunner = HotRunner( |
| 168 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 169 | flutterDevice, |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 170 | ], |
| 171 | stayResident: false, |
| 172 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 173 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 174 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | adf45d1 | 2019-07-09 13:10:26 -0700 | [diff] [blame] | 175 | ); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 176 | }); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 177 | device = FakeDevice(); |
| 178 | devFS = FakeDevFS(); |
| 179 | flutterDevice = FakeFlutterDevice() |
| 180 | ..testUri = testUri |
| 181 | ..vmServiceHost = (() => fakeVmServiceHost) |
| 182 | ..device = device |
| 183 | .._devFS = devFS; |
Alexander Aprelev | 5b1e972 | 2017-05-21 15:15:44 -0700 | [diff] [blame] | 184 | }); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 185 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 186 | testUsingContext('ResidentRunner can attach to device successfully', () => testbed.run(() async { |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 187 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 188 | listViews, |
| 189 | listViews, |
| 190 | ]); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 191 | final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync(); |
| 192 | final Completer<void> futureAppStart = Completer<void>.sync(); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 193 | final Future<int> result = residentRunner.attach( |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 194 | appStartedCompleter: futureAppStart, |
| 195 | connectionInfoCompleter: futureConnectionInfo, |
| 196 | enableDevTools: true, |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 197 | ); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 198 | final Future<DebugConnectionInfo> connectionInfo = futureConnectionInfo.future; |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 199 | |
| 200 | expect(await result, 0); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 201 | expect(futureConnectionInfo.isCompleted, true); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 202 | expect((await connectionInfo).baseUri, 'foo://bar'); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 203 | expect(futureAppStart.isCompleted, true); |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 204 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 205 | })); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 206 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 207 | testUsingContext('ResidentRunner suppresses errors for the initial compilation', () => testbed.run(() async { |
Jonah Williams | e216eec | 2020-06-03 12:00:03 -0700 | [diff] [blame] | 208 | globals.fs.file(globals.fs.path.join('lib', 'main.dart')) |
| 209 | .createSync(recursive: true); |
| 210 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 211 | listViews, |
| 212 | listViews, |
| 213 | ]); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 214 | final FakeResidentCompiler residentCompiler = FakeResidentCompiler() |
| 215 | ..nextOutput = const CompilerOutput('foo', 0 ,<Uri>[]); |
Jonah Williams | e216eec | 2020-06-03 12:00:03 -0700 | [diff] [blame] | 216 | residentRunner = HotRunner( |
| 217 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 218 | flutterDevice, |
Jonah Williams | e216eec | 2020-06-03 12:00:03 -0700 | [diff] [blame] | 219 | ], |
| 220 | stayResident: false, |
| 221 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 222 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 223 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | e216eec | 2020-06-03 12:00:03 -0700 | [diff] [blame] | 224 | ); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 225 | flutterDevice.generator = residentCompiler; |
Jonah Williams | e216eec | 2020-06-03 12:00:03 -0700 | [diff] [blame] | 226 | |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 227 | expect(await residentRunner.run(enableDevTools: true), 0); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 228 | expect(residentCompiler.didSuppressErrors, true); |
Jonah Williams | e216eec | 2020-06-03 12:00:03 -0700 | [diff] [blame] | 229 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 230 | })); |
Jonah Williams | e216eec | 2020-06-03 12:00:03 -0700 | [diff] [blame] | 231 | |
Jonah Williams | 2188196 | 2020-06-30 12:26:18 -0700 | [diff] [blame] | 232 | // Regression test for https://github.com/flutter/flutter/issues/60613 |
| 233 | testUsingContext('ResidentRunner calls appFailedToStart if initial compilation fails', () => testbed.run(() async { |
| 234 | globals.fs.file(globals.fs.path.join('lib', 'main.dart')) |
| 235 | .createSync(recursive: true); |
| 236 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 237 | final FakeResidentCompiler residentCompiler = FakeResidentCompiler() |
| 238 | ..nextOutput = const CompilerOutput('foo', 1 ,<Uri>[]); |
Jonah Williams | 2188196 | 2020-06-30 12:26:18 -0700 | [diff] [blame] | 239 | residentRunner = HotRunner( |
| 240 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 241 | flutterDevice, |
Jonah Williams | 2188196 | 2020-06-30 12:26:18 -0700 | [diff] [blame] | 242 | ], |
| 243 | stayResident: false, |
| 244 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 245 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 246 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | 2188196 | 2020-06-30 12:26:18 -0700 | [diff] [blame] | 247 | ); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 248 | flutterDevice.generator = residentCompiler; |
Jonah Williams | 2188196 | 2020-06-30 12:26:18 -0700 | [diff] [blame] | 249 | |
| 250 | expect(await residentRunner.run(), 1); |
| 251 | // Completing this future ensures that the daemon can exit correctly. |
| 252 | expect(await residentRunner.waitForAppToFinish(), 1); |
| 253 | })); |
| 254 | |
| 255 | // Regression test for https://github.com/flutter/flutter/issues/60613 |
| 256 | testUsingContext('ResidentRunner calls appFailedToStart if initial compilation fails - cold mode', () => testbed.run(() async { |
| 257 | globals.fs.file(globals.fs.path.join('lib', 'main.dart')) |
| 258 | .createSync(recursive: true); |
| 259 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); |
| 260 | residentRunner = ColdRunner( |
| 261 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 262 | flutterDevice, |
Jonah Williams | 2188196 | 2020-06-30 12:26:18 -0700 | [diff] [blame] | 263 | ], |
| 264 | stayResident: false, |
| 265 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.release), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 266 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 267 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | 2188196 | 2020-06-30 12:26:18 -0700 | [diff] [blame] | 268 | ); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 269 | flutterDevice.runColdCode = 1; |
Jonah Williams | 2188196 | 2020-06-30 12:26:18 -0700 | [diff] [blame] | 270 | |
| 271 | expect(await residentRunner.run(), 1); |
| 272 | // Completing this future ensures that the daemon can exit correctly. |
| 273 | expect(await residentRunner.waitForAppToFinish(), 1); |
| 274 | })); |
| 275 | |
| 276 | // Regression test for https://github.com/flutter/flutter/issues/60613 |
| 277 | testUsingContext('ResidentRunner calls appFailedToStart if exception is thrown - cold mode', () => testbed.run(() async { |
| 278 | globals.fs.file(globals.fs.path.join('lib', 'main.dart')) |
| 279 | .createSync(recursive: true); |
| 280 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); |
| 281 | residentRunner = ColdRunner( |
| 282 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 283 | flutterDevice, |
Jonah Williams | 2188196 | 2020-06-30 12:26:18 -0700 | [diff] [blame] | 284 | ], |
| 285 | stayResident: false, |
| 286 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.release), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 287 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 288 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | 2188196 | 2020-06-30 12:26:18 -0700 | [diff] [blame] | 289 | ); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 290 | flutterDevice.runColdError = Exception('BAD STUFF'); |
| 291 | |
Jonah Williams | 2188196 | 2020-06-30 12:26:18 -0700 | [diff] [blame] | 292 | |
| 293 | expect(await residentRunner.run(), 1); |
| 294 | // Completing this future ensures that the daemon can exit correctly. |
| 295 | expect(await residentRunner.waitForAppToFinish(), 1); |
| 296 | })); |
| 297 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 298 | testUsingContext('ResidentRunner does not suppressErrors if running with an applicationBinary', () => testbed.run(() async { |
Jonah Williams | e216eec | 2020-06-03 12:00:03 -0700 | [diff] [blame] | 299 | globals.fs.file(globals.fs.path.join('lib', 'main.dart')) |
| 300 | .createSync(recursive: true); |
| 301 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 302 | listViews, |
| 303 | listViews, |
| 304 | ]); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 305 | final FakeResidentCompiler residentCompiler = FakeResidentCompiler() |
| 306 | ..nextOutput = const CompilerOutput('foo', 0 ,<Uri>[]); |
Jonah Williams | e216eec | 2020-06-03 12:00:03 -0700 | [diff] [blame] | 307 | residentRunner = HotRunner( |
| 308 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 309 | flutterDevice, |
Jonah Williams | e216eec | 2020-06-03 12:00:03 -0700 | [diff] [blame] | 310 | ], |
| 311 | applicationBinary: globals.fs.file('app.apk'), |
| 312 | stayResident: false, |
| 313 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 314 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 315 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | e216eec | 2020-06-03 12:00:03 -0700 | [diff] [blame] | 316 | ); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 317 | flutterDevice.generator = residentCompiler; |
Jonah Williams | e216eec | 2020-06-03 12:00:03 -0700 | [diff] [blame] | 318 | |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 319 | expect(await residentRunner.run(enableDevTools: true), 0); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 320 | expect(residentCompiler.didSuppressErrors, false); |
Jonah Williams | e216eec | 2020-06-03 12:00:03 -0700 | [diff] [blame] | 321 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 322 | })); |
Jonah Williams | e216eec | 2020-06-03 12:00:03 -0700 | [diff] [blame] | 323 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 324 | testUsingContext('ResidentRunner can attach to device successfully with --fast-start', () => testbed.run(() async { |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 325 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 326 | listViews, |
| 327 | listViews, |
| 328 | listViews, |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 329 | FakeVmServiceRequest( |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 330 | method: 'getIsolate', |
| 331 | args: <String, Object>{ |
| 332 | 'isolateId': fakeUnpausedIsolate.id, |
| 333 | }, |
| 334 | jsonResponse: fakeUnpausedIsolate.toJson(), |
| 335 | ), |
| 336 | FakeVmServiceRequest( |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 337 | method: 'getVM', |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 338 | jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson(), |
| 339 | ), |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 340 | listViews, |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 341 | const FakeVmServiceRequest( |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 342 | method: 'streamListen', |
| 343 | args: <String, Object>{ |
| 344 | 'streamId': 'Isolate', |
| 345 | } |
| 346 | ), |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 347 | FakeVmServiceRequest( |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 348 | method: kRunInViewMethod, |
| 349 | args: <String, Object>{ |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 350 | 'viewId': fakeFlutterView.id, |
Jonah Williams | 0afddf3 | 2020-10-12 09:47:41 -0700 | [diff] [blame] | 351 | 'mainScript': 'main.dart.dill', |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 352 | 'assetDirectory': 'build/flutter_assets', |
| 353 | } |
| 354 | ), |
| 355 | FakeVmServiceStreamResponse( |
| 356 | streamId: 'Isolate', |
| 357 | event: vm_service.Event( |
| 358 | timestamp: 0, |
| 359 | kind: vm_service.EventKind.kIsolateRunnable, |
| 360 | ) |
| 361 | ), |
| 362 | ]); |
Jonah Williams | bda9d90 | 2019-12-10 10:26:14 -0800 | [diff] [blame] | 363 | residentRunner = HotRunner( |
| 364 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 365 | flutterDevice, |
Jonah Williams | bda9d90 | 2019-12-10 10:26:14 -0800 | [diff] [blame] | 366 | ], |
| 367 | stayResident: false, |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 368 | debuggingOptions: DebuggingOptions.enabled( |
| 369 | BuildInfo.debug, |
| 370 | fastStart: true, |
| 371 | startPaused: true, |
| 372 | ), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 373 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 374 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | bda9d90 | 2019-12-10 10:26:14 -0800 | [diff] [blame] | 375 | ); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 376 | final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync(); |
| 377 | final Completer<void> futureAppStart = Completer<void>.sync(); |
Jonah Williams | bda9d90 | 2019-12-10 10:26:14 -0800 | [diff] [blame] | 378 | final Future<int> result = residentRunner.attach( |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 379 | appStartedCompleter: futureAppStart, |
| 380 | connectionInfoCompleter: futureConnectionInfo, |
| 381 | enableDevTools: true, |
Jonah Williams | bda9d90 | 2019-12-10 10:26:14 -0800 | [diff] [blame] | 382 | ); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 383 | final Future<DebugConnectionInfo> connectionInfo = futureConnectionInfo.future; |
Jonah Williams | bda9d90 | 2019-12-10 10:26:14 -0800 | [diff] [blame] | 384 | |
| 385 | expect(await result, 0); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 386 | expect(futureConnectionInfo.isCompleted, true); |
Jonah Williams | bda9d90 | 2019-12-10 10:26:14 -0800 | [diff] [blame] | 387 | expect((await connectionInfo).baseUri, 'foo://bar'); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 388 | expect(futureAppStart.isCompleted, true); |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 389 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 390 | })); |
Jonah Williams | bda9d90 | 2019-12-10 10:26:14 -0800 | [diff] [blame] | 391 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 392 | testUsingContext('ResidentRunner can handle an RPC exception from hot reload', () => testbed.run(() async { |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 393 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 394 | listViews, |
| 395 | listViews, |
| 396 | listViews, |
| 397 | ]); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 398 | final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync(); |
| 399 | final Completer<void> futureAppStart = Completer<void>.sync(); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 400 | unawaited(residentRunner.attach( |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 401 | appStartedCompleter: futureAppStart, |
| 402 | connectionInfoCompleter: futureConnectionInfo, |
| 403 | enableDevTools: true, |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 404 | )); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 405 | await futureAppStart.future; |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 406 | flutterDevice.reportError = vm_service.RPCError('something bad happened', 666, ''); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 407 | |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 408 | final OperationResult result = await residentRunner.restart(); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 409 | expect(result.fatal, true); |
| 410 | expect(result.code, 1); |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 411 | expect((globals.flutterUsage as TestUsage).events, contains( |
Lau Ching Jun | 2acd0007 | 2021-05-18 20:29:03 -0700 | [diff] [blame] | 412 | TestUsageEvent('hot', 'exception', parameters: CustomDimensions( |
| 413 | hotEventTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm), |
| 414 | hotEventSdkName: 'Android', |
| 415 | hotEventEmulator: false, |
| 416 | hotEventFullRestart: false, |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 417 | fastReassemble: false, |
Lau Ching Jun | 2acd0007 | 2021-05-18 20:29:03 -0700 | [diff] [blame] | 418 | )), |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 419 | )); |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 420 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 421 | }, overrides: <Type, Generator>{ |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 422 | Usage: () => TestUsage(), |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 423 | })); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 424 | |
Jonah Williams | 50dfd13 | 2021-01-06 15:54:04 -0800 | [diff] [blame] | 425 | testUsingContext('ResidentRunner fails its operation if the device initialization is not complete', () => testbed.run(() async { |
| 426 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 427 | listViews, |
| 428 | listViews, |
Jonah Williams | 50dfd13 | 2021-01-06 15:54:04 -0800 | [diff] [blame] | 429 | ]); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 430 | final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync(); |
| 431 | final Completer<void> futureAppStart = Completer<void>.sync(); |
Jonah Williams | 50dfd13 | 2021-01-06 15:54:04 -0800 | [diff] [blame] | 432 | unawaited(residentRunner.attach( |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 433 | appStartedCompleter: futureAppStart, |
| 434 | connectionInfoCompleter: futureConnectionInfo, |
Jonah Williams | 50dfd13 | 2021-01-06 15:54:04 -0800 | [diff] [blame] | 435 | )); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 436 | await futureAppStart.future; |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 437 | flutterDevice._devFS = null; |
Jonah Williams | 50dfd13 | 2021-01-06 15:54:04 -0800 | [diff] [blame] | 438 | |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 439 | final OperationResult result = await residentRunner.restart(); |
Jonah Williams | 50dfd13 | 2021-01-06 15:54:04 -0800 | [diff] [blame] | 440 | expect(result.fatal, false); |
| 441 | expect(result.code, 1); |
| 442 | expect(result.message, contains('Device initialization has not completed.')); |
| 443 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 444 | })); |
Jonah Williams | 50dfd13 | 2021-01-06 15:54:04 -0800 | [diff] [blame] | 445 | |
Jonah Williams | 3300a1b | 2020-10-27 09:20:05 -0700 | [diff] [blame] | 446 | testUsingContext('ResidentRunner can handle an reload-barred exception from hot reload', () => testbed.run(() async { |
| 447 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 448 | listViews, |
| 449 | listViews, |
Jonah Williams | 3300a1b | 2020-10-27 09:20:05 -0700 | [diff] [blame] | 450 | listViews, |
| 451 | ]); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 452 | final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync(); |
| 453 | final Completer<void> futureAppStart = Completer<void>.sync(); |
Jonah Williams | 3300a1b | 2020-10-27 09:20:05 -0700 | [diff] [blame] | 454 | unawaited(residentRunner.attach( |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 455 | appStartedCompleter: futureAppStart, |
| 456 | connectionInfoCompleter: futureConnectionInfo, |
| 457 | enableDevTools: true, |
Jonah Williams | 3300a1b | 2020-10-27 09:20:05 -0700 | [diff] [blame] | 458 | )); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 459 | await futureAppStart.future; |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 460 | flutterDevice.reportError = vm_service.RPCError('something bad happened', kIsolateReloadBarred, ''); |
Jonah Williams | 3300a1b | 2020-10-27 09:20:05 -0700 | [diff] [blame] | 461 | |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 462 | final OperationResult result = await residentRunner.restart(); |
Jonah Williams | 3300a1b | 2020-10-27 09:20:05 -0700 | [diff] [blame] | 463 | expect(result.fatal, true); |
| 464 | expect(result.code, kIsolateReloadBarred); |
| 465 | expect(result.message, contains('Unable to hot reload application due to an unrecoverable error')); |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 466 | |
| 467 | expect((globals.flutterUsage as TestUsage).events, contains( |
Lau Ching Jun | 2acd0007 | 2021-05-18 20:29:03 -0700 | [diff] [blame] | 468 | TestUsageEvent('hot', 'reload-barred', parameters: CustomDimensions( |
| 469 | hotEventTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm), |
| 470 | hotEventSdkName: 'Android', |
| 471 | hotEventEmulator: false, |
| 472 | hotEventFullRestart: false, |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 473 | fastReassemble: false, |
Lau Ching Jun | 2acd0007 | 2021-05-18 20:29:03 -0700 | [diff] [blame] | 474 | )), |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 475 | )); |
Jonah Williams | 3300a1b | 2020-10-27 09:20:05 -0700 | [diff] [blame] | 476 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
| 477 | }, overrides: <Type, Generator>{ |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 478 | Usage: () => TestUsage(), |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 479 | })); |
Jonah Williams | 3300a1b | 2020-10-27 09:20:05 -0700 | [diff] [blame] | 480 | |
Jonah Williams | 55abbb6 | 2020-06-22 17:05:01 -0700 | [diff] [blame] | 481 | testUsingContext('ResidentRunner reports hot reload event with null safety analytics', () => testbed.run(() async { |
| 482 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 483 | listViews, |
| 484 | listViews, |
| 485 | listViews, |
| 486 | ]); |
| 487 | residentRunner = HotRunner( |
| 488 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 489 | flutterDevice, |
Jonah Williams | 55abbb6 | 2020-06-22 17:05:01 -0700 | [diff] [blame] | 490 | ], |
| 491 | stayResident: false, |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 492 | target: 'main.dart', |
Jonah Williams | 55abbb6 | 2020-06-22 17:05:01 -0700 | [diff] [blame] | 493 | debuggingOptions: DebuggingOptions.enabled(const BuildInfo( |
| 494 | BuildMode.debug, '', treeShakeIcons: false, extraFrontEndOptions: <String>[ |
| 495 | '--enable-experiment=non-nullable', |
| 496 | ], |
| 497 | )), |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 498 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | 55abbb6 | 2020-06-22 17:05:01 -0700 | [diff] [blame] | 499 | ); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 500 | final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync(); |
| 501 | final Completer<void> futureAppStart = Completer<void>.sync(); |
Jonah Williams | 55abbb6 | 2020-06-22 17:05:01 -0700 | [diff] [blame] | 502 | unawaited(residentRunner.attach( |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 503 | appStartedCompleter: futureAppStart, |
| 504 | connectionInfoCompleter: futureConnectionInfo, |
| 505 | enableDevTools: true, |
Jonah Williams | 55abbb6 | 2020-06-22 17:05:01 -0700 | [diff] [blame] | 506 | )); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 507 | await futureAppStart.future; |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 508 | flutterDevice.reportError = vm_service.RPCError('something bad happened', 666, ''); |
Jonah Williams | 55abbb6 | 2020-06-22 17:05:01 -0700 | [diff] [blame] | 509 | |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 510 | final OperationResult result = await residentRunner.restart(); |
Jonah Williams | 55abbb6 | 2020-06-22 17:05:01 -0700 | [diff] [blame] | 511 | expect(result.fatal, true); |
| 512 | expect(result.code, 1); |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 513 | |
| 514 | expect((globals.flutterUsage as TestUsage).events, contains( |
Lau Ching Jun | 2acd0007 | 2021-05-18 20:29:03 -0700 | [diff] [blame] | 515 | TestUsageEvent('hot', 'exception', parameters: CustomDimensions( |
| 516 | hotEventTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm), |
| 517 | hotEventSdkName: 'Android', |
| 518 | hotEventEmulator: false, |
| 519 | hotEventFullRestart: false, |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 520 | fastReassemble: false, |
Lau Ching Jun | 2acd0007 | 2021-05-18 20:29:03 -0700 | [diff] [blame] | 521 | )), |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 522 | )); |
Jonah Williams | 55abbb6 | 2020-06-22 17:05:01 -0700 | [diff] [blame] | 523 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
| 524 | }, overrides: <Type, Generator>{ |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 525 | Usage: () => TestUsage(), |
Jonah Williams | 55abbb6 | 2020-06-22 17:05:01 -0700 | [diff] [blame] | 526 | })); |
| 527 | |
Jonah Williams | 6cec03c | 2020-11-04 11:15:30 -0800 | [diff] [blame] | 528 | testUsingContext('ResidentRunner does not reload sources if no sources changed', () => testbed.run(() async { |
| 529 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 530 | listViews, |
| 531 | listViews, |
Jonah Williams | 6cec03c | 2020-11-04 11:15:30 -0800 | [diff] [blame] | 532 | listViews, |
| 533 | FakeVmServiceRequest( |
| 534 | method: 'getIsolate', |
| 535 | args: <String, Object>{ |
| 536 | 'isolateId': '1', |
| 537 | }, |
| 538 | jsonResponse: fakeUnpausedIsolate.toJson(), |
| 539 | ), |
| 540 | FakeVmServiceRequest( |
| 541 | method: 'ext.flutter.reassemble', |
| 542 | args: <String, Object>{ |
| 543 | 'isolateId': fakeUnpausedIsolate.id, |
| 544 | }, |
| 545 | ), |
| 546 | ]); |
| 547 | residentRunner = HotRunner( |
| 548 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 549 | flutterDevice, |
Jonah Williams | 6cec03c | 2020-11-04 11:15:30 -0800 | [diff] [blame] | 550 | ], |
| 551 | stayResident: false, |
| 552 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 553 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 554 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | 6cec03c | 2020-11-04 11:15:30 -0800 | [diff] [blame] | 555 | ); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 556 | final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync(); |
| 557 | final Completer<void> futureAppStart = Completer<void>.sync(); |
Jonah Williams | 6cec03c | 2020-11-04 11:15:30 -0800 | [diff] [blame] | 558 | unawaited(residentRunner.attach( |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 559 | appStartedCompleter: futureAppStart, |
| 560 | connectionInfoCompleter: futureConnectionInfo, |
| 561 | enableDevTools: true, |
Jonah Williams | 6cec03c | 2020-11-04 11:15:30 -0800 | [diff] [blame] | 562 | )); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 563 | await futureAppStart.future; |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 564 | flutterDevice.report = UpdateFSReport(success: true); |
Jonah Williams | 6cec03c | 2020-11-04 11:15:30 -0800 | [diff] [blame] | 565 | |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 566 | final OperationResult result = await residentRunner.restart(); |
Jonah Williams | 6cec03c | 2020-11-04 11:15:30 -0800 | [diff] [blame] | 567 | |
| 568 | expect(result.code, 0); |
| 569 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 570 | })); |
Jonah Williams | 6cec03c | 2020-11-04 11:15:30 -0800 | [diff] [blame] | 571 | |
Jonah Williams | 762d9f7 | 2020-08-05 15:11:15 -0700 | [diff] [blame] | 572 | testUsingContext('ResidentRunner reports error with missing entrypoint file', () => testbed.run(() async { |
| 573 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 574 | listViews, |
| 575 | listViews, |
| 576 | listViews, |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 577 | FakeVmServiceRequest( |
| 578 | method: 'getVM', |
| 579 | jsonResponse: vm_service.VM.parse(<String, Object>{ |
| 580 | 'isolates': <Object>[ |
| 581 | fakeUnpausedIsolate.toJson(), |
| 582 | ], |
| 583 | }).toJson(), |
| 584 | ), |
| 585 | const FakeVmServiceRequest( |
| 586 | method: 'reloadSources', |
| 587 | args: <String, Object>{ |
| 588 | 'isolateId': '1', |
| 589 | 'pause': false, |
Jonah Williams | 0afddf3 | 2020-10-12 09:47:41 -0700 | [diff] [blame] | 590 | 'rootLibUri': 'main.dart.incremental.dill' |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 591 | }, |
| 592 | jsonResponse: <String, Object>{ |
| 593 | 'type': 'ReloadReport', |
| 594 | 'success': true, |
| 595 | 'details': <String, Object>{ |
| 596 | 'loadedLibraryCount': 1, |
| 597 | }, |
| 598 | }, |
| 599 | ), |
Jonah Williams | 762d9f7 | 2020-08-05 15:11:15 -0700 | [diff] [blame] | 600 | FakeVmServiceRequest( |
| 601 | method: 'getIsolate', |
| 602 | args: <String, Object>{ |
| 603 | 'isolateId': '1', |
| 604 | }, |
| 605 | jsonResponse: fakeUnpausedIsolate.toJson(), |
| 606 | ), |
| 607 | FakeVmServiceRequest( |
| 608 | method: 'ext.flutter.reassemble', |
| 609 | args: <String, Object>{ |
| 610 | 'isolateId': fakeUnpausedIsolate.id, |
| 611 | }, |
| 612 | ), |
| 613 | ]); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 614 | final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync(); |
| 615 | final Completer<void> futureAppStart = Completer<void>.sync(); |
Jonah Williams | 762d9f7 | 2020-08-05 15:11:15 -0700 | [diff] [blame] | 616 | unawaited(residentRunner.attach( |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 617 | appStartedCompleter: futureAppStart, |
| 618 | connectionInfoCompleter: futureConnectionInfo, |
| 619 | enableDevTools: true, |
Jonah Williams | 762d9f7 | 2020-08-05 15:11:15 -0700 | [diff] [blame] | 620 | )); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 621 | await futureAppStart.future; |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 622 | flutterDevice.report = UpdateFSReport(success: true, invalidatedSourcesCount: 1); |
Jonah Williams | 762d9f7 | 2020-08-05 15:11:15 -0700 | [diff] [blame] | 623 | |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 624 | final OperationResult result = await residentRunner.restart(); |
Jonah Williams | 762d9f7 | 2020-08-05 15:11:15 -0700 | [diff] [blame] | 625 | |
| 626 | expect(globals.fs.file(globals.fs.path.join('lib', 'main.dart')), isNot(exists)); |
| 627 | expect(testLogger.errorText, contains('The entrypoint file (i.e. the file with main())')); |
| 628 | expect(result.fatal, false); |
| 629 | expect(result.code, 0); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 630 | })); |
Jonah Williams | 762d9f7 | 2020-08-05 15:11:15 -0700 | [diff] [blame] | 631 | |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 632 | testUsingContext('ResidentRunner resets compilation time on reload reject', () => testbed.run(() async { |
| 633 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 634 | listViews, |
| 635 | listViews, |
| 636 | listViews, |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 637 | FakeVmServiceRequest( |
| 638 | method: 'getVM', |
| 639 | jsonResponse: vm_service.VM.parse(<String, Object>{ |
| 640 | 'isolates': <Object>[ |
| 641 | fakeUnpausedIsolate.toJson(), |
| 642 | ], |
| 643 | }).toJson(), |
| 644 | ), |
| 645 | const FakeVmServiceRequest( |
| 646 | method: 'reloadSources', |
| 647 | args: <String, Object>{ |
| 648 | 'isolateId': '1', |
| 649 | 'pause': false, |
Jonah Williams | 0afddf3 | 2020-10-12 09:47:41 -0700 | [diff] [blame] | 650 | 'rootLibUri': 'main.dart.incremental.dill' |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 651 | }, |
| 652 | jsonResponse: <String, Object>{ |
| 653 | 'type': 'ReloadReport', |
| 654 | 'success': false, |
| 655 | 'notices': <Object>[ |
| 656 | <String, Object>{ |
| 657 | 'message': 'Failed to hot reload' |
| 658 | } |
| 659 | ], |
| 660 | 'details': <String, Object>{}, |
| 661 | }, |
| 662 | ), |
| 663 | listViews, |
| 664 | FakeVmServiceRequest( |
| 665 | method: 'getIsolate', |
| 666 | args: <String, Object>{ |
| 667 | 'isolateId': '1', |
| 668 | }, |
| 669 | jsonResponse: fakeUnpausedIsolate.toJson(), |
| 670 | ), |
| 671 | FakeVmServiceRequest( |
| 672 | method: 'ext.flutter.reassemble', |
| 673 | args: <String, Object>{ |
| 674 | 'isolateId': fakeUnpausedIsolate.id, |
| 675 | }, |
| 676 | ), |
| 677 | ]); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 678 | final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync(); |
| 679 | final Completer<void> futureAppStart = Completer<void>.sync(); |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 680 | unawaited(residentRunner.attach( |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 681 | appStartedCompleter: futureAppStart, |
| 682 | connectionInfoCompleter: futureConnectionInfo, |
| 683 | enableDevTools: true, |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 684 | )); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 685 | await futureAppStart.future; |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 686 | flutterDevice.report = UpdateFSReport(success: true, invalidatedSourcesCount: 1); |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 687 | |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 688 | final OperationResult result = await residentRunner.restart(); |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 689 | |
| 690 | expect(result.fatal, false); |
| 691 | expect(result.message, contains('Reload rejected: Failed to hot reload')); // contains error message from reload report. |
| 692 | expect(result.code, 1); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 693 | expect(devFS.lastCompiled, null); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 694 | })); |
Jonah Williams | 55abbb6 | 2020-06-22 17:05:01 -0700 | [diff] [blame] | 695 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 696 | testUsingContext('ResidentRunner can send target platform to analytics from hot reload', () => testbed.run(() async { |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 697 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 698 | listViews, |
| 699 | listViews, |
Jonah Williams | 0f80116 | 2020-11-11 15:31:07 -0800 | [diff] [blame] | 700 | listViews, |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 701 | FakeVmServiceRequest( |
| 702 | method: 'getVM', |
| 703 | jsonResponse: vm_service.VM.parse(<String, Object>{ |
| 704 | 'isolates': <Object>[ |
| 705 | fakeUnpausedIsolate.toJson(), |
| 706 | ], |
| 707 | }).toJson(), |
| 708 | ), |
| 709 | const FakeVmServiceRequest( |
| 710 | method: 'reloadSources', |
| 711 | args: <String, Object>{ |
| 712 | 'isolateId': '1', |
| 713 | 'pause': false, |
Jonah Williams | 0afddf3 | 2020-10-12 09:47:41 -0700 | [diff] [blame] | 714 | 'rootLibUri': 'main.dart.incremental.dill' |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 715 | }, |
| 716 | jsonResponse: <String, Object>{ |
| 717 | 'type': 'ReloadReport', |
| 718 | 'success': true, |
| 719 | 'details': <String, Object>{ |
| 720 | 'loadedLibraryCount': 1, |
| 721 | }, |
| 722 | }, |
| 723 | ), |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 724 | FakeVmServiceRequest( |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 725 | method: 'getIsolate', |
| 726 | args: <String, Object>{ |
| 727 | 'isolateId': '1', |
| 728 | }, |
| 729 | jsonResponse: fakeUnpausedIsolate.toJson(), |
| 730 | ), |
| 731 | FakeVmServiceRequest( |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 732 | method: 'ext.flutter.reassemble', |
| 733 | args: <String, Object>{ |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 734 | 'isolateId': fakeUnpausedIsolate.id, |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 735 | }, |
| 736 | ), |
| 737 | ]); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 738 | final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync(); |
| 739 | final Completer<void> futureAppStart = Completer<void>.sync(); |
Zachary Anderson | ef146f6 | 2019-07-29 07:24:02 -0700 | [diff] [blame] | 740 | unawaited(residentRunner.attach( |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 741 | appStartedCompleter: futureAppStart, |
| 742 | connectionInfoCompleter: futureConnectionInfo, |
| 743 | enableDevTools: true, |
Zachary Anderson | ef146f6 | 2019-07-29 07:24:02 -0700 | [diff] [blame] | 744 | )); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 745 | await futureAppStart.future; |
Zachary Anderson | ef146f6 | 2019-07-29 07:24:02 -0700 | [diff] [blame] | 746 | |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 747 | final OperationResult result = await residentRunner.restart(); |
Zachary Anderson | ef146f6 | 2019-07-29 07:24:02 -0700 | [diff] [blame] | 748 | expect(result.fatal, false); |
| 749 | expect(result.code, 0); |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 750 | |
| 751 | final TestUsageEvent event = (globals.flutterUsage as TestUsage).events.first; |
| 752 | expect(event.category, 'hot'); |
| 753 | expect(event.parameter, 'reload'); |
Lau Ching Jun | 2acd0007 | 2021-05-18 20:29:03 -0700 | [diff] [blame] | 754 | expect(event.parameters.hotEventTargetPlatform, getNameForTargetPlatform(TargetPlatform.android_arm)); |
Zachary Anderson | ef146f6 | 2019-07-29 07:24:02 -0700 | [diff] [blame] | 755 | }, overrides: <Type, Generator>{ |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 756 | Usage: () => TestUsage(), |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 757 | })); |
Zachary Anderson | ef146f6 | 2019-07-29 07:24:02 -0700 | [diff] [blame] | 758 | |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 759 | testUsingContext('ResidentRunner can perform fast reassemble', () => testbed.run(() async { |
| 760 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 761 | listViews, |
| 762 | FakeVmServiceRequest( |
| 763 | method: 'getVM', |
| 764 | jsonResponse: fakeVM.toJson(), |
| 765 | ), |
| 766 | listViews, |
| 767 | listViews, |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 768 | FakeVmServiceRequest( |
| 769 | method: 'getVM', |
| 770 | jsonResponse: fakeVM.toJson(), |
| 771 | ), |
| 772 | const FakeVmServiceRequest( |
| 773 | method: 'reloadSources', |
| 774 | args: <String, Object>{ |
| 775 | 'isolateId': '1', |
| 776 | 'pause': false, |
Jonah Williams | 0afddf3 | 2020-10-12 09:47:41 -0700 | [diff] [blame] | 777 | 'rootLibUri': 'main.dart.incremental.dill', |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 778 | }, |
| 779 | jsonResponse: <String, Object>{ |
| 780 | 'type': 'ReloadReport', |
| 781 | 'success': true, |
| 782 | 'details': <String, Object>{ |
| 783 | 'loadedLibraryCount': 1, |
| 784 | }, |
| 785 | }, |
| 786 | ), |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 787 | FakeVmServiceRequest( |
| 788 | method: 'getIsolate', |
| 789 | args: <String, Object>{ |
| 790 | 'isolateId': '1', |
| 791 | }, |
| 792 | jsonResponse: fakeUnpausedIsolate.toJson(), |
| 793 | ), |
| 794 | FakeVmServiceRequest( |
| 795 | method: 'ext.flutter.fastReassemble', |
| 796 | args: <String, Object>{ |
| 797 | 'isolateId': fakeUnpausedIsolate.id, |
Jonah Williams | a19f5ba | 2020-09-19 11:02:04 -0700 | [diff] [blame] | 798 | 'className': 'FOO', |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 799 | }, |
| 800 | ), |
| 801 | ]); |
Christopher Fujino | 91dd327 | 2021-10-02 10:18:03 -0700 | [diff] [blame] | 802 | final FakeDelegateFlutterDevice flutterDevice = FakeDelegateFlutterDevice( |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 803 | device, |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 804 | BuildInfo.debug, |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 805 | FakeResidentCompiler(), |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 806 | devFS, |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 807 | )..vmService = fakeVmServiceHost.vmService; |
| 808 | residentRunner = HotRunner( |
| 809 | <FlutterDevice>[ |
| 810 | flutterDevice, |
| 811 | ], |
| 812 | stayResident: false, |
| 813 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 814 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 815 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 816 | ); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 817 | devFS.nextUpdateReport = UpdateFSReport( |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 818 | success: true, |
| 819 | fastReassembleClassName: 'FOO', |
| 820 | invalidatedSourcesCount: 1, |
| 821 | ); |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 822 | |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 823 | final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync(); |
| 824 | final Completer<void> futureAppStart = Completer<void>.sync(); |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 825 | unawaited(residentRunner.attach( |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 826 | appStartedCompleter: futureAppStart, |
| 827 | connectionInfoCompleter: futureConnectionInfo, |
| 828 | enableDevTools: true, |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 829 | )); |
| 830 | |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 831 | await futureAppStart.future; |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 832 | final OperationResult result = await residentRunner.restart(); |
Jonah Williams | a19f5ba | 2020-09-19 11:02:04 -0700 | [diff] [blame] | 833 | |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 834 | expect(result.fatal, false); |
| 835 | expect(result.code, 0); |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 836 | |
| 837 | final TestUsageEvent event = (globals.flutterUsage as TestUsage).events.first; |
| 838 | expect(event.category, 'hot'); |
| 839 | expect(event.parameter, 'reload'); |
Lau Ching Jun | 2acd0007 | 2021-05-18 20:29:03 -0700 | [diff] [blame] | 840 | expect(event.parameters.fastReassemble, true); |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 841 | }, overrides: <Type, Generator>{ |
| 842 | FileSystem: () => MemoryFileSystem.test(), |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 843 | Platform: () => FakePlatform(), |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 844 | ProjectFileInvalidator: () => FakeProjectFileInvalidator(), |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 845 | Usage: () => TestUsage(), |
Jonah Williams | a19f5ba | 2020-09-19 11:02:04 -0700 | [diff] [blame] | 846 | FeatureFlags: () => TestFeatureFlags(isSingleWidgetReloadEnabled: true), |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 847 | })); |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 848 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 849 | testUsingContext('ResidentRunner can send target platform to analytics from full restart', () => testbed.run(() async { |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 850 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 851 | listViews, |
| 852 | listViews, |
| 853 | listViews, |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 854 | FakeVmServiceRequest( |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 855 | method: 'getIsolate', |
| 856 | args: <String, Object>{ |
| 857 | 'isolateId': fakeUnpausedIsolate.id, |
| 858 | }, |
| 859 | jsonResponse: fakeUnpausedIsolate.toJson(), |
| 860 | ), |
| 861 | FakeVmServiceRequest( |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 862 | method: 'getVM', |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 863 | jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson(), |
| 864 | ), |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 865 | listViews, |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 866 | const FakeVmServiceRequest( |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 867 | method: 'streamListen', |
| 868 | args: <String, Object>{ |
| 869 | 'streamId': 'Isolate', |
| 870 | }, |
| 871 | ), |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 872 | FakeVmServiceRequest( |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 873 | method: kRunInViewMethod, |
| 874 | args: <String, Object>{ |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 875 | 'viewId': fakeFlutterView.id, |
Jonah Williams | 0afddf3 | 2020-10-12 09:47:41 -0700 | [diff] [blame] | 876 | 'mainScript': 'main.dart.dill', |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 877 | 'assetDirectory': 'build/flutter_assets', |
| 878 | }, |
| 879 | ), |
| 880 | FakeVmServiceStreamResponse( |
| 881 | streamId: 'Isolate', |
| 882 | event: vm_service.Event( |
| 883 | timestamp: 0, |
| 884 | kind: vm_service.EventKind.kIsolateRunnable, |
| 885 | ) |
| 886 | ) |
| 887 | ]); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 888 | final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync(); |
| 889 | final Completer<void> futureAppStart = Completer<void>.sync(); |
Zachary Anderson | d208ce2 | 2019-07-30 12:18:15 -0700 | [diff] [blame] | 890 | unawaited(residentRunner.attach( |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 891 | appStartedCompleter: futureAppStart, |
| 892 | connectionInfoCompleter: futureConnectionInfo, |
| 893 | enableDevTools: true, |
Zachary Anderson | d208ce2 | 2019-07-30 12:18:15 -0700 | [diff] [blame] | 894 | )); |
| 895 | |
| 896 | final OperationResult result = await residentRunner.restart(fullRestart: true); |
| 897 | expect(result.fatal, false); |
| 898 | expect(result.code, 0); |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 899 | |
| 900 | final TestUsageEvent event = (globals.flutterUsage as TestUsage).events.first; |
| 901 | expect(event.category, 'hot'); |
| 902 | expect(event.parameter, 'restart'); |
Lau Ching Jun | 2acd0007 | 2021-05-18 20:29:03 -0700 | [diff] [blame] | 903 | expect(event.parameters.hotEventTargetPlatform, getNameForTargetPlatform(TargetPlatform.android_arm)); |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 904 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Zachary Anderson | d208ce2 | 2019-07-30 12:18:15 -0700 | [diff] [blame] | 905 | }, overrides: <Type, Generator>{ |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 906 | Usage: () => TestUsage(), |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 907 | })); |
Zachary Anderson | d208ce2 | 2019-07-30 12:18:15 -0700 | [diff] [blame] | 908 | |
Danny Tuppeny | 99e85b1 | 2021-11-19 06:23:09 +0000 | [diff] [blame] | 909 | testUsingContext('ResidentRunner can remove breakpoints and exception-pause-mode from paused isolate during hot restart', () => testbed.run(() async { |
Jonah Williams | c6dce23 | 2020-07-24 15:34:55 -0700 | [diff] [blame] | 910 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 911 | listViews, |
| 912 | listViews, |
| 913 | listViews, |
| 914 | FakeVmServiceRequest( |
| 915 | method: 'getIsolate', |
| 916 | args: <String, Object>{ |
| 917 | 'isolateId': fakeUnpausedIsolate.id, |
| 918 | }, |
| 919 | jsonResponse: fakePausedIsolate.toJson(), |
| 920 | ), |
| 921 | FakeVmServiceRequest( |
| 922 | method: 'getVM', |
| 923 | jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson(), |
| 924 | ), |
| 925 | const FakeVmServiceRequest( |
Anna Gringauze | d7466d8 | 2021-12-07 14:29:07 -0800 | [diff] [blame^] | 926 | method: 'setIsolatePauseMode', |
Danny Tuppeny | 99e85b1 | 2021-11-19 06:23:09 +0000 | [diff] [blame] | 927 | args: <String, String>{ |
| 928 | 'isolateId': '1', |
Anna Gringauze | d7466d8 | 2021-12-07 14:29:07 -0800 | [diff] [blame^] | 929 | 'exceptionPauseMode': 'None', |
Danny Tuppeny | 99e85b1 | 2021-11-19 06:23:09 +0000 | [diff] [blame] | 930 | } |
| 931 | ), |
| 932 | const FakeVmServiceRequest( |
Jonah Williams | c6dce23 | 2020-07-24 15:34:55 -0700 | [diff] [blame] | 933 | method: 'removeBreakpoint', |
| 934 | args: <String, String>{ |
| 935 | 'isolateId': '1', |
| 936 | 'breakpointId': 'test-breakpoint', |
| 937 | } |
| 938 | ), |
| 939 | const FakeVmServiceRequest( |
| 940 | method: 'resume', |
| 941 | args: <String, String>{ |
| 942 | 'isolateId': '1', |
| 943 | } |
| 944 | ), |
| 945 | listViews, |
| 946 | const FakeVmServiceRequest( |
| 947 | method: 'streamListen', |
| 948 | args: <String, Object>{ |
| 949 | 'streamId': 'Isolate', |
| 950 | }, |
| 951 | ), |
| 952 | FakeVmServiceRequest( |
| 953 | method: kRunInViewMethod, |
| 954 | args: <String, Object>{ |
| 955 | 'viewId': fakeFlutterView.id, |
Jonah Williams | 0afddf3 | 2020-10-12 09:47:41 -0700 | [diff] [blame] | 956 | 'mainScript': 'main.dart.dill', |
Jonah Williams | c6dce23 | 2020-07-24 15:34:55 -0700 | [diff] [blame] | 957 | 'assetDirectory': 'build/flutter_assets', |
| 958 | }, |
| 959 | ), |
| 960 | FakeVmServiceStreamResponse( |
| 961 | streamId: 'Isolate', |
| 962 | event: vm_service.Event( |
| 963 | timestamp: 0, |
| 964 | kind: vm_service.EventKind.kIsolateRunnable, |
| 965 | ) |
| 966 | ) |
| 967 | ]); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 968 | final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync(); |
| 969 | final Completer<void> futureAppStart = Completer<void>.sync(); |
Jonah Williams | c6dce23 | 2020-07-24 15:34:55 -0700 | [diff] [blame] | 970 | unawaited(residentRunner.attach( |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 971 | appStartedCompleter: futureAppStart, |
| 972 | connectionInfoCompleter: futureConnectionInfo, |
| 973 | enableDevTools: true, |
Jonah Williams | c6dce23 | 2020-07-24 15:34:55 -0700 | [diff] [blame] | 974 | )); |
| 975 | |
| 976 | final OperationResult result = await residentRunner.restart(fullRestart: true); |
| 977 | |
| 978 | expect(result.isOk, true); |
| 979 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 980 | })); |
Jonah Williams | c6dce23 | 2020-07-24 15:34:55 -0700 | [diff] [blame] | 981 | |
Jonah Williams | 6d36056 | 2020-09-09 15:56:25 -0700 | [diff] [blame] | 982 | testUsingContext('ResidentRunner will alternative the name of the dill file uploaded for a hot restart', () => testbed.run(() async { |
| 983 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 984 | listViews, |
| 985 | listViews, |
| 986 | listViews, |
| 987 | FakeVmServiceRequest( |
| 988 | method: 'getIsolate', |
| 989 | args: <String, Object>{ |
| 990 | 'isolateId': fakeUnpausedIsolate.id, |
| 991 | }, |
| 992 | jsonResponse: fakeUnpausedIsolate.toJson(), |
| 993 | ), |
| 994 | FakeVmServiceRequest( |
| 995 | method: 'getVM', |
| 996 | jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson(), |
| 997 | ), |
| 998 | listViews, |
| 999 | const FakeVmServiceRequest( |
| 1000 | method: 'streamListen', |
| 1001 | args: <String, Object>{ |
| 1002 | 'streamId': 'Isolate', |
| 1003 | }, |
| 1004 | ), |
| 1005 | FakeVmServiceRequest( |
| 1006 | method: kRunInViewMethod, |
| 1007 | args: <String, Object>{ |
| 1008 | 'viewId': fakeFlutterView.id, |
Jonah Williams | 0afddf3 | 2020-10-12 09:47:41 -0700 | [diff] [blame] | 1009 | 'mainScript': 'main.dart.dill', |
Jonah Williams | 6d36056 | 2020-09-09 15:56:25 -0700 | [diff] [blame] | 1010 | 'assetDirectory': 'build/flutter_assets', |
| 1011 | }, |
| 1012 | ), |
| 1013 | FakeVmServiceStreamResponse( |
| 1014 | streamId: 'Isolate', |
| 1015 | event: vm_service.Event( |
| 1016 | timestamp: 0, |
| 1017 | kind: vm_service.EventKind.kIsolateRunnable, |
| 1018 | ), |
| 1019 | ), |
| 1020 | listViews, |
| 1021 | FakeVmServiceRequest( |
| 1022 | method: 'getIsolate', |
| 1023 | args: <String, Object>{ |
| 1024 | 'isolateId': fakeUnpausedIsolate.id, |
| 1025 | }, |
| 1026 | jsonResponse: fakeUnpausedIsolate.toJson(), |
| 1027 | ), |
| 1028 | FakeVmServiceRequest( |
| 1029 | method: 'getVM', |
| 1030 | jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson(), |
| 1031 | ), |
| 1032 | listViews, |
| 1033 | const FakeVmServiceRequest( |
| 1034 | method: 'streamListen', |
| 1035 | args: <String, Object>{ |
| 1036 | 'streamId': 'Isolate', |
| 1037 | }, |
| 1038 | ), |
| 1039 | FakeVmServiceRequest( |
| 1040 | method: kRunInViewMethod, |
| 1041 | args: <String, Object>{ |
| 1042 | 'viewId': fakeFlutterView.id, |
Jonah Williams | 0afddf3 | 2020-10-12 09:47:41 -0700 | [diff] [blame] | 1043 | 'mainScript': 'main.dart.swap.dill', |
Jonah Williams | 6d36056 | 2020-09-09 15:56:25 -0700 | [diff] [blame] | 1044 | 'assetDirectory': 'build/flutter_assets', |
| 1045 | }, |
| 1046 | ), |
| 1047 | FakeVmServiceStreamResponse( |
| 1048 | streamId: 'Isolate', |
| 1049 | event: vm_service.Event( |
| 1050 | timestamp: 0, |
| 1051 | kind: vm_service.EventKind.kIsolateRunnable, |
| 1052 | ), |
| 1053 | ), |
| 1054 | listViews, |
| 1055 | FakeVmServiceRequest( |
| 1056 | method: 'getIsolate', |
| 1057 | args: <String, Object>{ |
| 1058 | 'isolateId': fakeUnpausedIsolate.id, |
| 1059 | }, |
| 1060 | jsonResponse: fakeUnpausedIsolate.toJson(), |
| 1061 | ), |
| 1062 | FakeVmServiceRequest( |
| 1063 | method: 'getVM', |
| 1064 | jsonResponse: vm_service.VM.parse(<String, Object>{}).toJson(), |
| 1065 | ), |
| 1066 | listViews, |
| 1067 | const FakeVmServiceRequest( |
| 1068 | method: 'streamListen', |
| 1069 | args: <String, Object>{ |
| 1070 | 'streamId': 'Isolate', |
| 1071 | }, |
| 1072 | ), |
| 1073 | FakeVmServiceRequest( |
| 1074 | method: kRunInViewMethod, |
| 1075 | args: <String, Object>{ |
| 1076 | 'viewId': fakeFlutterView.id, |
Jonah Williams | 0afddf3 | 2020-10-12 09:47:41 -0700 | [diff] [blame] | 1077 | 'mainScript': 'main.dart.dill', |
Jonah Williams | 6d36056 | 2020-09-09 15:56:25 -0700 | [diff] [blame] | 1078 | 'assetDirectory': 'build/flutter_assets', |
| 1079 | }, |
| 1080 | ), |
| 1081 | FakeVmServiceStreamResponse( |
| 1082 | streamId: 'Isolate', |
| 1083 | event: vm_service.Event( |
| 1084 | timestamp: 0, |
| 1085 | kind: vm_service.EventKind.kIsolateRunnable, |
| 1086 | ), |
| 1087 | ) |
| 1088 | ]); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1089 | final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync(); |
| 1090 | final Completer<void> futureAppStart = Completer<void>.sync(); |
Jonah Williams | 6d36056 | 2020-09-09 15:56:25 -0700 | [diff] [blame] | 1091 | unawaited(residentRunner.attach( |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1092 | appStartedCompleter: futureAppStart, |
| 1093 | connectionInfoCompleter: futureConnectionInfo, |
| 1094 | enableDevTools: true, |
Jonah Williams | 6d36056 | 2020-09-09 15:56:25 -0700 | [diff] [blame] | 1095 | )); |
| 1096 | |
| 1097 | await residentRunner.restart(fullRestart: true); |
| 1098 | await residentRunner.restart(fullRestart: true); |
| 1099 | await residentRunner.restart(fullRestart: true); |
| 1100 | |
| 1101 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 1102 | })); |
Jonah Williams | 6d36056 | 2020-09-09 15:56:25 -0700 | [diff] [blame] | 1103 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 1104 | testUsingContext('ResidentRunner Can handle an RPC exception from hot restart', () => testbed.run(() async { |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1105 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 1106 | listViews, |
| 1107 | listViews, |
| 1108 | ]); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1109 | final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync(); |
| 1110 | final Completer<void> futureAppStart = Completer<void>.sync(); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 1111 | unawaited(residentRunner.attach( |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1112 | appStartedCompleter: futureAppStart, |
| 1113 | connectionInfoCompleter: futureConnectionInfo, |
| 1114 | enableDevTools: true, |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 1115 | )); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1116 | await futureAppStart.future; |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1117 | flutterDevice.reportError = vm_service.RPCError('something bad happened', 666, ''); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 1118 | |
| 1119 | final OperationResult result = await residentRunner.restart(fullRestart: true); |
| 1120 | expect(result.fatal, true); |
| 1121 | expect(result.code, 1); |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 1122 | |
| 1123 | expect((globals.flutterUsage as TestUsage).events, contains( |
Lau Ching Jun | 2acd0007 | 2021-05-18 20:29:03 -0700 | [diff] [blame] | 1124 | TestUsageEvent('hot', 'exception', parameters: CustomDimensions( |
| 1125 | hotEventTargetPlatform: getNameForTargetPlatform(TargetPlatform.android_arm), |
| 1126 | hotEventSdkName: 'Android', |
| 1127 | hotEventEmulator: false, |
| 1128 | hotEventFullRestart: true, |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 1129 | fastReassemble: false, |
Lau Ching Jun | 2acd0007 | 2021-05-18 20:29:03 -0700 | [diff] [blame] | 1130 | )), |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 1131 | )); |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1132 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 1133 | }, overrides: <Type, Generator>{ |
Jenn Magder | 6ecb8cb | 2021-01-28 18:49:04 -0800 | [diff] [blame] | 1134 | Usage: () => TestUsage(), |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 1135 | })); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 1136 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 1137 | testUsingContext('ResidentRunner uses temp directory when there is no output dill path', () => testbed.run(() { |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 1138 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); |
Ian Hickson | cdc2d99 | 2019-10-07 16:43:04 -0700 | [diff] [blame] | 1139 | expect(residentRunner.artifactDirectory.path, contains('flutter_tool.')); |
Jonah Williams | 6d37867 | 2019-09-11 12:57:43 -0700 | [diff] [blame] | 1140 | |
| 1141 | final ResidentRunner otherRunner = HotRunner( |
| 1142 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1143 | flutterDevice, |
Jonah Williams | 6d37867 | 2019-09-11 12:57:43 -0700 | [diff] [blame] | 1144 | ], |
| 1145 | stayResident: false, |
| 1146 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame] | 1147 | dillOutputPath: globals.fs.path.join('foobar', 'app.dill'), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 1148 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 1149 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | 6d37867 | 2019-09-11 12:57:43 -0700 | [diff] [blame] | 1150 | ); |
| 1151 | expect(otherRunner.artifactDirectory.path, contains('foobar')); |
| 1152 | })); |
| 1153 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 1154 | testUsingContext('ResidentRunner deletes artifact directory on preExit', () => testbed.run(() async { |
Jonah Williams | 6d8ec35 | 2020-05-29 15:43:03 -0700 | [diff] [blame] | 1155 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1156 | residentRunner.artifactDirectory.childFile('app.dill').createSync(); |
Jonah Williams | 6d8ec35 | 2020-05-29 15:43:03 -0700 | [diff] [blame] | 1157 | await residentRunner.preExit(); |
Jonah Williams | 6d8ec35 | 2020-05-29 15:43:03 -0700 | [diff] [blame] | 1158 | |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1159 | expect(residentRunner.artifactDirectory, isNot(exists)); |
Jonah Williams | 6d8ec35 | 2020-05-29 15:43:03 -0700 | [diff] [blame] | 1160 | })); |
| 1161 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 1162 | testUsingContext('ResidentRunner can run source generation', () => testbed.run(() async { |
Shi-Hao Hong | b80b432 | 2020-09-04 00:26:58 +0800 | [diff] [blame] | 1163 | final File arbFile = globals.fs.file(globals.fs.path.join('lib', 'l10n', 'app_en.arb')) |
| 1164 | ..createSync(recursive: true); |
Alexandre Ardhuin | 73301a3 | 2020-10-16 00:37:04 +0200 | [diff] [blame] | 1165 | arbFile.writeAsStringSync(''' |
| 1166 | { |
Shi-Hao Hong | b80b432 | 2020-09-04 00:26:58 +0800 | [diff] [blame] | 1167 | "helloWorld": "Hello, World!", |
| 1168 | "@helloWorld": { |
| 1169 | "description": "Sample description" |
| 1170 | } |
| 1171 | }'''); |
Jonah Williams | 70b889a | 2020-05-18 12:47:18 -0700 | [diff] [blame] | 1172 | globals.fs.file('l10n.yaml').createSync(); |
Shi-Hao Hong | fd22fc3 | 2020-08-31 13:19:41 +0800 | [diff] [blame] | 1173 | globals.fs.file('pubspec.yaml').writeAsStringSync('flutter:\n generate: true\n'); |
Jonah Williams | 70b889a | 2020-05-18 12:47:18 -0700 | [diff] [blame] | 1174 | |
Emmanuel Garcia | b0a63c4 | 2021-04-23 15:34:04 -0700 | [diff] [blame] | 1175 | // Create necessary files for [DartPluginRegistrantTarget] |
| 1176 | final File packageConfig = globals.fs.directory('.dart_tool') |
| 1177 | .childFile('package_config.json'); |
| 1178 | packageConfig.createSync(recursive: true); |
| 1179 | packageConfig.writeAsStringSync(''' |
| 1180 | { |
| 1181 | "configVersion": 2, |
| 1182 | "packages": [ |
| 1183 | { |
| 1184 | "name": "path_provider_linux", |
| 1185 | "rootUri": "../../../path_provider_linux", |
| 1186 | "packageUri": "lib/", |
| 1187 | "languageVersion": "2.12" |
| 1188 | } |
| 1189 | ] |
| 1190 | } |
| 1191 | '''); |
| 1192 | // Start from an empty generated_main.dart file. |
| 1193 | globals.fs.directory('.dart_tool').childDirectory('flutter_build').childFile('generated_main.dart').createSync(recursive: true); |
| 1194 | |
Jonah Williams | 70b889a | 2020-05-18 12:47:18 -0700 | [diff] [blame] | 1195 | await residentRunner.runSourceGenerators(); |
| 1196 | |
| 1197 | expect(testLogger.errorText, isEmpty); |
Shi-Hao Hong | a1a096e | 2020-11-06 08:24:02 +0800 | [diff] [blame] | 1198 | expect(testLogger.statusText, isEmpty); |
Jonah Williams | 70b889a | 2020-05-18 12:47:18 -0700 | [diff] [blame] | 1199 | })); |
| 1200 | |
stuartmorgan | ed61608 | 2021-10-27 12:25:15 -0400 | [diff] [blame] | 1201 | testUsingContext('generated main uses correct target', () => testbed.run(() async { |
| 1202 | final File arbFile = globals.fs.file(globals.fs.path.join('lib', 'l10n', 'app_en.arb')) |
| 1203 | ..createSync(recursive: true); |
| 1204 | arbFile.writeAsStringSync(''' |
| 1205 | { |
| 1206 | "helloWorld": "Hello, World!", |
| 1207 | "@helloWorld": { |
| 1208 | "description": "Sample description" |
| 1209 | } |
| 1210 | }'''); |
| 1211 | globals.fs.file('l10n.yaml').createSync(); |
| 1212 | globals.fs.file('pubspec.yaml').writeAsStringSync(''' |
| 1213 | flutter: |
| 1214 | generate: true |
| 1215 | |
| 1216 | dependencies: |
| 1217 | flutter: |
| 1218 | sdk: flutter |
| 1219 | path_provider_linux: 1.0.0 |
| 1220 | '''); |
| 1221 | |
| 1222 | // Create necessary files for [DartPluginRegistrantTarget], including a |
| 1223 | // plugin that will trigger generation. |
| 1224 | final File packageConfig = globals.fs.directory('.dart_tool') |
| 1225 | .childFile('package_config.json'); |
| 1226 | packageConfig.createSync(recursive: true); |
| 1227 | packageConfig.writeAsStringSync(''' |
| 1228 | { |
| 1229 | "configVersion": 2, |
| 1230 | "packages": [ |
| 1231 | { |
| 1232 | "name": "path_provider_linux", |
| 1233 | "rootUri": "../path_provider_linux", |
| 1234 | "packageUri": "lib/", |
| 1235 | "languageVersion": "2.12" |
| 1236 | } |
| 1237 | ] |
| 1238 | } |
| 1239 | '''); |
| 1240 | globals.fs.file('.packages').writeAsStringSync(''' |
| 1241 | path_provider_linux:/path_provider_linux/lib/ |
| 1242 | '''); |
| 1243 | final Directory fakePluginDir = globals.fs.directory('path_provider_linux'); |
| 1244 | final File pluginPubspec = fakePluginDir.childFile('pubspec.yaml'); |
| 1245 | pluginPubspec.createSync(recursive: true); |
| 1246 | pluginPubspec.writeAsStringSync(''' |
| 1247 | name: path_provider_linux |
| 1248 | |
| 1249 | flutter: |
| 1250 | plugin: |
| 1251 | implements: path_provider |
| 1252 | platforms: |
| 1253 | linux: |
| 1254 | dartPluginClass: PathProviderLinux |
| 1255 | '''); |
| 1256 | |
| 1257 | residentRunner = HotRunner( |
| 1258 | <FlutterDevice>[ |
| 1259 | flutterDevice, |
| 1260 | ], |
| 1261 | stayResident: false, |
| 1262 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), |
| 1263 | target: 'custom_main.dart', |
| 1264 | devtoolsHandler: createNoOpHandler, |
| 1265 | ); |
| 1266 | await residentRunner.runSourceGenerators(); |
| 1267 | |
| 1268 | final File generatedMain = globals.fs.directory('.dart_tool') |
| 1269 | .childDirectory('flutter_build') |
| 1270 | .childFile('generated_main.dart'); |
| 1271 | |
| 1272 | expect(generatedMain.readAsStringSync(), contains('custom_main.dart')); |
| 1273 | expect(testLogger.errorText, isEmpty); |
| 1274 | expect(testLogger.statusText, isEmpty); |
| 1275 | })); |
| 1276 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 1277 | testUsingContext('ResidentRunner can run source generation - generation fails', () => testbed.run(() async { |
Shi-Hao Hong | b80b432 | 2020-09-04 00:26:58 +0800 | [diff] [blame] | 1278 | // Intentionally define arb file with wrong name. generate_localizations defaults |
| 1279 | // to app_en.arb. |
| 1280 | final File arbFile = globals.fs.file(globals.fs.path.join('lib', 'l10n', 'foo.arb')) |
| 1281 | ..createSync(recursive: true); |
Alexandre Ardhuin | 73301a3 | 2020-10-16 00:37:04 +0200 | [diff] [blame] | 1282 | arbFile.writeAsStringSync(''' |
| 1283 | { |
Shi-Hao Hong | b80b432 | 2020-09-04 00:26:58 +0800 | [diff] [blame] | 1284 | "helloWorld": "Hello, World!", |
| 1285 | "@helloWorld": { |
| 1286 | "description": "Sample description" |
| 1287 | } |
| 1288 | }'''); |
Jonah Williams | 70b889a | 2020-05-18 12:47:18 -0700 | [diff] [blame] | 1289 | globals.fs.file('l10n.yaml').createSync(); |
Shi-Hao Hong | fd22fc3 | 2020-08-31 13:19:41 +0800 | [diff] [blame] | 1290 | globals.fs.file('pubspec.yaml').writeAsStringSync('flutter:\n generate: true\n'); |
Jonah Williams | 70b889a | 2020-05-18 12:47:18 -0700 | [diff] [blame] | 1291 | |
| 1292 | await residentRunner.runSourceGenerators(); |
| 1293 | |
Shi-Hao Hong | b80b432 | 2020-09-04 00:26:58 +0800 | [diff] [blame] | 1294 | expect(testLogger.errorText, allOf(contains('Exception'))); |
| 1295 | expect(testLogger.statusText, isEmpty); |
Jonah Williams | 70b889a | 2020-05-18 12:47:18 -0700 | [diff] [blame] | 1296 | })); |
| 1297 | |
Ian Hickson | 598737a | 2021-04-22 19:34:02 -0700 | [diff] [blame] | 1298 | testUsingContext('ResidentRunner printHelpDetails hot runner', () => testbed.run(() { |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 1299 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 1300 | |
| 1301 | residentRunner.printHelp(details: true); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 1302 | |
Zachary Anderson | 4d096c4 | 2020-01-10 16:53:01 -0800 | [diff] [blame] | 1303 | final CommandHelp commandHelp = residentRunner.commandHelp; |
| 1304 | |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 1305 | // supports service protocol |
| 1306 | expect(residentRunner.supportsServiceProtocol, true); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 1307 | // isRunningDebug |
| 1308 | expect(residentRunner.isRunningDebug, true); |
Jonah Williams | 08fe78f | 2020-04-07 12:17:39 -0700 | [diff] [blame] | 1309 | // does support SkSL |
| 1310 | expect(residentRunner.supportsWriteSkSL, true); |
Zachary Anderson | 23ce192 | 2020-01-09 08:18:03 -0800 | [diff] [blame] | 1311 | // commands |
| 1312 | expect(testLogger.statusText, equals( |
| 1313 | <dynamic>[ |
| 1314 | 'Flutter run key commands.', |
Zachary Anderson | 4d096c4 | 2020-01-10 16:53:01 -0800 | [diff] [blame] | 1315 | commandHelp.r, |
| 1316 | commandHelp.R, |
Kenzie Schmoll | 766b450 | 2021-05-13 09:54:10 -0700 | [diff] [blame] | 1317 | commandHelp.v, |
Zachary Anderson | 4d096c4 | 2020-01-10 16:53:01 -0800 | [diff] [blame] | 1318 | commandHelp.s, |
| 1319 | commandHelp.w, |
| 1320 | commandHelp.t, |
| 1321 | commandHelp.L, |
| 1322 | commandHelp.S, |
| 1323 | commandHelp.U, |
| 1324 | commandHelp.i, |
| 1325 | commandHelp.p, |
Ian Hickson | 598737a | 2021-04-22 19:34:02 -0700 | [diff] [blame] | 1326 | commandHelp.I, |
Zachary Anderson | 4d096c4 | 2020-01-10 16:53:01 -0800 | [diff] [blame] | 1327 | commandHelp.o, |
Ian Hickson | 598737a | 2021-04-22 19:34:02 -0700 | [diff] [blame] | 1328 | commandHelp.b, |
Zachary Anderson | 4d096c4 | 2020-01-10 16:53:01 -0800 | [diff] [blame] | 1329 | commandHelp.P, |
| 1330 | commandHelp.a, |
Ian Hickson | 598737a | 2021-04-22 19:34:02 -0700 | [diff] [blame] | 1331 | commandHelp.M, |
| 1332 | commandHelp.g, |
| 1333 | commandHelp.hWithDetails, |
| 1334 | commandHelp.c, |
| 1335 | commandHelp.q, |
| 1336 | '', |
| 1337 | '💪 Running with sound null safety 💪', |
| 1338 | '', |
| 1339 | 'An Observatory debugger and profiler on FakeDevice is available at: null', |
| 1340 | '', |
| 1341 | ].join('\n') |
| 1342 | )); |
| 1343 | })); |
| 1344 | |
| 1345 | testUsingContext('ResidentRunner printHelp hot runner', () => testbed.run(() { |
| 1346 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); |
| 1347 | |
| 1348 | residentRunner.printHelp(details: false); |
| 1349 | |
| 1350 | final CommandHelp commandHelp = residentRunner.commandHelp; |
| 1351 | |
| 1352 | // supports service protocol |
| 1353 | expect(residentRunner.supportsServiceProtocol, true); |
| 1354 | // isRunningDebug |
| 1355 | expect(residentRunner.isRunningDebug, true); |
| 1356 | // does support SkSL |
| 1357 | expect(residentRunner.supportsWriteSkSL, true); |
| 1358 | // commands |
| 1359 | expect(testLogger.statusText, equals( |
| 1360 | <dynamic>[ |
| 1361 | 'Flutter run key commands.', |
| 1362 | commandHelp.r, |
| 1363 | commandHelp.R, |
| 1364 | commandHelp.hWithoutDetails, |
| 1365 | commandHelp.c, |
| 1366 | commandHelp.q, |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1367 | '', |
| 1368 | '💪 Running with sound null safety 💪', |
| 1369 | '', |
Jonah Williams | 6efe8e9 | 2021-01-29 14:27:42 -0800 | [diff] [blame] | 1370 | 'An Observatory debugger and profiler on FakeDevice is available at: null', |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1371 | '', |
Zachary Anderson | 23ce192 | 2020-01-09 08:18:03 -0800 | [diff] [blame] | 1372 | ].join('\n') |
| 1373 | )); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 1374 | })); |
| 1375 | |
Jonah Williams | c034f1a | 2020-09-02 17:33:41 -0700 | [diff] [blame] | 1376 | testUsingContext('ResidentRunner printHelpDetails cold runner', () => testbed.run(() { |
Jonah Williams | c034f1a | 2020-09-02 17:33:41 -0700 | [diff] [blame] | 1377 | fakeVmServiceHost = null; |
| 1378 | residentRunner = ColdRunner( |
| 1379 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1380 | flutterDevice, |
Jonah Williams | c034f1a | 2020-09-02 17:33:41 -0700 | [diff] [blame] | 1381 | ], |
| 1382 | stayResident: false, |
| 1383 | debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 1384 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 1385 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | c034f1a | 2020-09-02 17:33:41 -0700 | [diff] [blame] | 1386 | ); |
| 1387 | residentRunner.printHelp(details: true); |
| 1388 | |
| 1389 | final CommandHelp commandHelp = residentRunner.commandHelp; |
| 1390 | |
| 1391 | // does not supports service protocol |
| 1392 | expect(residentRunner.supportsServiceProtocol, false); |
| 1393 | // isRunningDebug |
| 1394 | expect(residentRunner.isRunningDebug, false); |
Jonah Williams | c034f1a | 2020-09-02 17:33:41 -0700 | [diff] [blame] | 1395 | // does support SkSL |
| 1396 | expect(residentRunner.supportsWriteSkSL, false); |
| 1397 | // commands |
| 1398 | expect(testLogger.statusText, equals( |
| 1399 | <dynamic>[ |
| 1400 | 'Flutter run key commands.', |
Kenzie Schmoll | 766b450 | 2021-05-13 09:54:10 -0700 | [diff] [blame] | 1401 | commandHelp.v, |
Jonah Williams | c034f1a | 2020-09-02 17:33:41 -0700 | [diff] [blame] | 1402 | commandHelp.s, |
Ian Hickson | 598737a | 2021-04-22 19:34:02 -0700 | [diff] [blame] | 1403 | commandHelp.hWithDetails, |
| 1404 | commandHelp.c, |
| 1405 | commandHelp.q, |
| 1406 | '' |
| 1407 | ].join('\n') |
| 1408 | )); |
| 1409 | })); |
| 1410 | |
| 1411 | testUsingContext('ResidentRunner printHelp cold runner', () => testbed.run(() { |
| 1412 | fakeVmServiceHost = null; |
| 1413 | residentRunner = ColdRunner( |
| 1414 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1415 | flutterDevice, |
Ian Hickson | 598737a | 2021-04-22 19:34:02 -0700 | [diff] [blame] | 1416 | ], |
| 1417 | stayResident: false, |
| 1418 | debuggingOptions: DebuggingOptions.disabled(BuildInfo.release), |
| 1419 | target: 'main.dart', |
| 1420 | devtoolsHandler: createNoOpHandler, |
| 1421 | ); |
| 1422 | residentRunner.printHelp(details: false); |
| 1423 | |
| 1424 | final CommandHelp commandHelp = residentRunner.commandHelp; |
| 1425 | |
| 1426 | // does not supports service protocol |
| 1427 | expect(residentRunner.supportsServiceProtocol, false); |
| 1428 | // isRunningDebug |
| 1429 | expect(residentRunner.isRunningDebug, false); |
| 1430 | // does support SkSL |
| 1431 | expect(residentRunner.supportsWriteSkSL, false); |
| 1432 | // commands |
| 1433 | expect(testLogger.statusText, equals( |
| 1434 | <dynamic>[ |
| 1435 | 'Flutter run key commands.', |
| 1436 | commandHelp.hWithoutDetails, |
Jonah Williams | c034f1a | 2020-09-02 17:33:41 -0700 | [diff] [blame] | 1437 | commandHelp.c, |
| 1438 | commandHelp.q, |
| 1439 | '' |
| 1440 | ].join('\n') |
| 1441 | )); |
| 1442 | })); |
| 1443 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 1444 | testUsingContext('ResidentRunner handles writeSkSL returning no data', () => testbed.run(() async { |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 1445 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1446 | listViews, |
| 1447 | FakeVmServiceRequest( |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 1448 | method: kGetSkSLsMethod, |
| 1449 | args: <String, Object>{ |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 1450 | 'viewId': fakeFlutterView.id, |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 1451 | }, |
| 1452 | jsonResponse: <String, Object>{ |
| 1453 | 'SkSLs': <String, Object>{} |
| 1454 | } |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1455 | ), |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 1456 | ]); |
Jonah Williams | 08fe78f | 2020-04-07 12:17:39 -0700 | [diff] [blame] | 1457 | await residentRunner.writeSkSL(); |
| 1458 | |
Jonah Williams | 08576cb | 2020-10-12 09:31:02 -0700 | [diff] [blame] | 1459 | expect(testLogger.statusText, contains('No data was received')); |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1460 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Jonah Williams | 08fe78f | 2020-04-07 12:17:39 -0700 | [diff] [blame] | 1461 | })); |
| 1462 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 1463 | testUsingContext('ResidentRunner can write SkSL data to a unique file with engine revision, platform, and device name', () => testbed.run(() async { |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 1464 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1465 | listViews, |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 1466 | FakeVmServiceRequest( |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 1467 | method: kGetSkSLsMethod, |
| 1468 | args: <String, Object>{ |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 1469 | 'viewId': fakeFlutterView.id, |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 1470 | }, |
| 1471 | jsonResponse: <String, Object>{ |
| 1472 | 'SkSLs': <String, Object>{ |
| 1473 | 'A': 'B', |
| 1474 | } |
| 1475 | } |
| 1476 | ) |
| 1477 | ]); |
Jonah Williams | 08fe78f | 2020-04-07 12:17:39 -0700 | [diff] [blame] | 1478 | await residentRunner.writeSkSL(); |
| 1479 | |
Jonah Williams | c570925 | 2020-05-08 09:44:03 -0700 | [diff] [blame] | 1480 | expect(testLogger.statusText, contains('flutter_01.sksl.json')); |
| 1481 | expect(globals.fs.file('flutter_01.sksl.json'), exists); |
| 1482 | expect(json.decode(globals.fs.file('flutter_01.sksl.json').readAsStringSync()), <String, Object>{ |
Jonah Williams | 368da5b | 2020-04-30 13:39:08 -0700 | [diff] [blame] | 1483 | 'platform': 'android', |
Jonah Williams | 6efe8e9 | 2021-01-29 14:27:42 -0800 | [diff] [blame] | 1484 | 'name': 'FakeDevice', |
Jonah Williams | 7217027 | 2021-03-05 14:04:03 -0800 | [diff] [blame] | 1485 | 'engineRevision': 'abcdefg', |
Jonah Williams | 08fe78f | 2020-04-07 12:17:39 -0700 | [diff] [blame] | 1486 | 'data': <String, Object>{'A': 'B'} |
| 1487 | }); |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 1488 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Jonah Williams | 5d61bff | 2020-06-24 10:23:59 -0700 | [diff] [blame] | 1489 | }, overrides: <Type, Generator>{ |
| 1490 | FileSystemUtils: () => FileSystemUtils( |
| 1491 | fileSystem: globals.fs, |
| 1492 | platform: globals.platform, |
Jonah Williams | 7217027 | 2021-03-05 14:04:03 -0800 | [diff] [blame] | 1493 | ), |
| 1494 | FlutterVersion: () => FakeFlutterVersion(engineRevision: 'abcdefg') |
Jonah Williams | 08fe78f | 2020-04-07 12:17:39 -0700 | [diff] [blame] | 1495 | })); |
| 1496 | |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1497 | testUsingContext('ResidentRunner ignores DevtoolsLauncher when attaching with enableDevTools: false - cold mode', () => testbed.run(() async { |
| 1498 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 1499 | listViews, |
| 1500 | listViews, |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1501 | ]); |
| 1502 | residentRunner = ColdRunner( |
| 1503 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1504 | flutterDevice, |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1505 | ], |
| 1506 | stayResident: false, |
| 1507 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile, vmserviceOutFile: 'foo'), |
| 1508 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 1509 | devtoolsHandler: createNoOpHandler, |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1510 | ); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1511 | |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 1512 | final Future<int> result = residentRunner.attach(); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1513 | expect(await result, 0); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 1514 | })); |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1515 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 1516 | testUsingContext('FlutterDevice can exit from a release mode isolate with no VmService', () => testbed.run(() async { |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1517 | final TestFlutterDevice flutterDevice = TestFlutterDevice( |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1518 | device, |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1519 | ); |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1520 | |
| 1521 | await flutterDevice.exitApps(); |
| 1522 | |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1523 | expect(device.appStopped, true); |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1524 | })); |
| 1525 | |
Jonah Williams | f666f93 | 2021-06-02 17:34:02 -0700 | [diff] [blame] | 1526 | testUsingContext('FlutterDevice will exit an un-paused isolate using stopApp', () => testbed.run(() async { |
| 1527 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 1528 | final TestFlutterDevice flutterDevice = TestFlutterDevice( |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1529 | device, |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 1530 | ); |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 1531 | flutterDevice.vmService = fakeVmServiceHost.vmService; |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 1532 | |
Jonah Williams | ffcf1db | 2020-04-27 17:41:42 -0700 | [diff] [blame] | 1533 | final Future<void> exitFuture = flutterDevice.exitApps(); |
| 1534 | |
| 1535 | await expectLater(exitFuture, completes); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1536 | expect(device.appStopped, true); |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 1537 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Jonah Williams | 1957c66 | 2019-07-18 10:40:40 -0700 | [diff] [blame] | 1538 | })); |
Jonah Williams | 3b4d9f6 | 2019-07-23 15:38:52 -0700 | [diff] [blame] | 1539 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 1540 | testUsingContext('HotRunner writes vm service file when providing debugging option', () => testbed.run(() async { |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1541 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 1542 | listViews, |
| 1543 | listViews, |
Jonah Williams | a3b14c5 | 2021-02-24 15:40:33 -0800 | [diff] [blame] | 1544 | ], wsAddress: testUri); |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame] | 1545 | globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 1546 | residentRunner = HotRunner( |
| 1547 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1548 | flutterDevice, |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 1549 | ], |
| 1550 | stayResident: false, |
| 1551 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 1552 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 1553 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 1554 | ); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1555 | |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1556 | await residentRunner.run(enableDevTools: true); |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 1557 | |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 1558 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame] | 1559 | expect(await globals.fs.file('foo').readAsString(), testUri.toString()); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 1560 | })); |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 1561 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 1562 | testUsingContext('HotRunner copies compiled app.dill to cache during startup', () => testbed.run(() async { |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1563 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 1564 | listViews, |
| 1565 | listViews, |
Jonah Williams | a3b14c5 | 2021-02-24 15:40:33 -0800 | [diff] [blame] | 1566 | ], wsAddress: testUri); |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1567 | globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); |
| 1568 | residentRunner = HotRunner( |
| 1569 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1570 | flutterDevice, |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1571 | ], |
| 1572 | stayResident: false, |
| 1573 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 1574 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 1575 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1576 | ); |
| 1577 | residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1578 | |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1579 | await residentRunner.run(enableDevTools: true); |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1580 | |
| 1581 | expect(await globals.fs.file(globals.fs.path.join('build', 'cache.dill')).readAsString(), 'ABC'); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 1582 | })); |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1583 | |
Jonah Williams | e54f8f5 | 2020-06-09 12:03:28 -0700 | [diff] [blame] | 1584 | testUsingContext('HotRunner copies compiled app.dill to cache during startup with dart defines', () => testbed.run(() async { |
| 1585 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 1586 | listViews, |
| 1587 | listViews, |
Jonah Williams | a3b14c5 | 2021-02-24 15:40:33 -0800 | [diff] [blame] | 1588 | ], wsAddress: testUri); |
Jonah Williams | e54f8f5 | 2020-06-09 12:03:28 -0700 | [diff] [blame] | 1589 | globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); |
| 1590 | residentRunner = HotRunner( |
| 1591 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1592 | flutterDevice, |
Jonah Williams | e54f8f5 | 2020-06-09 12:03:28 -0700 | [diff] [blame] | 1593 | ], |
| 1594 | stayResident: false, |
| 1595 | debuggingOptions: DebuggingOptions.enabled( |
| 1596 | const BuildInfo( |
| 1597 | BuildMode.debug, |
| 1598 | '', |
| 1599 | treeShakeIcons: false, |
| 1600 | dartDefines: <String>['a', 'b'], |
| 1601 | ) |
| 1602 | ), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 1603 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 1604 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | e54f8f5 | 2020-06-09 12:03:28 -0700 | [diff] [blame] | 1605 | ); |
| 1606 | residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1607 | |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1608 | await residentRunner.run(enableDevTools: true); |
Jonah Williams | e54f8f5 | 2020-06-09 12:03:28 -0700 | [diff] [blame] | 1609 | |
| 1610 | expect(await globals.fs.file(globals.fs.path.join( |
| 1611 | 'build', '187ef4436122d1cc2f40dc2b92f0eba0.cache.dill')).readAsString(), 'ABC'); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 1612 | })); |
Jonah Williams | e54f8f5 | 2020-06-09 12:03:28 -0700 | [diff] [blame] | 1613 | |
Jonah Williams | c543db7 | 2020-06-30 15:49:31 -0700 | [diff] [blame] | 1614 | testUsingContext('HotRunner copies compiled app.dill to cache during startup with null safety', () => testbed.run(() async { |
| 1615 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 1616 | listViews, |
| 1617 | listViews, |
Jonah Williams | a3b14c5 | 2021-02-24 15:40:33 -0800 | [diff] [blame] | 1618 | ], wsAddress: testUri); |
Jonah Williams | c543db7 | 2020-06-30 15:49:31 -0700 | [diff] [blame] | 1619 | globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); |
| 1620 | residentRunner = HotRunner( |
| 1621 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1622 | flutterDevice, |
Jonah Williams | c543db7 | 2020-06-30 15:49:31 -0700 | [diff] [blame] | 1623 | ], |
| 1624 | stayResident: false, |
| 1625 | debuggingOptions: DebuggingOptions.enabled( |
| 1626 | const BuildInfo( |
| 1627 | BuildMode.debug, |
| 1628 | '', |
| 1629 | treeShakeIcons: false, |
Jonah Williams | 1977ee7 | 2021-06-25 11:11:04 -0700 | [diff] [blame] | 1630 | extraFrontEndOptions: <String>['--enable-experiment=non-nullable'] |
Jonah Williams | c543db7 | 2020-06-30 15:49:31 -0700 | [diff] [blame] | 1631 | ) |
| 1632 | ), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 1633 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 1634 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | c543db7 | 2020-06-30 15:49:31 -0700 | [diff] [blame] | 1635 | ); |
| 1636 | residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1637 | |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1638 | await residentRunner.run(enableDevTools: true); |
Jonah Williams | c543db7 | 2020-06-30 15:49:31 -0700 | [diff] [blame] | 1639 | |
| 1640 | expect(await globals.fs.file(globals.fs.path.join( |
Jonah Williams | 1977ee7 | 2021-06-25 11:11:04 -0700 | [diff] [blame] | 1641 | 'build', 'cache.dill')).readAsString(), 'ABC'); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 1642 | })); |
Jonah Williams | c543db7 | 2020-06-30 15:49:31 -0700 | [diff] [blame] | 1643 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 1644 | testUsingContext('HotRunner does not copy app.dill if a dillOutputPath is given', () => testbed.run(() async { |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1645 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 1646 | listViews, |
| 1647 | listViews, |
Jonah Williams | a3b14c5 | 2021-02-24 15:40:33 -0800 | [diff] [blame] | 1648 | ], wsAddress: testUri); |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1649 | globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); |
| 1650 | residentRunner = HotRunner( |
| 1651 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1652 | flutterDevice, |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1653 | ], |
| 1654 | stayResident: false, |
| 1655 | dillOutputPath: 'test', |
| 1656 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 1657 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 1658 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1659 | ); |
| 1660 | residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1661 | |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1662 | await residentRunner.run(enableDevTools: true); |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1663 | |
| 1664 | expect(globals.fs.file(globals.fs.path.join('build', 'cache.dill')), isNot(exists)); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 1665 | })); |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1666 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 1667 | testUsingContext('HotRunner copies compiled app.dill to cache during startup with --track-widget-creation', () => testbed.run(() async { |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1668 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 1669 | listViews, |
| 1670 | listViews, |
Jonah Williams | a3b14c5 | 2021-02-24 15:40:33 -0800 | [diff] [blame] | 1671 | ], wsAddress: testUri); |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1672 | globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); |
| 1673 | residentRunner = HotRunner( |
| 1674 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1675 | flutterDevice, |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1676 | ], |
| 1677 | stayResident: false, |
| 1678 | debuggingOptions: DebuggingOptions.enabled(const BuildInfo( |
| 1679 | BuildMode.debug, |
| 1680 | '', |
| 1681 | treeShakeIcons: false, |
| 1682 | trackWidgetCreation: true, |
| 1683 | )), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 1684 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 1685 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1686 | ); |
| 1687 | residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1688 | |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1689 | await residentRunner.run(enableDevTools: true); |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1690 | |
| 1691 | expect(await globals.fs.file(globals.fs.path.join('build', 'cache.dill.track.dill')).readAsString(), 'ABC'); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 1692 | })); |
Jonah Williams | e934c2f | 2020-06-04 10:17:43 -0700 | [diff] [blame] | 1693 | |
Jonah Williams | 6efe8e9 | 2021-01-29 14:27:42 -0800 | [diff] [blame] | 1694 | testUsingContext('HotRunner calls device dispose', () => testbed.run(() async { |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1695 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 1696 | listViews, |
| 1697 | listViews, |
Jonah Williams | a3b14c5 | 2021-02-24 15:40:33 -0800 | [diff] [blame] | 1698 | ], wsAddress: testUri); |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame] | 1699 | globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); |
Zachary Anderson | 99684ce | 2019-12-05 08:48:00 -0800 | [diff] [blame] | 1700 | residentRunner = HotRunner( |
| 1701 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1702 | flutterDevice, |
Zachary Anderson | 99684ce | 2019-12-05 08:48:00 -0800 | [diff] [blame] | 1703 | ], |
| 1704 | stayResident: false, |
| 1705 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 1706 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 1707 | devtoolsHandler: createNoOpHandler, |
Zachary Anderson | 99684ce | 2019-12-05 08:48:00 -0800 | [diff] [blame] | 1708 | ); |
Zachary Anderson | 99684ce | 2019-12-05 08:48:00 -0800 | [diff] [blame] | 1709 | |
Zachary Anderson | 99684ce | 2019-12-05 08:48:00 -0800 | [diff] [blame] | 1710 | await residentRunner.run(); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1711 | expect(device.disposed, true); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 1712 | })); |
Zachary Anderson | 99684ce | 2019-12-05 08:48:00 -0800 | [diff] [blame] | 1713 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 1714 | testUsingContext('HotRunner handles failure to write vmservice file', () => testbed.run(() async { |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1715 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 1716 | listViews, |
| 1717 | listViews, |
| 1718 | ]); |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame] | 1719 | globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 1720 | residentRunner = HotRunner( |
| 1721 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1722 | flutterDevice, |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 1723 | ], |
| 1724 | stayResident: false, |
| 1725 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 1726 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 1727 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 1728 | ); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1729 | |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1730 | await residentRunner.run(enableDevTools: true); |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 1731 | |
Alexandre Ardhuin | 980f14e | 2019-11-24 06:54:43 +0100 | [diff] [blame] | 1732 | expect(testLogger.errorText, contains('Failed to write vmservice-out-file at foo')); |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1733 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 1734 | }, overrides: <Type, Generator>{ |
Jenn Magder | e8fbb43 | 2020-09-29 17:50:33 -0700 | [diff] [blame] | 1735 | FileSystem: () => ThrowingForwardingFileSystem(MemoryFileSystem.test()), |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 1736 | })); |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 1737 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 1738 | testUsingContext('ColdRunner writes vm service file when providing debugging option', () => testbed.run(() async { |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1739 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 1740 | listViews, |
Jonah Williams | a3b14c5 | 2021-02-24 15:40:33 -0800 | [diff] [blame] | 1741 | ], wsAddress: testUri); |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame] | 1742 | globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 1743 | residentRunner = ColdRunner( |
| 1744 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1745 | flutterDevice, |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 1746 | ], |
| 1747 | stayResident: false, |
| 1748 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile, vmserviceOutFile: 'foo'), |
Jonah Williams | 613a959 | 2020-11-20 14:17:11 -0800 | [diff] [blame] | 1749 | target: 'main.dart', |
Jonah Williams | 7ab8517 | 2021-02-10 17:04:47 -0800 | [diff] [blame] | 1750 | devtoolsHandler: createNoOpHandler, |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 1751 | ); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1752 | |
Ian Hickson | 8acac06 | 2021-02-01 16:06:02 -0800 | [diff] [blame] | 1753 | await residentRunner.run(enableDevTools: true); |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 1754 | |
Jonah Williams | ee7a37f | 2020-01-06 11:04:20 -0800 | [diff] [blame] | 1755 | expect(await globals.fs.file('foo').readAsString(), testUri.toString()); |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 1756 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 1757 | })); |
Jonah Williams | 79a985f | 2019-10-22 20:35:05 -0700 | [diff] [blame] | 1758 | |
Jonah Williams | 7ca324a | 2020-06-30 12:29:42 -0700 | [diff] [blame] | 1759 | testUsingContext('FlutterDevice uses dartdevc configuration when targeting web', () async { |
Jonah Williams | 9202e54 | 2020-04-20 15:15:54 -0700 | [diff] [blame] | 1760 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1761 | final FakeDevice device = FakeDevice(targetPlatform: TargetPlatform.web_javascript); |
Jonah Williams | 79a985f | 2019-10-22 20:35:05 -0700 | [diff] [blame] | 1762 | final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create( |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1763 | device, |
Jonah Williams | 7ca324a | 2020-06-30 12:29:42 -0700 | [diff] [blame] | 1764 | buildInfo: const BuildInfo( |
| 1765 | BuildMode.debug, |
| 1766 | '', |
| 1767 | treeShakeIcons: false, |
| 1768 | nullSafetyMode: NullSafetyMode.unsound, |
| 1769 | ), |
Jonah Williams | 79a985f | 2019-10-22 20:35:05 -0700 | [diff] [blame] | 1770 | target: null, |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 1771 | platform: FakePlatform(), |
Alexandre Ardhuin | 980f14e | 2019-11-24 06:54:43 +0100 | [diff] [blame] | 1772 | )).generator as DefaultResidentCompiler; |
Jonah Williams | 79a985f | 2019-10-22 20:35:05 -0700 | [diff] [blame] | 1773 | |
Jonah Williams | 6d8ec35 | 2020-05-29 15:43:03 -0700 | [diff] [blame] | 1774 | expect(residentCompiler.initializeFromDill, |
Jonah Williams | 0a73ecf | 2020-11-13 09:41:11 -0800 | [diff] [blame] | 1775 | globals.fs.path.join(getBuildDirectory(), 'fbbe6a61fb7a1de317d381f8df4814e5.cache.dill')); |
Jonah Williams | 515027a | 2020-02-28 11:26:02 -0800 | [diff] [blame] | 1776 | expect(residentCompiler.librariesSpec, |
Jonah Williams | b30d97a | 2021-04-22 19:29:02 -0700 | [diff] [blame] | 1777 | globals.fs.file(globals.artifacts.getHostArtifact(HostArtifact.flutterWebLibrariesJson)) |
Jonah Williams | 515027a | 2020-02-28 11:26:02 -0800 | [diff] [blame] | 1778 | .uri.toString()); |
Jonah Williams | 79a985f | 2019-10-22 20:35:05 -0700 | [diff] [blame] | 1779 | expect(residentCompiler.targetModel, TargetModel.dartdevc); |
| 1780 | expect(residentCompiler.sdkRoot, |
Alexandre Ardhuin | 34059ee | 2021-06-01 20:14:06 +0200 | [diff] [blame] | 1781 | '${globals.artifacts.getHostArtifact(HostArtifact.flutterWebSdk).path}/'); |
Jonah Williams | b30d97a | 2021-04-22 19:29:02 -0700 | [diff] [blame] | 1782 | expect(residentCompiler.platformDill, 'file:///HostArtifact.webPlatformKernelDill'); |
Jonah Williams | 7ca324a | 2020-06-30 12:29:42 -0700 | [diff] [blame] | 1783 | }, overrides: <Type, Generator>{ |
| 1784 | Artifacts: () => Artifacts.test(), |
| 1785 | FileSystem: () => MemoryFileSystem.test(), |
| 1786 | ProcessManager: () => FakeProcessManager.any(), |
| 1787 | }); |
| 1788 | |
| 1789 | testUsingContext('FlutterDevice uses dartdevc configuration when targeting web with null-safety autodetected', () async { |
| 1790 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1791 | final FakeDevice device = FakeDevice(targetPlatform: TargetPlatform.web_javascript); |
Jonah Williams | 7ca324a | 2020-06-30 12:29:42 -0700 | [diff] [blame] | 1792 | |
| 1793 | final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create( |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1794 | device, |
Jonah Williams | 7ca324a | 2020-06-30 12:29:42 -0700 | [diff] [blame] | 1795 | buildInfo: const BuildInfo( |
| 1796 | BuildMode.debug, |
| 1797 | '', |
| 1798 | treeShakeIcons: false, |
| 1799 | extraFrontEndOptions: <String>['--enable-experiment=non-nullable'], |
| 1800 | ), |
Jonah Williams | 7ca324a | 2020-06-30 12:29:42 -0700 | [diff] [blame] | 1801 | target: null, |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 1802 | platform: FakePlatform(), |
Jonah Williams | 7ca324a | 2020-06-30 12:29:42 -0700 | [diff] [blame] | 1803 | )).generator as DefaultResidentCompiler; |
| 1804 | |
| 1805 | expect(residentCompiler.initializeFromDill, |
Jonah Williams | 1977ee7 | 2021-06-25 11:11:04 -0700 | [diff] [blame] | 1806 | globals.fs.path.join(getBuildDirectory(), '80b1a4cf4e7b90e1ab5f72022a0bc624.cache.dill')); |
Jonah Williams | 7ca324a | 2020-06-30 12:29:42 -0700 | [diff] [blame] | 1807 | expect(residentCompiler.librariesSpec, |
Jonah Williams | b30d97a | 2021-04-22 19:29:02 -0700 | [diff] [blame] | 1808 | globals.fs.file(globals.artifacts.getHostArtifact(HostArtifact.flutterWebLibrariesJson)) |
Jonah Williams | 7ca324a | 2020-06-30 12:29:42 -0700 | [diff] [blame] | 1809 | .uri.toString()); |
| 1810 | expect(residentCompiler.targetModel, TargetModel.dartdevc); |
| 1811 | expect(residentCompiler.sdkRoot, |
Alexandre Ardhuin | 34059ee | 2021-06-01 20:14:06 +0200 | [diff] [blame] | 1812 | '${globals.artifacts.getHostArtifact(HostArtifact.flutterWebSdk).path}/'); |
Jonah Williams | b30d97a | 2021-04-22 19:29:02 -0700 | [diff] [blame] | 1813 | expect(residentCompiler.platformDill, 'file:///HostArtifact.webPlatformSoundKernelDill'); |
Jonah Williams | 7ca324a | 2020-06-30 12:29:42 -0700 | [diff] [blame] | 1814 | }, overrides: <Type, Generator>{ |
| 1815 | Artifacts: () => Artifacts.test(), |
| 1816 | FileSystem: () => MemoryFileSystem.test(), |
| 1817 | ProcessManager: () => FakeProcessManager.any(), |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 1818 | }); |
Jenn Magder | 2e7d913 | 2019-11-01 14:37:17 -0700 | [diff] [blame] | 1819 | |
Jonah Williams | a19f5ba | 2020-09-19 11:02:04 -0700 | [diff] [blame] | 1820 | testUsingContext('FlutterDevice passes flutter-widget-cache flag when feature is enabled', () async { |
| 1821 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 1822 | final FakeDevice device = FakeDevice(); |
Jonah Williams | a19f5ba | 2020-09-19 11:02:04 -0700 | [diff] [blame] | 1823 | |
| 1824 | final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create( |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1825 | device, |
Jonah Williams | a19f5ba | 2020-09-19 11:02:04 -0700 | [diff] [blame] | 1826 | buildInfo: const BuildInfo( |
| 1827 | BuildMode.debug, |
| 1828 | '', |
| 1829 | treeShakeIcons: false, |
| 1830 | extraFrontEndOptions: <String>[], |
| 1831 | ), |
Jonah Williams | 51ededb | 2020-09-23 07:03:59 -0700 | [diff] [blame] | 1832 | target: null, platform: null, |
Jonah Williams | a19f5ba | 2020-09-19 11:02:04 -0700 | [diff] [blame] | 1833 | )).generator as DefaultResidentCompiler; |
| 1834 | |
| 1835 | expect(residentCompiler.extraFrontEndOptions, |
| 1836 | contains('--flutter-widget-cache')); |
| 1837 | }, overrides: <Type, Generator>{ |
| 1838 | Artifacts: () => Artifacts.test(), |
| 1839 | FileSystem: () => MemoryFileSystem.test(), |
| 1840 | ProcessManager: () => FakeProcessManager.any(), |
| 1841 | FeatureFlags: () => TestFeatureFlags(isSingleWidgetReloadEnabled: true) |
| 1842 | }); |
| 1843 | |
Jonah Williams | 67a57eb | 2021-06-10 11:59:04 -0700 | [diff] [blame] | 1844 | testUsingContext('FlutterDevice passes alternative-invalidation-strategy flag', () async { |
Jonah Williams | 1816778 | 2020-12-01 09:54:23 -0800 | [diff] [blame] | 1845 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 1846 | final FakeDevice device = FakeDevice(); |
Jonah Williams | 6efe8e9 | 2021-01-29 14:27:42 -0800 | [diff] [blame] | 1847 | |
Jonah Williams | 1816778 | 2020-12-01 09:54:23 -0800 | [diff] [blame] | 1848 | |
| 1849 | final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create( |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1850 | device, |
Jonah Williams | 1816778 | 2020-12-01 09:54:23 -0800 | [diff] [blame] | 1851 | buildInfo: const BuildInfo( |
| 1852 | BuildMode.debug, |
| 1853 | '', |
| 1854 | treeShakeIcons: false, |
| 1855 | extraFrontEndOptions: <String>[], |
| 1856 | ), |
| 1857 | target: null, platform: null, |
| 1858 | )).generator as DefaultResidentCompiler; |
| 1859 | |
| 1860 | expect(residentCompiler.extraFrontEndOptions, |
| 1861 | contains('--enable-experiment=alternative-invalidation-strategy')); |
| 1862 | }, overrides: <Type, Generator>{ |
| 1863 | Artifacts: () => Artifacts.test(), |
| 1864 | FileSystem: () => MemoryFileSystem.test(), |
| 1865 | ProcessManager: () => FakeProcessManager.any(), |
Jonah Williams | 1816778 | 2020-12-01 09:54:23 -0800 | [diff] [blame] | 1866 | }); |
| 1867 | |
Lau Ching Jun | a9d6131 | 2021-05-26 23:06:38 -0700 | [diff] [blame] | 1868 | testUsingContext('FlutterDevice passes initializeFromDill parameter if specified', () async { |
| 1869 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); |
Ian Hickson | 61a0add | 2021-10-08 09:25:14 -0700 | [diff] [blame] | 1870 | final FakeDevice device = FakeDevice(); |
Lau Ching Jun | a9d6131 | 2021-05-26 23:06:38 -0700 | [diff] [blame] | 1871 | |
| 1872 | final DefaultResidentCompiler residentCompiler = (await FlutterDevice.create( |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1873 | device, |
Lau Ching Jun | a9d6131 | 2021-05-26 23:06:38 -0700 | [diff] [blame] | 1874 | buildInfo: const BuildInfo( |
| 1875 | BuildMode.debug, |
| 1876 | '', |
| 1877 | treeShakeIcons: false, |
| 1878 | extraFrontEndOptions: <String>[], |
| 1879 | initializeFromDill: '/foo/bar.dill', |
| 1880 | ), |
| 1881 | target: null, platform: null, |
| 1882 | )).generator as DefaultResidentCompiler; |
| 1883 | |
| 1884 | expect(residentCompiler.initializeFromDill, '/foo/bar.dill'); |
| 1885 | }, overrides: <Type, Generator>{ |
| 1886 | Artifacts: () => Artifacts.test(), |
| 1887 | FileSystem: () => MemoryFileSystem.test(), |
| 1888 | ProcessManager: () => FakeProcessManager.any(), |
| 1889 | }); |
| 1890 | |
Ben Konyi | 92427f2 | 2021-01-25 12:29:05 -0800 | [diff] [blame] | 1891 | testUsingContext('Handle existing VM service clients DDS error', () => testbed.run(() async { |
| 1892 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1893 | final FakeDevice device = FakeDevice() |
Jonah Williams | 6b3093b | 2021-03-31 12:59:00 -0700 | [diff] [blame] | 1894 | ..dds = DartDevelopmentService(); |
Ben Konyi | ac3c443 | 2021-10-20 22:05:49 -0700 | [diff] [blame] | 1895 | ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri}) { |
Jenn Magder | 2d55032 | 2021-08-17 21:12:03 -0700 | [diff] [blame] | 1896 | expect(uri, Uri(scheme: 'foo', host: 'bar')); |
| 1897 | expect(enableAuthCodes, isTrue); |
| 1898 | expect(ipv6, isFalse); |
| 1899 | expect(serviceUri, Uri(scheme: 'http', host: '127.0.0.1', port: 0)); |
Ben Konyi | 92427f2 | 2021-01-25 12:29:05 -0800 | [diff] [blame] | 1900 | throw FakeDartDevelopmentServiceException(message: |
| 1901 | 'Existing VM service clients prevent DDS from taking control.', |
| 1902 | ); |
| 1903 | }; |
| 1904 | final TestFlutterDevice flutterDevice = TestFlutterDevice( |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1905 | device, |
Ben Konyi | 92427f2 | 2021-01-25 12:29:05 -0800 | [diff] [blame] | 1906 | observatoryUris: Stream<Uri>.value(testUri), |
| 1907 | ); |
| 1908 | bool caught = false; |
| 1909 | final Completer<void>done = Completer<void>(); |
| 1910 | runZonedGuarded(() { |
| 1911 | flutterDevice.connect(allowExistingDdsInstance: true).then((_) => done.complete()); |
| 1912 | }, (Object e, StackTrace st) { |
| 1913 | expect(e is ToolExit, true); |
| 1914 | expect((e as ToolExit).message, |
| 1915 | contains('Existing VM service clients prevent DDS from taking control.', |
| 1916 | )); |
| 1917 | done.complete(); |
| 1918 | caught = true; |
| 1919 | }); |
| 1920 | await done.future; |
| 1921 | if (!caught) { |
| 1922 | fail('Expected ToolExit to be thrown.'); |
| 1923 | } |
| 1924 | }, overrides: <Type, Generator>{ |
| 1925 | VMServiceConnector: () => (Uri httpUri, { |
| 1926 | ReloadSources reloadSources, |
| 1927 | Restart restart, |
| 1928 | CompileExpression compileExpression, |
| 1929 | GetSkSLMethod getSkSLMethod, |
| 1930 | PrintStructuredErrorLogMethod printStructuredErrorLogMethod, |
| 1931 | io.CompressionOptions compression, |
| 1932 | Device device, |
Jonah Williams | 4ae68a3 | 2021-04-01 13:23:40 -0700 | [diff] [blame] | 1933 | Logger logger, |
Jonah Williams | 6728cf3 | 2021-06-10 12:00:38 -0700 | [diff] [blame] | 1934 | }) async => FakeVmServiceHost(requests: <VmServiceExpectation>[]).vmService, |
Ben Konyi | 92427f2 | 2021-01-25 12:29:05 -0800 | [diff] [blame] | 1935 | })); |
| 1936 | |
Jenn Magder | 2d55032 | 2021-08-17 21:12:03 -0700 | [diff] [blame] | 1937 | testUsingContext('Host VM service ipv6 defaults', () => testbed.run(() async { |
| 1938 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); |
| 1939 | final FakeDevice device = FakeDevice() |
| 1940 | ..dds = DartDevelopmentService(); |
| 1941 | final Completer<void>done = Completer<void>(); |
Ben Konyi | ac3c443 | 2021-10-20 22:05:49 -0700 | [diff] [blame] | 1942 | ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri}) async { |
Jenn Magder | 2d55032 | 2021-08-17 21:12:03 -0700 | [diff] [blame] | 1943 | expect(uri, Uri(scheme: 'foo', host: 'bar')); |
| 1944 | expect(enableAuthCodes, isFalse); |
| 1945 | expect(ipv6, isTrue); |
| 1946 | expect(serviceUri, Uri(scheme: 'http', host: '::1', port: 0)); |
| 1947 | done.complete(); |
| 1948 | return null; |
| 1949 | }; |
| 1950 | final TestFlutterDevice flutterDevice = TestFlutterDevice( |
| 1951 | device, |
| 1952 | observatoryUris: Stream<Uri>.value(testUri), |
| 1953 | ); |
| 1954 | await flutterDevice.connect(allowExistingDdsInstance: true, ipv6: true, disableServiceAuthCodes: true); |
| 1955 | await done.future; |
| 1956 | }, overrides: <Type, Generator>{ |
| 1957 | VMServiceConnector: () => (Uri httpUri, { |
| 1958 | ReloadSources reloadSources, |
| 1959 | Restart restart, |
| 1960 | CompileExpression compileExpression, |
| 1961 | GetSkSLMethod getSkSLMethod, |
| 1962 | PrintStructuredErrorLogMethod printStructuredErrorLogMethod, |
| 1963 | io.CompressionOptions compression, |
| 1964 | Device device, |
| 1965 | Logger logger, |
| 1966 | }) async => FakeVmServiceHost(requests: <VmServiceExpectation>[]).vmService, |
| 1967 | })); |
| 1968 | |
Ben Konyi | 620a828 | 2020-12-22 10:24:04 -0800 | [diff] [blame] | 1969 | testUsingContext('Failed DDS start outputs error message', () => testbed.run(() async { |
| 1970 | // See https://github.com/flutter/flutter/issues/72385 for context. |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1971 | final FakeDevice device = FakeDevice() |
Jonah Williams | 6b3093b | 2021-03-31 12:59:00 -0700 | [diff] [blame] | 1972 | ..dds = DartDevelopmentService(); |
Ben Konyi | ac3c443 | 2021-10-20 22:05:49 -0700 | [diff] [blame] | 1973 | ddsLauncherCallback = (Uri uri, {bool enableAuthCodes, bool ipv6, Uri serviceUri}) { |
Jenn Magder | 2d55032 | 2021-08-17 21:12:03 -0700 | [diff] [blame] | 1974 | expect(uri, Uri(scheme: 'foo', host: 'bar')); |
| 1975 | expect(enableAuthCodes, isTrue); |
| 1976 | expect(ipv6, isFalse); |
| 1977 | expect(serviceUri, Uri(scheme: 'http', host: '127.0.0.1', port: 0)); |
Ben Konyi | 620a828 | 2020-12-22 10:24:04 -0800 | [diff] [blame] | 1978 | throw FakeDartDevelopmentServiceException(message: 'No URI'); |
| 1979 | }; |
| 1980 | final TestFlutterDevice flutterDevice = TestFlutterDevice( |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 1981 | device, |
Ben Konyi | 620a828 | 2020-12-22 10:24:04 -0800 | [diff] [blame] | 1982 | observatoryUris: Stream<Uri>.value(testUri), |
| 1983 | ); |
| 1984 | bool caught = false; |
| 1985 | final Completer<void>done = Completer<void>(); |
| 1986 | runZonedGuarded(() { |
| 1987 | flutterDevice.connect(allowExistingDdsInstance: true).then((_) => done.complete()); |
| 1988 | }, (Object e, StackTrace st) { |
| 1989 | expect(e is StateError, true); |
| 1990 | expect((e as StateError).message, contains('No URI')); |
| 1991 | expect(testLogger.errorText, contains( |
| 1992 | 'DDS has failed to start and there is not an existing DDS instance', |
| 1993 | )); |
| 1994 | done.complete(); |
| 1995 | caught = true; |
| 1996 | }); |
| 1997 | await done.future; |
| 1998 | if (!caught) { |
| 1999 | fail('Expected a StateError to be thrown.'); |
| 2000 | } |
Ben Konyi | 913d593 | 2021-01-19 22:34:03 -0800 | [diff] [blame] | 2001 | }, overrides: <Type, Generator>{ |
| 2002 | VMServiceConnector: () => (Uri httpUri, { |
| 2003 | ReloadSources reloadSources, |
| 2004 | Restart restart, |
| 2005 | CompileExpression compileExpression, |
| 2006 | GetSkSLMethod getSkSLMethod, |
| 2007 | PrintStructuredErrorLogMethod printStructuredErrorLogMethod, |
| 2008 | io.CompressionOptions compression, |
| 2009 | Device device, |
Jonah Williams | 4ae68a3 | 2021-04-01 13:23:40 -0700 | [diff] [blame] | 2010 | Logger logger, |
Jonah Williams | 6728cf3 | 2021-06-10 12:00:38 -0700 | [diff] [blame] | 2011 | }) async => FakeVmServiceHost(requests: <VmServiceExpectation>[]).vmService, |
Ben Konyi | 620a828 | 2020-12-22 10:24:04 -0800 | [diff] [blame] | 2012 | })); |
Ben Konyi | 89ef88c | 2020-12-04 17:16:30 -0800 | [diff] [blame] | 2013 | |
Jenn Magder | 8863133 | 2020-06-08 11:28:02 -0700 | [diff] [blame] | 2014 | testUsingContext('nextPlatform moves through expected platforms', () { |
Jonah Williams | 9904a7f | 2021-04-16 17:27:35 -0700 | [diff] [blame] | 2015 | expect(nextPlatform('android'), 'iOS'); |
| 2016 | expect(nextPlatform('iOS'), 'fuchsia'); |
| 2017 | expect(nextPlatform('fuchsia'), 'macOS'); |
| 2018 | expect(nextPlatform('macOS'), 'android'); |
| 2019 | expect(() => nextPlatform('unknown'), throwsAssertionError); |
Jonah Williams | 5ba2830 | 2019-12-12 15:20:52 -0800 | [diff] [blame] | 2020 | }); |
Jason Simmons | f94fa27 | 2021-04-18 09:34:03 -0700 | [diff] [blame] | 2021 | |
| 2022 | testUsingContext('cleanupAtFinish shuts down resident devtools handler', () => testbed.run(() async { |
| 2023 | residentRunner = HotRunner( |
| 2024 | <FlutterDevice>[ |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 2025 | flutterDevice, |
Jason Simmons | f94fa27 | 2021-04-18 09:34:03 -0700 | [diff] [blame] | 2026 | ], |
| 2027 | stayResident: false, |
| 2028 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, vmserviceOutFile: 'foo'), |
| 2029 | target: 'main.dart', |
| 2030 | devtoolsHandler: createNoOpHandler, |
| 2031 | ); |
| 2032 | await residentRunner.cleanupAtFinish(); |
| 2033 | |
| 2034 | expect((residentRunner.residentDevtoolsHandler as NoOpDevtoolsHandler).wasShutdown, true); |
| 2035 | })); |
Lau Ching Jun | af42e7d | 2021-06-28 13:16:04 -0700 | [diff] [blame] | 2036 | |
| 2037 | testUsingContext('HotRunner sets asset directory when first evict assets', () => testbed.run(() async { |
| 2038 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 2039 | listViews, |
| 2040 | setAssetBundlePath, |
| 2041 | evict, |
| 2042 | ]); |
| 2043 | residentRunner = HotRunner( |
| 2044 | <FlutterDevice>[ |
| 2045 | flutterDevice, |
| 2046 | ], |
| 2047 | stayResident: false, |
| 2048 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), |
| 2049 | target: 'main.dart', |
| 2050 | devtoolsHandler: createNoOpHandler, |
| 2051 | ); |
| 2052 | |
| 2053 | (flutterDevice.devFS as FakeDevFS).assetPathsToEvict = <String>{'asset'}; |
| 2054 | |
| 2055 | expect(flutterDevice.devFS.hasSetAssetDirectory, false); |
| 2056 | await (residentRunner as HotRunner).evictDirtyAssets(); |
| 2057 | expect(flutterDevice.devFS.hasSetAssetDirectory, true); |
| 2058 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
| 2059 | })); |
| 2060 | |
| 2061 | testUsingContext('HotRunner does not sets asset directory when no assets to evict', () => testbed.run(() async { |
| 2062 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 2063 | ]); |
| 2064 | residentRunner = HotRunner( |
| 2065 | <FlutterDevice>[ |
| 2066 | flutterDevice, |
| 2067 | ], |
| 2068 | stayResident: false, |
| 2069 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), |
| 2070 | target: 'main.dart', |
| 2071 | devtoolsHandler: createNoOpHandler, |
| 2072 | ); |
| 2073 | |
| 2074 | expect(flutterDevice.devFS.hasSetAssetDirectory, false); |
| 2075 | await (residentRunner as HotRunner).evictDirtyAssets(); |
| 2076 | expect(flutterDevice.devFS.hasSetAssetDirectory, false); |
| 2077 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
| 2078 | })); |
| 2079 | |
| 2080 | testUsingContext('HotRunner does not set asset directory if it has been set before', () => testbed.run(() async { |
| 2081 | fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ |
| 2082 | listViews, |
| 2083 | evict, |
| 2084 | ]); |
| 2085 | residentRunner = HotRunner( |
| 2086 | <FlutterDevice>[ |
| 2087 | flutterDevice, |
| 2088 | ], |
| 2089 | stayResident: false, |
| 2090 | debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), |
| 2091 | target: 'main.dart', |
| 2092 | devtoolsHandler: createNoOpHandler, |
| 2093 | ); |
| 2094 | |
| 2095 | (flutterDevice.devFS as FakeDevFS).assetPathsToEvict = <String>{'asset'}; |
| 2096 | flutterDevice.devFS.hasSetAssetDirectory = true; |
| 2097 | |
| 2098 | await (residentRunner as HotRunner).evictDirtyAssets(); |
| 2099 | expect(flutterDevice.devFS.hasSetAssetDirectory, true); |
| 2100 | expect(fakeVmServiceHost.hasRemainingExpectations, false); |
| 2101 | })); |
Alexander Aprelev | 5b1e972 | 2017-05-21 15:15:44 -0700 | [diff] [blame] | 2102 | } |
| 2103 | |
Ben Konyi | 89ef88c | 2020-12-04 17:16:30 -0800 | [diff] [blame] | 2104 | class FakeDartDevelopmentServiceException implements dds.DartDevelopmentServiceException { |
Ben Konyi | 620a828 | 2020-12-22 10:24:04 -0800 | [diff] [blame] | 2105 | FakeDartDevelopmentServiceException({this.message = defaultMessage}); |
| 2106 | |
Ben Konyi | 89ef88c | 2020-12-04 17:16:30 -0800 | [diff] [blame] | 2107 | @override |
| 2108 | final int errorCode = dds.DartDevelopmentServiceException.existingDdsInstanceError; |
| 2109 | |
| 2110 | @override |
Ben Konyi | 620a828 | 2020-12-22 10:24:04 -0800 | [diff] [blame] | 2111 | final String message; |
| 2112 | static const String defaultMessage = 'A DDS instance is already connected at http://localhost:8181'; |
Ben Konyi | 89ef88c | 2020-12-04 17:16:30 -0800 | [diff] [blame] | 2113 | } |
| 2114 | |
Jonah Williams | 6b17840 | 2019-07-15 15:44:58 -0700 | [diff] [blame] | 2115 | class TestFlutterDevice extends FlutterDevice { |
Jonah Williams | 9b7b9d7 | 2020-05-05 12:09:51 -0700 | [diff] [blame] | 2116 | TestFlutterDevice(Device device, { Stream<Uri> observatoryUris }) |
Jonah Williams | c1112d3 | 2020-03-06 14:53:36 -0800 | [diff] [blame] | 2117 | : super(device, buildInfo: BuildInfo.debug) { |
Jenn Magder | 2e7d913 | 2019-11-01 14:37:17 -0700 | [diff] [blame] | 2118 | _observatoryUris = observatoryUris; |
| 2119 | } |
Jonah Williams | 6b17840 | 2019-07-15 15:44:58 -0700 | [diff] [blame] | 2120 | |
| 2121 | @override |
Emmanuel Garcia | 5df4b7d | 2019-11-20 18:51:25 -0800 | [diff] [blame] | 2122 | Stream<Uri> get observatoryUris => _observatoryUris; |
| 2123 | Stream<Uri> _observatoryUris; |
Jonah Williams | 6b17840 | 2019-07-15 15:44:58 -0700 | [diff] [blame] | 2124 | } |
| 2125 | |
Jonah Williams | e22d4aa | 2019-10-15 13:05:47 -0700 | [diff] [blame] | 2126 | class ThrowingForwardingFileSystem extends ForwardingFileSystem { |
| 2127 | ThrowingForwardingFileSystem(FileSystem delegate) : super(delegate); |
| 2128 | |
| 2129 | @override |
| 2130 | File file(dynamic path) { |
| 2131 | if (path == 'foo') { |
| 2132 | throw const FileSystemException(); |
| 2133 | } |
| 2134 | return delegate.file(path); |
| 2135 | } |
| 2136 | } |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 2137 | |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 2138 | class FakeFlutterDevice extends Fake implements FlutterDevice { |
| 2139 | FakeVmServiceHost Function() vmServiceHost; |
| 2140 | Uri testUri; |
| 2141 | UpdateFSReport report = UpdateFSReport( |
| 2142 | success: true, |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 2143 | invalidatedSourcesCount: 1, |
| 2144 | ); |
| 2145 | Object reportError; |
| 2146 | Object runColdError; |
| 2147 | int runHotCode = 0; |
| 2148 | int runColdCode = 0; |
| 2149 | |
| 2150 | @override |
| 2151 | ResidentCompiler generator; |
| 2152 | |
| 2153 | @override |
| 2154 | Stream<Uri> get observatoryUris => Stream<Uri>.value(testUri); |
| 2155 | |
| 2156 | @override |
| 2157 | FlutterVmService get vmService => vmServiceHost?.call()?.vmService; |
| 2158 | |
| 2159 | DevFS _devFS; |
| 2160 | |
| 2161 | @override |
| 2162 | DevFS get devFS => _devFS; |
| 2163 | |
| 2164 | @override |
| 2165 | set devFS(DevFS value) { } |
| 2166 | |
| 2167 | @override |
| 2168 | Device device; |
| 2169 | |
| 2170 | @override |
| 2171 | Future<void> stopEchoingDeviceLog() async { } |
| 2172 | |
| 2173 | @override |
| 2174 | Future<void> initLogReader() async { } |
| 2175 | |
| 2176 | @override |
| 2177 | Future<Uri> setupDevFS(String fsName, Directory rootDirectory) async { |
| 2178 | return testUri; |
| 2179 | } |
| 2180 | |
| 2181 | @override |
| 2182 | Future<int> runHot({HotRunner hotRunner, String route}) async { |
| 2183 | return runHotCode; |
| 2184 | } |
| 2185 | |
| 2186 | @override |
| 2187 | Future<int> runCold({ColdRunner coldRunner, String route}) async { |
| 2188 | if (runColdError != null) { |
| 2189 | throw runColdError; |
| 2190 | } |
| 2191 | return runColdCode; |
| 2192 | } |
| 2193 | |
| 2194 | @override |
| 2195 | Future<void> connect({ |
| 2196 | ReloadSources reloadSources, |
| 2197 | Restart restart, |
| 2198 | CompileExpression compileExpression, |
| 2199 | GetSkSLMethod getSkSLMethod, |
| 2200 | PrintStructuredErrorLogMethod printStructuredErrorLogMethod, |
| 2201 | int hostVmServicePort, |
| 2202 | int ddsPort, |
| 2203 | bool disableServiceAuthCodes = false, |
| 2204 | bool enableDds = true, |
| 2205 | @required bool allowExistingDdsInstance, |
| 2206 | bool ipv6 = false, |
| 2207 | }) async { } |
| 2208 | |
| 2209 | @override |
| 2210 | Future<UpdateFSReport> updateDevFS({ |
| 2211 | Uri mainUri, |
| 2212 | String target, |
| 2213 | AssetBundle bundle, |
| 2214 | DateTime firstBuildTime, |
| 2215 | bool bundleFirstUpload = false, |
| 2216 | bool bundleDirty = false, |
| 2217 | bool fullRestart = false, |
| 2218 | String projectRootPath, |
| 2219 | String pathToReload, |
| 2220 | String dillOutputPath, |
| 2221 | List<Uri> invalidatedFiles, |
| 2222 | PackageConfig packageConfig, |
| 2223 | }) async { |
| 2224 | if (reportError != null) { |
| 2225 | throw reportError; |
| 2226 | } |
| 2227 | return report; |
| 2228 | } |
| 2229 | |
| 2230 | @override |
| 2231 | Future<void> updateReloadStatus(bool wasReloadSuccessful) async { } |
| 2232 | } |
| 2233 | |
| 2234 | class FakeDelegateFlutterDevice extends FlutterDevice { |
| 2235 | FakeDelegateFlutterDevice( |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 2236 | Device device, |
| 2237 | BuildInfo buildInfo, |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 2238 | ResidentCompiler residentCompiler, |
| 2239 | this.fakeDevFS, |
Jonah Williams | a19f5ba | 2020-09-19 11:02:04 -0700 | [diff] [blame] | 2240 | ) : super(device, buildInfo: buildInfo, generator: residentCompiler); |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 2241 | |
| 2242 | @override |
| 2243 | Future<void> connect({ |
| 2244 | ReloadSources reloadSources, |
| 2245 | Restart restart, |
Ian Hickson | e541469 | 2021-04-23 16:29:38 -0700 | [diff] [blame] | 2246 | bool enableDds = true, |
Ben Konyi | a17b330 | 2020-09-16 16:27:42 -0700 | [diff] [blame] | 2247 | bool disableServiceAuthCodes = false, |
Ben Konyi | 3a5a3ea | 2020-07-29 10:05:40 -0700 | [diff] [blame] | 2248 | bool ipv6 = false, |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 2249 | CompileExpression compileExpression, |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 2250 | GetSkSLMethod getSkSLMethod, |
Ben Konyi | a17b330 | 2020-09-16 16:27:42 -0700 | [diff] [blame] | 2251 | int hostVmServicePort, |
| 2252 | int ddsPort, |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 2253 | PrintStructuredErrorLogMethod printStructuredErrorLogMethod, |
Ben Konyi | 89ef88c | 2020-12-04 17:16:30 -0800 | [diff] [blame] | 2254 | bool allowExistingDdsInstance = false, |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 2255 | }) async { } |
| 2256 | |
| 2257 | |
| 2258 | final DevFS fakeDevFS; |
| 2259 | |
| 2260 | @override |
| 2261 | DevFS get devFS => fakeDevFS; |
| 2262 | |
| 2263 | @override |
| 2264 | set devFS(DevFS value) {} |
| 2265 | } |
| 2266 | |
| 2267 | class FakeResidentCompiler extends Fake implements ResidentCompiler { |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 2268 | CompilerOutput nextOutput; |
| 2269 | bool didSuppressErrors = false; |
| 2270 | |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 2271 | @override |
| 2272 | Future<CompilerOutput> recompile( |
| 2273 | Uri mainUri, |
| 2274 | List<Uri> invalidatedFiles, { |
| 2275 | @required String outputPath, |
| 2276 | @required PackageConfig packageConfig, |
Emmanuel Garcia | b0a63c4 | 2021-04-23 15:34:04 -0700 | [diff] [blame] | 2277 | @required String projectRootPath, |
| 2278 | @required FileSystem fs, |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 2279 | bool suppressErrors = false, |
stuartmorgan | 97fb8c0 | 2021-09-30 23:25:13 -0400 | [diff] [blame] | 2280 | bool checkDartPluginRegistry = false, |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 2281 | }) async { |
Jonah Williams | 73df069 | 2021-06-14 16:29:02 -0700 | [diff] [blame] | 2282 | didSuppressErrors = suppressErrors; |
| 2283 | return nextOutput ?? const CompilerOutput('foo.dill', 0, <Uri>[]); |
Jonah Williams | 07caa0f | 2020-07-20 14:03:44 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | @override |
| 2287 | void accept() { } |
| 2288 | |
| 2289 | @override |
| 2290 | void reset() { } |
| 2291 | } |
| 2292 | |
| 2293 | class FakeProjectFileInvalidator extends Fake implements ProjectFileInvalidator { |
| 2294 | @override |
| 2295 | Future<InvalidationResult> findInvalidated({ |
| 2296 | @required DateTime lastCompiled, |
| 2297 | @required List<Uri> urisToMonitor, |
| 2298 | @required String packagesPath, |
| 2299 | @required PackageConfig packageConfig, |
| 2300 | bool asyncScanning = false, |
| 2301 | }) async { |
| 2302 | return InvalidationResult( |
| 2303 | packageConfig: packageConfig ?? PackageConfig.empty, |
| 2304 | uris: <Uri>[Uri.parse('file:///hello_world/main.dart'), |
| 2305 | ]); |
| 2306 | } |
| 2307 | } |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 2308 | |
Ian Hickson | 2bab651 | 2021-10-04 13:48:04 -0700 | [diff] [blame] | 2309 | // Unfortunately Device, despite not being immutable, has an `operator ==`. |
| 2310 | // Until we fix that, we have to also ignore related lints here. |
| 2311 | // ignore: avoid_implementing_value_types |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 2312 | class FakeDevice extends Fake implements Device { |
| 2313 | FakeDevice({ |
| 2314 | String sdkNameAndVersion = 'Android', |
| 2315 | TargetPlatform targetPlatform = TargetPlatform.android_arm, |
| 2316 | bool isLocalEmulator = false, |
| 2317 | this.supportsHotRestart = true, |
Jonah Williams | 6efe8e9 | 2021-01-29 14:27:42 -0800 | [diff] [blame] | 2318 | this.supportsScreenshot = true, |
| 2319 | this.supportsFlutterExit = true, |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 2320 | }) : _isLocalEmulator = isLocalEmulator, |
| 2321 | _targetPlatform = targetPlatform, |
| 2322 | _sdkNameAndVersion = sdkNameAndVersion; |
| 2323 | |
| 2324 | final bool _isLocalEmulator; |
| 2325 | final TargetPlatform _targetPlatform; |
| 2326 | final String _sdkNameAndVersion; |
| 2327 | |
Jonah Williams | 6efe8e9 | 2021-01-29 14:27:42 -0800 | [diff] [blame] | 2328 | bool disposed = false; |
| 2329 | bool appStopped = false; |
| 2330 | bool failScreenshot = false; |
| 2331 | |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 2332 | @override |
Jonah Williams | 6efe8e9 | 2021-01-29 14:27:42 -0800 | [diff] [blame] | 2333 | bool supportsHotRestart; |
| 2334 | |
| 2335 | @override |
| 2336 | bool supportsScreenshot; |
| 2337 | |
| 2338 | @override |
| 2339 | bool supportsFlutterExit; |
| 2340 | |
| 2341 | @override |
| 2342 | PlatformType get platformType => _targetPlatform == TargetPlatform.web_javascript |
| 2343 | ? PlatformType.web |
| 2344 | : PlatformType.android; |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 2345 | |
| 2346 | @override |
| 2347 | Future<String> get sdkNameAndVersion async => _sdkNameAndVersion; |
| 2348 | |
| 2349 | @override |
| 2350 | Future<TargetPlatform> get targetPlatform async => _targetPlatform; |
| 2351 | |
| 2352 | @override |
| 2353 | Future<bool> get isLocalEmulator async => _isLocalEmulator; |
| 2354 | |
| 2355 | @override |
| 2356 | String get name => 'FakeDevice'; |
| 2357 | |
| 2358 | @override |
Jonah Williams | 6efe8e9 | 2021-01-29 14:27:42 -0800 | [diff] [blame] | 2359 | DartDevelopmentService dds; |
| 2360 | |
| 2361 | @override |
| 2362 | Future<void> dispose() async { |
| 2363 | disposed = true; |
| 2364 | } |
| 2365 | |
| 2366 | @override |
| 2367 | Future<bool> stopApp(covariant ApplicationPackage app, {String userIdentifier}) async { |
| 2368 | appStopped = true; |
| 2369 | return true; |
| 2370 | } |
| 2371 | |
| 2372 | @override |
| 2373 | Future<void> takeScreenshot(File outputFile) async { |
| 2374 | if (failScreenshot) { |
| 2375 | throw Exception(); |
| 2376 | } |
| 2377 | outputFile.writeAsBytesSync(List<int>.generate(1024, (int i) => i)); |
| 2378 | } |
| 2379 | |
| 2380 | @override |
| 2381 | FutureOr<DeviceLogReader> getLogReader({ |
| 2382 | covariant ApplicationPackage app, |
| 2383 | bool includePastLogs = false, |
| 2384 | }) => NoOpDeviceLogReader(name); |
| 2385 | |
| 2386 | @override |
| 2387 | DevicePortForwarder portForwarder = const NoOpDevicePortForwarder(); |
Jonah Williams | bdb830a | 2020-10-09 15:44:52 -0700 | [diff] [blame] | 2388 | } |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 2389 | |
| 2390 | class FakeDevFS extends Fake implements DevFS { |
| 2391 | @override |
| 2392 | DateTime lastCompiled = DateTime(2000); |
| 2393 | |
| 2394 | @override |
| 2395 | PackageConfig lastPackageConfig = PackageConfig.empty; |
| 2396 | |
| 2397 | @override |
| 2398 | List<Uri> sources = <Uri>[]; |
| 2399 | |
| 2400 | @override |
| 2401 | Uri baseUri = Uri(); |
| 2402 | |
| 2403 | @override |
| 2404 | Future<void> destroy() async { } |
| 2405 | |
| 2406 | @override |
| 2407 | Set<String> assetPathsToEvict = <String>{}; |
| 2408 | |
| 2409 | UpdateFSReport nextUpdateReport = UpdateFSReport(success: true); |
| 2410 | |
| 2411 | @override |
Lau Ching Jun | af42e7d | 2021-06-28 13:16:04 -0700 | [diff] [blame] | 2412 | bool hasSetAssetDirectory = false; |
| 2413 | |
| 2414 | @override |
Jonah Williams | 8beee47 | 2021-05-24 11:59:03 -0700 | [diff] [blame] | 2415 | Future<Uri> create() async { |
| 2416 | return Uri(); |
| 2417 | } |
| 2418 | |
| 2419 | @override |
| 2420 | void resetLastCompiled() { |
| 2421 | lastCompiled = null; |
| 2422 | } |
| 2423 | |
| 2424 | @override |
| 2425 | Future<UpdateFSReport> update({ |
| 2426 | @required Uri mainUri, |
| 2427 | @required ResidentCompiler generator, |
| 2428 | @required bool trackWidgetCreation, |
| 2429 | @required String pathToReload, |
| 2430 | @required List<Uri> invalidatedFiles, |
| 2431 | @required PackageConfig packageConfig, |
| 2432 | @required String dillOutputPath, |
| 2433 | DevFSWriter devFSWriter, |
| 2434 | String target, |
| 2435 | AssetBundle bundle, |
| 2436 | DateTime firstBuildTime, |
| 2437 | bool bundleFirstUpload = false, |
| 2438 | bool fullRestart = false, |
| 2439 | String projectRootPath, |
| 2440 | }) async { |
| 2441 | return nextUpdateReport; |
| 2442 | } |
| 2443 | } |