Revert "Read dart_plugin_registrant path from FlutterProject to support non-standard path." (#107850)

This commit is contained in:
Christopher Fujino 2022-07-18 12:58:10 -07:00 committed by GitHub
parent b156c0c440
commit 81045d4a44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 212 additions and 376 deletions

View File

@ -328,7 +328,7 @@ class KernelCompiler {
dartPluginRegistrant.path, dartPluginRegistrant.path,
'--source', '--source',
'package:flutter/src/dart_plugin_registrant.dart', 'package:flutter/src/dart_plugin_registrant.dart',
'-Dflutter.dart_plugin_registrant=${toMultiRootPath(dartPluginRegistrant.uri, _fileSystemScheme, _fileSystemRoots, _fileSystem.path.separator == r'\')}', '-Dflutter.dart_plugin_registrant=${dartPluginRegistrant.uri}',
], ],
// See: https://github.com/flutter/flutter/issues/103994 // See: https://github.com/flutter/flutter/issues/103994
'--verbosity=error', '--verbosity=error',
@ -375,7 +375,7 @@ class _RecompileRequest extends _CompilationRequest {
this.outputPath, this.outputPath,
this.packageConfig, this.packageConfig,
this.suppressErrors, this.suppressErrors,
{this.additionalSourceUri} {this.additionalSource}
); );
Uri mainUri; Uri mainUri;
@ -383,7 +383,7 @@ class _RecompileRequest extends _CompilationRequest {
String outputPath; String outputPath;
PackageConfig packageConfig; PackageConfig packageConfig;
bool suppressErrors; bool suppressErrors;
final Uri? additionalSourceUri; final String? additionalSource;
@override @override
Future<CompilerOutput?> _run(DefaultResidentCompiler compiler) async => Future<CompilerOutput?> _run(DefaultResidentCompiler compiler) async =>
@ -499,7 +499,6 @@ abstract class ResidentCompiler {
String? projectRootPath, String? projectRootPath,
bool suppressErrors = false, bool suppressErrors = false,
bool checkDartPluginRegistry = false, bool checkDartPluginRegistry = false,
File? dartPluginRegistrant,
}); });
Future<CompilerOutput?> compileExpression( Future<CompilerOutput?> compileExpression(
@ -643,7 +642,6 @@ class DefaultResidentCompiler implements ResidentCompiler {
required PackageConfig packageConfig, required PackageConfig packageConfig,
bool suppressErrors = false, bool suppressErrors = false,
bool checkDartPluginRegistry = false, bool checkDartPluginRegistry = false,
File? dartPluginRegistrant,
String? projectRootPath, String? projectRootPath,
FileSystem? fs, FileSystem? fs,
}) async { }) async {
@ -651,10 +649,20 @@ class DefaultResidentCompiler implements ResidentCompiler {
if (!_controller.hasListener) { if (!_controller.hasListener) {
_controller.stream.listen(_handleCompilationRequest); _controller.stream.listen(_handleCompilationRequest);
} }
Uri? additionalSourceUri; String? additionalSource;
// `dart_plugin_registrant.dart` contains the Dart plugin registry. // `dart_plugin_registrant.dart` contains the Dart plugin registry.
if (checkDartPluginRegistry && dartPluginRegistrant != null && dartPluginRegistrant.existsSync()) { if (checkDartPluginRegistry && projectRootPath != null && fs != null) {
additionalSourceUri = dartPluginRegistrant.uri; final File dartPluginRegistrantDart = fs.file(
fs.path.join(
projectRootPath,
'.dart_tool',
'flutter_build',
'dart_plugin_registrant.dart',
),
);
if (dartPluginRegistrantDart != null && dartPluginRegistrantDart.existsSync()) {
additionalSource = dartPluginRegistrantDart.path;
}
} }
final Completer<CompilerOutput?> completer = Completer<CompilerOutput?>(); final Completer<CompilerOutput?> completer = Completer<CompilerOutput?>();
_controller.add(_RecompileRequest( _controller.add(_RecompileRequest(
@ -664,7 +672,7 @@ class DefaultResidentCompiler implements ResidentCompiler {
outputPath, outputPath,
packageConfig, packageConfig,
suppressErrors, suppressErrors,
additionalSourceUri: additionalSourceUri, additionalSource: additionalSource,
)); ));
return completer.future; return completer.future;
} }
@ -677,15 +685,9 @@ class DefaultResidentCompiler implements ResidentCompiler {
final String mainUri = request.packageConfig.toPackageUri(request.mainUri)?.toString() ?? final String mainUri = request.packageConfig.toPackageUri(request.mainUri)?.toString() ??
toMultiRootPath(request.mainUri, fileSystemScheme, fileSystemRoots, _platform.isWindows); toMultiRootPath(request.mainUri, fileSystemScheme, fileSystemRoots, _platform.isWindows);
String? additionalSourceUri;
if (request.additionalSourceUri != null) {
additionalSourceUri = request.packageConfig.toPackageUri(request.additionalSourceUri!)?.toString() ??
toMultiRootPath(request.additionalSourceUri!, fileSystemScheme, fileSystemRoots, _platform.isWindows);
}
final Process? server = _server; final Process? server = _server;
if (server == null) { if (server == null) {
return _compile(mainUri, request.outputPath, additionalSourceUri: additionalSourceUri); return _compile(mainUri, request.outputPath, additionalSource: request.additionalSource);
} }
final String inputKey = Uuid().generateV4(); final String inputKey = Uuid().generateV4();
@ -731,7 +733,7 @@ class DefaultResidentCompiler implements ResidentCompiler {
Future<CompilerOutput?> _compile( Future<CompilerOutput?> _compile(
String scriptUri, String scriptUri,
String? outputPath, String? outputPath,
{String? additionalSourceUri} {String? additionalSource}
) async { ) async {
final String frontendServer = _artifacts.getArtifactPath( final String frontendServer = _artifacts.getArtifactPath(
Artifact.frontendServerSnapshotForEngineDartSdk Artifact.frontendServerSnapshotForEngineDartSdk
@ -784,12 +786,12 @@ class DefaultResidentCompiler implements ResidentCompiler {
initializeFromDill!, initializeFromDill!,
], ],
if (assumeInitializeFromDillUpToDate) '--assume-initialize-from-dill-up-to-date', if (assumeInitializeFromDillUpToDate) '--assume-initialize-from-dill-up-to-date',
if (additionalSourceUri != null) ...<String>[ if (additionalSource != null) ...<String>[
'--source', '--source',
additionalSourceUri, additionalSource,
'--source', '--source',
'package:flutter/src/dart_plugin_registrant.dart', 'package:flutter/src/dart_plugin_registrant.dart',
'-Dflutter.dart_plugin_registrant=$additionalSourceUri', '-Dflutter.dart_plugin_registrant=${Uri.file(additionalSource)}',
], ],
if (platformDill != null) ...<String>[ if (platformDill != null) ...<String>[
'--platform', '--platform',

View File

@ -581,7 +581,6 @@ class DevFS {
bool bundleFirstUpload = false, bool bundleFirstUpload = false,
bool fullRestart = false, bool fullRestart = false,
String? projectRootPath, String? projectRootPath,
File? dartPluginRegistrant,
}) async { }) async {
assert(trackWidgetCreation != null); assert(trackWidgetCreation != null);
assert(generator != null); assert(generator != null);
@ -611,7 +610,6 @@ class DevFS {
projectRootPath: projectRootPath, projectRootPath: projectRootPath,
packageConfig: packageConfig, packageConfig: packageConfig,
checkDartPluginRegistry: true, // The entry point is assumed not to have changed. checkDartPluginRegistry: true, // The entry point is assumed not to have changed.
dartPluginRegistrant: dartPluginRegistrant,
).then((CompilerOutput? result) { ).then((CompilerOutput? result) {
compileTimer.stop(); compileTimer.stop();
return result; return result;

View File

@ -799,7 +799,6 @@ class WebDevFS implements DevFS {
bool bundleFirstUpload = false, bool bundleFirstUpload = false,
bool fullRestart = false, bool fullRestart = false,
String? projectRootPath, String? projectRootPath,
File? dartPluginRegistrant,
}) async { }) async {
assert(trackWidgetCreation != null); assert(trackWidgetCreation != null);
assert(generator != null); assert(generator != null);
@ -867,7 +866,6 @@ class WebDevFS implements DevFS {
packageConfig: packageConfig, packageConfig: packageConfig,
projectRootPath: projectRootPath, projectRootPath: projectRootPath,
fs: globals.fs, fs: globals.fs,
dartPluginRegistrant: dartPluginRegistrant,
); );
if (compilerOutput == null || compilerOutput.errorCount > 0) { if (compilerOutput == null || compilerOutput.errorCount > 0) {
return UpdateFSReport(); return UpdateFSReport();

View File

@ -563,7 +563,6 @@ class FlutterDevice {
invalidatedFiles: invalidatedFiles, invalidatedFiles: invalidatedFiles,
packageConfig: packageConfig, packageConfig: packageConfig,
devFSWriter: devFSWriter, devFSWriter: devFSWriter,
dartPluginRegistrant: FlutterProject.current().dartPluginRegistrant,
); );
} on DevFSException { } on DevFSException {
devFSStatus.cancel(); devFSStatus.cancel();

View File

@ -373,7 +373,6 @@ class HotRunner extends ResidentRunner {
// should only be displayed once. // should only be displayed once.
suppressErrors: applicationBinary == null, suppressErrors: applicationBinary == null,
checkDartPluginRegistry: true, checkDartPluginRegistry: true,
dartPluginRegistrant: FlutterProject.current().dartPluginRegistrant,
outputPath: dillOutputPath, outputPath: dillOutputPath,
packageConfig: debuggingOptions.buildInfo.packageConfig, packageConfig: debuggingOptions.buildInfo.packageConfig,
projectRootPath: FlutterProject.current().directory.absolute.path, projectRootPath: FlutterProject.current().directory.absolute.path,

View File

@ -4,7 +4,6 @@
import 'dart:async'; import 'dart:async';
import 'package:file/file.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/async_guard.dart'; import 'package:flutter_tools/src/base/async_guard.dart';
@ -395,43 +394,6 @@ void main() {
'line2\nline3\n' 'line2\nline3\n'
)); ));
}); });
testWithoutContext('incremental compile with dartPluginRegistrant', () async {
fakeProcessManager.addCommand(FakeCommand(
command: const <String>[
...frontendServerCommand,
'--filesystem-root',
'/foo/bar/fizz',
'--filesystem-scheme',
'scheme',
'--source',
'some/dir/plugin_registrant.dart',
'--source',
'package:flutter/src/dart_plugin_registrant.dart',
'-Dflutter.dart_plugin_registrant=some/dir/plugin_registrant.dart',
'--verbosity=error',
],
stdout: 'result abc\nline1\nline2\nabc\nabc /path/to/main.dart.dill 0',
stdin: frontendServerStdIn,
));
final MemoryFileSystem fs = MemoryFileSystem();
final File dartPluginRegistrant = fs.file('some/dir/plugin_registrant.dart')..createSync(recursive: true);
final CompilerOutput? output = await generatorWithScheme.recompile(
Uri.parse('file:///foo/bar/fizz/main.dart'),
null /* invalidatedFiles */,
outputPath: '/build/',
packageConfig: PackageConfig.empty,
fs: fs,
projectRootPath: '',
checkDartPluginRegistry: true,
dartPluginRegistrant: dartPluginRegistrant,
);
expect(frontendServerStdIn.getAndClear(), 'compile scheme:///main.dart\n');
expect(testLogger.errorText, equals('line1\nline2\n'));
expect(output?.outputFilename, equals('/path/to/main.dart.dill'));
expect(fakeProcessManager, hasNoRemainingExpectations);
});
} }
Future<void> _recompile( Future<void> _recompile(

View File

@ -581,7 +581,7 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
Future<CompilerOutput> Function(Uri mainUri, List<Uri>? invalidatedFiles)? onRecompile; Future<CompilerOutput> Function(Uri mainUri, List<Uri>? invalidatedFiles)? onRecompile;
@override @override
Future<CompilerOutput> recompile(Uri mainUri, List<Uri>? invalidatedFiles, {String? outputPath, PackageConfig? packageConfig, String? projectRootPath, FileSystem? fs, bool suppressErrors = false, bool checkDartPluginRegistry = false, File? dartPluginRegistrant}) { Future<CompilerOutput> recompile(Uri mainUri, List<Uri>? invalidatedFiles, {String? outputPath, PackageConfig? packageConfig, String? projectRootPath, FileSystem? fs, bool suppressErrors = false, bool checkDartPluginRegistry = false}) {
return onRecompile?.call(mainUri, invalidatedFiles) return onRecompile?.call(mainUri, invalidatedFiles)
?? Future<CompilerOutput>.value(const CompilerOutput('', 1, <Uri>[])); ?? Future<CompilerOutput>.value(const CompilerOutput('', 1, <Uri>[]));
} }

View File

@ -2464,7 +2464,6 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
@required FileSystem fs, @required FileSystem fs,
bool suppressErrors = false, bool suppressErrors = false,
bool checkDartPluginRegistry = false, bool checkDartPluginRegistry = false,
File dartPluginRegistrant,
}) async { }) async {
didSuppressErrors = suppressErrors; didSuppressErrors = suppressErrors;
return nextOutput ?? const CompilerOutput('foo.dill', 0, <Uri>[]); return nextOutput ?? const CompilerOutput('foo.dill', 0, <Uri>[]);
@ -2624,7 +2623,6 @@ class FakeDevFS extends Fake implements DevFS {
bool bundleFirstUpload = false, bool bundleFirstUpload = false,
bool fullRestart = false, bool fullRestart = false,
String projectRootPath, String projectRootPath,
File dartPluginRegistrant,
}) async { }) async {
return nextUpdateReport; return nextUpdateReport;
} }

View File

@ -42,8 +42,7 @@ import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
import '../src/fake_vm_services.dart'; import '../src/fake_vm_services.dart';
const List<VmServiceExpectation> kAttachLogExpectations = const List<VmServiceExpectation> kAttachLogExpectations = <VmServiceExpectation>[
<VmServiceExpectation>[
FakeVmServiceRequest( FakeVmServiceRequest(
method: 'streamListen', method: 'streamListen',
args: <String, Object>{ args: <String, Object>{
@ -58,23 +57,34 @@ const List<VmServiceExpectation> kAttachLogExpectations =
), ),
]; ];
const List<VmServiceExpectation> kAttachIsolateExpectations = const List<VmServiceExpectation> kAttachIsolateExpectations = <VmServiceExpectation>[
<VmServiceExpectation>[ FakeVmServiceRequest(
FakeVmServiceRequest(method: 'streamListen', args: <String, Object>{ method: 'streamListen',
args: <String, Object>{
'streamId': 'Isolate', 'streamId': 'Isolate',
}), }
FakeVmServiceRequest(method: 'registerService', args: <String, Object>{ ),
FakeVmServiceRequest(
method: 'registerService',
args: <String, Object>{
'service': 'reloadSources', 'service': 'reloadSources',
'alias': 'Flutter Tools', 'alias': 'Flutter Tools',
}), }
FakeVmServiceRequest(method: 'registerService', args: <String, Object>{ ),
FakeVmServiceRequest(
method: 'registerService',
args: <String, Object>{
'service': 'flutterVersion', 'service': 'flutterVersion',
'alias': 'Flutter Tools', 'alias': 'Flutter Tools',
}), }
FakeVmServiceRequest(method: 'registerService', args: <String, Object>{ ),
FakeVmServiceRequest(
method: 'registerService',
args: <String, Object>{
'service': 'flutterMemoryInfo', 'service': 'flutterMemoryInfo',
'alias': 'Flutter Tools', 'alias': 'Flutter Tools',
}), }
),
FakeVmServiceRequest( FakeVmServiceRequest(
method: 'streamListen', method: 'streamListen',
args: <String, Object>{ args: <String, Object>{
@ -138,9 +148,7 @@ void main() {
chromeConnection.tabs.add(chromeTab); chromeConnection.tabs.add(chromeTab);
} }
testUsingContext( testUsingContext('runner with web server device does not support debugging without --start-paused', () {
'runner with web server device does not support debugging without --start-paused',
() {
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice); final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
flutterDevice.device = WebServerDevice( flutterDevice.device = WebServerDevice(
logger: BufferLogger.test(), logger: BufferLogger.test(),
@ -148,8 +156,7 @@ void main() {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
final ResidentRunner profileResidentWebRunner = ResidentWebRunner( final ResidentRunner profileResidentWebRunner = ResidentWebRunner(
flutterDevice, flutterDevice,
flutterProject: flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
ipv6: true, ipv6: true,
fileSystem: fileSystem, fileSystem: fileSystem,
@ -169,9 +176,7 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext( testUsingContext('runner with web server device supports debugging with --start-paused', () {
'runner with web server device supports debugging with --start-paused',
() {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
setupMocks(); setupMocks();
flutterDevice.device = WebServerDevice( flutterDevice.device = WebServerDevice(
@ -179,10 +184,8 @@ void main() {
); );
final ResidentRunner profileResidentWebRunner = ResidentWebRunner( final ResidentRunner profileResidentWebRunner = ResidentWebRunner(
flutterDevice, flutterDevice,
flutterProject: flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, startPaused: true),
debuggingOptions:
DebuggingOptions.enabled(BuildInfo.debug, startPaused: true),
ipv6: true, ipv6: true,
fileSystem: fileSystem, fileSystem: fileSystem,
logger: BufferLogger.test(), logger: BufferLogger.test(),
@ -199,8 +202,7 @@ void main() {
testUsingContext('profile does not supportsServiceProtocol', () { testUsingContext('profile does not supportsServiceProtocol', () {
final ResidentRunner residentWebRunner = ResidentWebRunner( final ResidentRunner residentWebRunner = ResidentWebRunner(
flutterDevice, flutterDevice,
flutterProject: flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
ipv6: true, ipv6: true,
fileSystem: fileSystem, fileSystem: fileSystem,
@ -212,8 +214,7 @@ void main() {
flutterDevice.device = chromeDevice; flutterDevice.device = chromeDevice;
final ResidentRunner profileResidentWebRunner = ResidentWebRunner( final ResidentRunner profileResidentWebRunner = ResidentWebRunner(
flutterDevice, flutterDevice,
flutterProject: flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile), debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile),
ipv6: true, ipv6: true,
fileSystem: fileSystem, fileSystem: fileSystem,
@ -231,98 +232,69 @@ void main() {
testUsingContext('Can successfully run and connect to vmservice', () async { testUsingContext('Can successfully run and connect to vmservice', () async {
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ResidentRunner residentWebRunner = final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice, logger: logger);
setUpResidentRunner(flutterDevice, logger: logger); fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList());
fakeVmServiceHost =
FakeVmServiceHost(requests: kAttachExpectations.toList());
setupMocks(); setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
final DebugConnectionInfo debugConnectionInfo = final DebugConnectionInfo debugConnectionInfo = await connectionInfoCompleter.future;
await connectionInfoCompleter.future;
expect(appConnection.ranMain, true); expect(appConnection.ranMain, true);
expect(logger.statusText, expect(logger.statusText, contains('Debug service listening on ws://127.0.0.1/abcd/'));
contains('Debug service listening on ws://127.0.0.1/abcd/'));
expect(debugConnectionInfo.wsUri.toString(), 'ws://127.0.0.1/abcd/'); expect(debugConnectionInfo.wsUri.toString(), 'ws://127.0.0.1/abcd/');
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext('WebRunner copies compiled app.dill to cache during startup', testUsingContext('WebRunner copies compiled app.dill to cache during startup', () async {
() async {
final DebuggingOptions debuggingOptions = DebuggingOptions.enabled( final DebuggingOptions debuggingOptions = DebuggingOptions.enabled(
const BuildInfo(BuildMode.debug, null, treeShakeIcons: false), const BuildInfo(BuildMode.debug, null, treeShakeIcons: false),
); );
final ResidentRunner residentWebRunner = final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice, debuggingOptions: debuggingOptions);
setUpResidentRunner(flutterDevice, debuggingOptions: debuggingOptions); fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList());
fakeVmServiceHost =
FakeVmServiceHost(requests: kAttachExpectations.toList());
setupMocks(); setupMocks();
residentWebRunner.artifactDirectory residentWebRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
.childFile('app.dill') final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
.writeAsStringSync('ABC');
final Completer<DebugConnectionInfo> connectionInfoCompleter =
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
await connectionInfoCompleter.future; await connectionInfoCompleter.future;
expect( expect(await fileSystem.file(fileSystem.path.join('build', 'cache.dill')).readAsString(), 'ABC');
await fileSystem
.file(fileSystem.path.join('build', 'cache.dill'))
.readAsString(),
'ABC');
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext( testUsingContext('WebRunner copies compiled app.dill to cache during startup with track-widget-creation', () async {
'WebRunner copies compiled app.dill to cache during startup with track-widget-creation',
() async {
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice); final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
fakeVmServiceHost = fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList());
FakeVmServiceHost(requests: kAttachExpectations.toList());
setupMocks(); setupMocks();
residentWebRunner.artifactDirectory residentWebRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC');
.childFile('app.dill') final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
.writeAsStringSync('ABC');
final Completer<DebugConnectionInfo> connectionInfoCompleter =
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
await connectionInfoCompleter.future; await connectionInfoCompleter.future;
expect( expect(await fileSystem.file(fileSystem.path.join('build', 'cache.dill.track.dill')).readAsString(), 'ABC');
await fileSystem
.file(fileSystem.path.join('build', 'cache.dill.track.dill'))
.readAsString(),
'ABC');
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
// Regression test for https://github.com/flutter/flutter/issues/60613 // Regression test for https://github.com/flutter/flutter/issues/60613
testUsingContext( testUsingContext('ResidentWebRunner calls appFailedToStart if initial compilation fails', () async {
'ResidentWebRunner calls appFailedToStart if initial compilation fails', fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList());
() async {
fakeVmServiceHost =
FakeVmServiceHost(requests: kAttachExpectations.toList());
setupMocks(); setupMocks();
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice); final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
fileSystem fileSystem.file(globals.fs.path.join('lib', 'main.dart'))
.file(globals.fs.path.join('lib', 'main.dart'))
.createSync(recursive: true); .createSync(recursive: true);
webDevFS.report = UpdateFSReport(); webDevFS.report = UpdateFSReport();
@ -334,18 +306,15 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext( testUsingContext('Can successfully run without an index.html including status warning', () async {
'Can successfully run without an index.html including status warning',
() async {
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
fakeVmServiceHost = fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList());
FakeVmServiceHost(requests: kAttachExpectations.toList());
setupMocks(); setupMocks();
fileSystem.file(fileSystem.path.join('web', 'index.html')).deleteSync(); fileSystem.file(fileSystem.path.join('web', 'index.html'))
.deleteSync();
final ResidentWebRunner residentWebRunner = ResidentWebRunner( final ResidentWebRunner residentWebRunner = ResidentWebRunner(
flutterDevice, flutterDevice,
flutterProject: flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
ipv6: true, ipv6: true,
stayResident: false, stayResident: false,
@ -363,15 +332,12 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext('Can successfully run and disconnect with --no-resident', testUsingContext('Can successfully run and disconnect with --no-resident', () async {
() async { fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList());
fakeVmServiceHost =
FakeVmServiceHost(requests: kAttachExpectations.toList());
setupMocks(); setupMocks();
final ResidentRunner residentWebRunner = ResidentWebRunner( final ResidentRunner residentWebRunner = ResidentWebRunner(
flutterDevice, flutterDevice,
flutterProject: flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
ipv6: true, ipv6: true,
stayResident: false, stayResident: false,
@ -387,11 +353,9 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext('Listens to stdout and stderr streams before running main', testUsingContext('Listens to stdout and stderr streams before running main', () async {
() async {
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ResidentRunner residentWebRunner = final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice, logger: logger);
setUpResidentRunner(flutterDevice, logger: logger);
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
...kAttachLogExpectations, ...kAttachLogExpectations,
FakeVmServiceStreamResponse( FakeVmServiceStreamResponse(
@ -399,20 +363,21 @@ void main() {
event: vm_service.Event( event: vm_service.Event(
timestamp: 0, timestamp: 0,
kind: vm_service.EventStreams.kStdout, kind: vm_service.EventStreams.kStdout,
bytes: base64.encode(utf8.encode('THIS MESSAGE IS IMPORTANT'))), bytes: base64.encode(utf8.encode('THIS MESSAGE IS IMPORTANT'))
),
), ),
FakeVmServiceStreamResponse( FakeVmServiceStreamResponse(
streamId: 'Stderr', streamId: 'Stderr',
event: vm_service.Event( event: vm_service.Event(
timestamp: 0, timestamp: 0,
kind: vm_service.EventStreams.kStderr, kind: vm_service.EventStreams.kStderr,
bytes: base64.encode(utf8.encode('SO IS THIS'))), bytes: base64.encode(utf8.encode('SO IS THIS'))
),
), ),
...kAttachIsolateExpectations, ...kAttachIsolateExpectations,
]); ]);
setupMocks(); setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
@ -425,10 +390,8 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext('Listens to extension events with structured errors', testUsingContext('Listens to extension events with structured errors', () async {
() async { final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice, logger: testLogger);
final ResidentRunner residentWebRunner =
setUpResidentRunner(flutterDevice, logger: testLogger);
final Map<String, String> extensionData = <String, String>{ final Map<String, String> extensionData = <String, String>{
'test': 'data', 'test': 'data',
'renderedErrorText': 'error text', 'renderedErrorText': 'error text',
@ -474,8 +437,7 @@ void main() {
]); ]);
setupMocks(); setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
@ -492,21 +454,17 @@ void main() {
testUsingContext('Does not run main with --start-paused', () async { testUsingContext('Does not run main with --start-paused', () async {
final ResidentRunner residentWebRunner = ResidentWebRunner( final ResidentRunner residentWebRunner = ResidentWebRunner(
flutterDevice, flutterDevice,
flutterProject: flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug, startPaused: true),
debuggingOptions:
DebuggingOptions.enabled(BuildInfo.debug, startPaused: true),
ipv6: true, ipv6: true,
fileSystem: fileSystem, fileSystem: fileSystem,
logger: BufferLogger.test(), logger: BufferLogger.test(),
usage: globals.flutterUsage, usage: globals.flutterUsage,
systemClock: globals.systemClock, systemClock: globals.systemClock,
); );
fakeVmServiceHost = fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList());
FakeVmServiceHost(requests: kAttachExpectations.toList());
setupMocks(); setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
@ -532,7 +490,8 @@ void main() {
method: 'hotRestart', method: 'hotRestart',
jsonResponse: <String, Object>{ jsonResponse: <String, Object>{
'type': 'Success', 'type': 'Success',
}), }
),
const FakeVmServiceRequest( const FakeVmServiceRequest(
method: 'streamListen', method: 'streamListen',
args: <String, Object>{ args: <String, Object>{
@ -542,8 +501,7 @@ void main() {
]); ]);
setupMocks(); setupMocks();
final TestChromiumLauncher chromiumLauncher = TestChromiumLauncher(); final TestChromiumLauncher chromiumLauncher = TestChromiumLauncher();
final Chromium chrome = final Chromium chrome = Chromium(1, chromeConnection, chromiumLauncher: chromiumLauncher);
Chromium(1, chromeConnection, chromiumLauncher: chromiumLauncher);
chromiumLauncher.setInstance(chrome); chromiumLauncher.setInstance(chrome);
flutterDevice.device = GoogleChromeDevice( flutterDevice.device = GoogleChromeDevice(
@ -555,13 +513,11 @@ void main() {
); );
webDevFS.report = UpdateFSReport(success: true); webDevFS.report = UpdateFSReport(success: true);
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
final DebugConnectionInfo debugConnectionInfo = final DebugConnectionInfo debugConnectionInfo = await connectionInfoCompleter.future;
await connectionInfoCompleter.future;
expect(debugConnectionInfo, isNotNull); expect(debugConnectionInfo, isNotNull);
@ -573,15 +529,7 @@ void main() {
// ensure that analytics are sent. // ensure that analytics are sent.
expect(testUsage.events, <TestUsageEvent>[ expect(testUsage.events, <TestUsageEvent>[
TestUsageEvent('hot', 'restart', TestUsageEvent('hot', 'restart', parameters: CustomDimensions.fromMap(<String, String>{'cd27': 'web-javascript', 'cd28': '', 'cd29': 'false', 'cd30': 'true', 'cd13': '0', 'cd48': 'false'})),
parameters: CustomDimensions.fromMap(<String, String>{
'cd27': 'web-javascript',
'cd28': '',
'cd29': 'false',
'cd30': 'true',
'cd13': '0',
'cd48': 'false'
})),
]); ]);
expect(testUsage.timings, const <TestTimingEvent>[ expect(testUsage.timings, const <TestTimingEvent>[
TestTimingEvent('hot', 'web-incremental-restart', Duration.zero), TestTimingEvent('hot', 'web-incremental-restart', Duration.zero),
@ -605,12 +553,12 @@ void main() {
method: 'hotRestart', method: 'hotRestart',
jsonResponse: <String, Object>{ jsonResponse: <String, Object>{
'type': 'Success', 'type': 'Success',
}), }
),
]); ]);
setupMocks(); setupMocks();
final TestChromiumLauncher chromiumLauncher = TestChromiumLauncher(); final TestChromiumLauncher chromiumLauncher = TestChromiumLauncher();
final Chromium chrome = final Chromium chrome = Chromium(1, chromeConnection, chromiumLauncher: chromiumLauncher);
Chromium(1, chromeConnection, chromiumLauncher: chromiumLauncher);
chromiumLauncher.setInstance(chrome); chromiumLauncher.setInstance(chrome);
flutterDevice.device = GoogleChromeDevice( flutterDevice.device = GoogleChromeDevice(
@ -622,19 +570,16 @@ void main() {
); );
webDevFS.report = UpdateFSReport(success: true); webDevFS.report = UpdateFSReport(success: true);
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
await connectionInfoCompleter.future; await connectionInfoCompleter.future;
final OperationResult result = final OperationResult result = await residentWebRunner.restart(fullRestart: true);
await residentWebRunner.restart(fullRestart: true);
// Ensure that generated entrypoint is generated correctly. // Ensure that generated entrypoint is generated correctly.
expect(webDevFS.mainUri, isNotNull); expect(webDevFS.mainUri, isNotNull);
final String entrypointContents = final String entrypointContents = fileSystem.file(webDevFS.mainUri).readAsStringSync();
fileSystem.file(webDevFS.mainUri).readAsStringSync();
expect(entrypointContents, contains('// Flutter web bootstrap script')); expect(entrypointContents, contains('// Flutter web bootstrap script'));
expect(entrypointContents, contains("import 'dart:ui' as ui;")); expect(entrypointContents, contains("import 'dart:ui' as ui;"));
expect(entrypointContents, contains('await ui.webOnlyWarmupEngine(')); expect(entrypointContents, contains('await ui.webOnlyWarmupEngine('));
@ -644,15 +589,7 @@ void main() {
// ensure that analytics are sent. // ensure that analytics are sent.
expect(testUsage.events, <TestUsageEvent>[ expect(testUsage.events, <TestUsageEvent>[
TestUsageEvent('hot', 'restart', TestUsageEvent('hot', 'restart', parameters: CustomDimensions.fromMap(<String, String>{'cd27': 'web-javascript', 'cd28': '', 'cd29': 'false', 'cd30': 'true', 'cd13': '0', 'cd48': 'false'})),
parameters: CustomDimensions.fromMap(<String, String>{
'cd27': 'web-javascript',
'cd28': '',
'cd29': 'false',
'cd30': 'true',
'cd13': '0',
'cd48': 'false'
})),
]); ]);
expect(testUsage.timings, const <TestTimingEvent>[ expect(testUsage.timings, const <TestTimingEvent>[
TestTimingEvent('hot', 'web-incremental-restart', Duration.zero), TestTimingEvent('hot', 'web-incremental-restart', Duration.zero),
@ -663,8 +600,7 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext('Can hot restart after attaching with web-server device', testUsingContext('Can hot restart after attaching with web-server device', () async {
() async {
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ResidentRunner residentWebRunner = setUpResidentRunner( final ResidentRunner residentWebRunner = setUpResidentRunner(
flutterDevice, flutterDevice,
@ -676,14 +612,12 @@ void main() {
flutterDevice.device = webServerDevice; flutterDevice.device = webServerDevice;
webDevFS.report = UpdateFSReport(success: true); webDevFS.report = UpdateFSReport(success: true);
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
await connectionInfoCompleter.future; await connectionInfoCompleter.future;
final OperationResult result = final OperationResult result = await residentWebRunner.restart(fullRestart: true);
await residentWebRunner.restart(fullRestart: true);
expect(logger.statusText, contains('Restarted application in')); expect(logger.statusText, contains('Restarted application in'));
expect(result.code, 0); expect(result.code, 0);
@ -699,8 +633,7 @@ void main() {
testUsingContext('web resident runner is debuggable', () { testUsingContext('web resident runner is debuggable', () {
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice); final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
fakeVmServiceHost = fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList());
FakeVmServiceHost(requests: kAttachExpectations.toList());
expect(residentWebRunner.debuggingEnabled, true); expect(residentWebRunner.debuggingEnabled, true);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
@ -714,8 +647,7 @@ void main() {
setupMocks(); setupMocks();
webDevFS.report = UpdateFSReport(); webDevFS.report = UpdateFSReport();
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
@ -729,12 +661,9 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext( testUsingContext('Faithfully displays stdout messages with leading/trailing spaces', () async {
'Faithfully displays stdout messages with leading/trailing spaces',
() async {
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ResidentRunner residentWebRunner = final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice, logger: logger);
setUpResidentRunner(flutterDevice, logger: logger);
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
...kAttachLogExpectations, ...kAttachLogExpectations,
FakeVmServiceStreamResponse( FakeVmServiceStreamResponse(
@ -743,25 +672,21 @@ void main() {
timestamp: 0, timestamp: 0,
kind: vm_service.EventStreams.kStdout, kind: vm_service.EventStreams.kStdout,
bytes: base64.encode( bytes: base64.encode(
utf8.encode( utf8.encode(' This is a message with 4 leading and trailing spaces '),
' This is a message with 4 leading and trailing spaces '),
), ),
), ),
), ),
...kAttachIsolateExpectations, ...kAttachIsolateExpectations,
]); ]);
setupMocks(); setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
await connectionInfoCompleter.future; await connectionInfoCompleter.future;
expect( expect(logger.statusText,
logger.statusText, contains(' This is a message with 4 leading and trailing spaces '));
contains(
' This is a message with 4 leading and trailing spaces '));
expect(fakeVmServiceHost.hasRemainingExpectations, false); expect(fakeVmServiceHost.hasRemainingExpectations, false);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
@ -770,19 +695,16 @@ void main() {
testUsingContext('Fails on compilation errors in hot restart', () async { testUsingContext('Fails on compilation errors in hot restart', () async {
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice); final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
fakeVmServiceHost = fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList());
FakeVmServiceHost(requests: kAttachExpectations.toList());
setupMocks(); setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
await connectionInfoCompleter.future; await connectionInfoCompleter.future;
webDevFS.report = UpdateFSReport(); webDevFS.report = UpdateFSReport();
final OperationResult result = final OperationResult result = await residentWebRunner.restart(fullRestart: true);
await residentWebRunner.restart(fullRestart: true);
expect(result.code, 1); expect(result.code, 1);
expect(result.message, contains('Failed to recompile application.')); expect(result.message, contains('Failed to recompile application.'));
@ -794,9 +716,7 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext( testUsingContext('Fails non-fatally on vmservice response error for hot restart', () async {
'Fails non-fatally on vmservice response error for hot restart',
() async {
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice); final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
...kAttachExpectations, ...kAttachExpectations,
@ -808,8 +728,7 @@ void main() {
), ),
]); ]);
setupMocks(); setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
@ -834,8 +753,7 @@ void main() {
), ),
]); ]);
setupMocks(); setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
@ -843,17 +761,16 @@ void main() {
final OperationResult result = await residentWebRunner.restart(); final OperationResult result = await residentWebRunner.restart();
expect(result.code, 1); expect(result.code, 1);
expect(result.message, contains(RPCErrorCodes.kInternalError.toString())); expect(result.message,
contains(RPCErrorCodes.kInternalError.toString()));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => fileSystem, FileSystem: () => fileSystem,
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext('printHelp without details shows hot restart help message', testUsingContext('printHelp without details shows hot restart help message', () async {
() async {
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ResidentRunner residentWebRunner = final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice, logger: logger);
setUpResidentRunner(flutterDevice, logger: logger);
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
residentWebRunner.printHelp(details: false); residentWebRunner.printHelp(details: false);
@ -863,16 +780,14 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext('cleanup of resources is safe to call multiple times', testUsingContext('cleanup of resources is safe to call multiple times', () async {
() async {
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice); final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
mockDevice.dds = DartDevelopmentService(); mockDevice.dds = DartDevelopmentService();
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
...kAttachExpectations, ...kAttachExpectations,
]); ]);
setupMocks(); setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
@ -894,8 +809,7 @@ void main() {
...kAttachExpectations, ...kAttachExpectations,
]); ]);
setupMocks(); setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
final Future<int> result = residentWebRunner.run( final Future<int> result = residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
); );
@ -911,23 +825,19 @@ void main() {
testUsingContext('Prints target and device name on run', () async { testUsingContext('Prints target and device name on run', () async {
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ResidentRunner residentWebRunner = final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice, logger: logger);
setUpResidentRunner(flutterDevice, logger: logger);
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
...kAttachExpectations, ...kAttachExpectations,
]); ]);
setupMocks(); setupMocks();
mockDevice.name = 'Chromez'; mockDevice.name = 'Chromez';
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run( unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
await connectionInfoCompleter.future; await connectionInfoCompleter.future;
expect( expect(logger.statusText, contains(
logger.statusText,
contains(
'Launching ${fileSystem.path.join('lib', 'main.dart')} on ' 'Launching ${fileSystem.path.join('lib', 'main.dart')} on '
'Chromez in debug mode', 'Chromez in debug mode',
)); ));
@ -937,8 +847,7 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext('Sends launched app.webLaunchUrl event for Chrome device', testUsingContext('Sends launched app.webLaunchUrl event for Chrome device', () async {
() async {
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[ fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
...kAttachLogExpectations, ...kAttachLogExpectations,
@ -947,8 +856,7 @@ void main() {
setupMocks(); setupMocks();
final FakeChromeConnection chromeConnection = FakeChromeConnection(); final FakeChromeConnection chromeConnection = FakeChromeConnection();
final TestChromiumLauncher chromiumLauncher = TestChromiumLauncher(); final TestChromiumLauncher chromiumLauncher = TestChromiumLauncher();
final Chromium chrome = final Chromium chrome = Chromium(1, chromeConnection, chromiumLauncher: chromiumLauncher);
Chromium(1, chromeConnection, chromiumLauncher: chromiumLauncher);
chromiumLauncher.setInstance(chrome); chromiumLauncher.setInstance(chrome);
flutterDevice.device = GoogleChromeDevice( flutterDevice.device = GoogleChromeDevice(
@ -965,8 +873,7 @@ void main() {
final ResidentWebRunner runner = ResidentWebRunner( final ResidentWebRunner runner = ResidentWebRunner(
flutterDevice, flutterDevice,
flutterProject: flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
ipv6: true, ipv6: true,
fileSystem: fileSystem, fileSystem: fileSystem,
@ -975,18 +882,15 @@ void main() {
systemClock: globals.systemClock, systemClock: globals.systemClock,
); );
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(runner.run( unawaited(runner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
await connectionInfoCompleter.future; await connectionInfoCompleter.future;
// Ensure we got the URL and that it was already launched. // Ensure we got the URL and that it was already launched.
expect( expect(logger.eventText,
logger.eventText, contains(json.encode(<String, Object>{
contains(json.encode(
<String, Object>{
'name': 'app.webLaunchUrl', 'name': 'app.webLaunchUrl',
'args': <String, Object>{ 'args': <String, Object>{
'url': 'http://localhost:8765/app/', 'url': 'http://localhost:8765/app/',
@ -1000,9 +904,7 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext( testUsingContext('Sends unlaunched app.webLaunchUrl event for Web Server device', () async {
'Sends unlaunched app.webLaunchUrl event for Web Server device',
() async {
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
setupMocks(); setupMocks();
@ -1013,8 +915,7 @@ void main() {
final ResidentWebRunner runner = ResidentWebRunner( final ResidentWebRunner runner = ResidentWebRunner(
flutterDevice, flutterDevice,
flutterProject: flutterProject: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
ipv6: true, ipv6: true,
fileSystem: fileSystem, fileSystem: fileSystem,
@ -1023,18 +924,15 @@ void main() {
systemClock: globals.systemClock, systemClock: globals.systemClock,
); );
final Completer<DebugConnectionInfo> connectionInfoCompleter = final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
Completer<DebugConnectionInfo>();
unawaited(runner.run( unawaited(runner.run(
connectionInfoCompleter: connectionInfoCompleter, connectionInfoCompleter: connectionInfoCompleter,
)); ));
await connectionInfoCompleter.future; await connectionInfoCompleter.future;
// Ensure we got the URL and that it was not already launched. // Ensure we got the URL and that it was not already launched.
expect( expect(logger.eventText,
logger.eventText, contains(json.encode(<String, Object>{
contains(json.encode(
<String, Object>{
'name': 'app.webLaunchUrl', 'name': 'app.webLaunchUrl',
'args': <String, Object>{ 'args': <String, Object>{
'url': 'http://localhost:8765/app/', 'url': 'http://localhost:8765/app/',
@ -1052,8 +950,8 @@ void main() {
// perf regression in hot restart. // perf regression in hot restart.
testUsingContext('Does not generate dart_plugin_registrant.dart', () async { testUsingContext('Does not generate dart_plugin_registrant.dart', () async {
// Create necessary files for [DartPluginRegistrantTarget] // Create necessary files for [DartPluginRegistrantTarget]
final File packageConfig = final File packageConfig = globals.fs.directory('.dart_tool')
globals.fs.directory('.dart_tool').childFile('package_config.json'); .childFile('package_config.json');
packageConfig.createSync(recursive: true); packageConfig.createSync(recursive: true);
packageConfig.writeAsStringSync(''' packageConfig.writeAsStringSync('''
{ {
@ -1069,14 +967,12 @@ void main() {
} }
'''); ''');
// Start with a dart_plugin_registrant.dart file. // Start with a dart_plugin_registrant.dart file.
globals.fs globals.fs.directory('.dart_tool')
.directory('.dart_tool')
.childDirectory('flutter_build') .childDirectory('flutter_build')
.childFile('dart_plugin_registrant.dart') .childFile('dart_plugin_registrant.dart')
.createSync(recursive: true); .createSync(recursive: true);
final FlutterProject project = final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice); final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
await residentWebRunner.runSourceGenerators(); await residentWebRunner.runSourceGenerators();
@ -1091,11 +987,9 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext('Successfully turns WebSocketException into ToolExit', testUsingContext('Successfully turns WebSocketException into ToolExit', () async {
() async {
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ResidentRunner residentWebRunner = final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice, logger: logger);
setUpResidentRunner(flutterDevice, logger: logger);
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
setupMocks(); setupMocks();
webDevFS.exception = const WebSocketException(); webDevFS.exception = const WebSocketException();
@ -1108,8 +1002,7 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext('Successfully turns AppConnectionException into ToolExit', testUsingContext('Successfully turns AppConnectionException into ToolExit', () async {
() async {
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice); final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
setupMocks(); setupMocks();
@ -1122,8 +1015,7 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
testUsingContext('Successfully turns ChromeDebugError into ToolExit', testUsingContext('Successfully turns ChromeDebugError into ToolExit', () async {
() async {
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice); final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
setupMocks(); setupMocks();
@ -1152,8 +1044,7 @@ void main() {
testUsingContext('Rethrows unknown Error type from dwds tooling', () async { testUsingContext('Rethrows unknown Error type from dwds tooling', () async {
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ResidentRunner residentWebRunner = final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice, logger: logger);
setUpResidentRunner(flutterDevice, logger: logger);
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]); fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
setupMocks(); setupMocks();
webDevFS.exception = StateError(''); webDevFS.exception = StateError('');
@ -1166,18 +1057,15 @@ void main() {
}); });
} }
ResidentRunner setUpResidentRunner( ResidentRunner setUpResidentRunner(FlutterDevice flutterDevice, {
FlutterDevice flutterDevice, {
Logger logger, Logger logger,
SystemClock systemClock, SystemClock systemClock,
DebuggingOptions debuggingOptions, DebuggingOptions debuggingOptions,
}) { }) {
return ResidentWebRunner( return ResidentWebRunner(
flutterDevice, flutterDevice,
flutterProject: flutterProject: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory),
FlutterProject.fromDirectoryTest(globals.fs.currentDirectory), debuggingOptions: debuggingOptions ?? DebuggingOptions.enabled(BuildInfo.debug),
debuggingOptions:
debuggingOptions ?? DebuggingOptions.enabled(BuildInfo.debug),
ipv6: true, ipv6: true,
usage: globals.flutterUsage, usage: globals.flutterUsage,
systemClock: systemClock ?? SystemClock.fixed(DateTime.now()), systemClock: systemClock ?? SystemClock.fixed(DateTime.now()),
@ -1238,8 +1126,7 @@ class FakeDebugConnection extends Fake implements DebugConnection {
FakeVmServiceHost Function() fakeVmServiceHost; FakeVmServiceHost Function() fakeVmServiceHost;
@override @override
vm_service.VmService get vmService => vm_service.VmService get vmService => fakeVmServiceHost.call().vmService.service;
fakeVmServiceHost.call().vmService.service;
@override @override
String uri; String uri;
@ -1283,7 +1170,6 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
@required FileSystem fs, @required FileSystem fs,
bool suppressErrors = false, bool suppressErrors = false,
bool checkDartPluginRegistry = false, bool checkDartPluginRegistry = false,
File dartPluginRegistrant,
}) async { }) async {
return const CompilerOutput('foo.dill', 0, <Uri>[]); return const CompilerOutput('foo.dill', 0, <Uri>[]);
} }
@ -1343,7 +1229,6 @@ class FakeWebDevFS extends Fake implements WebDevFS {
bool bundleFirstUpload = false, bool bundleFirstUpload = false,
bool fullRestart = false, bool fullRestart = false,
String projectRootPath, String projectRootPath,
File dartPluginRegistrant,
}) async { }) async {
this.mainUri = mainUri; this.mainUri = mainUri;
return report; return report;
@ -1364,8 +1249,7 @@ class FakeChromeConnection extends Fake implements ChromeConnection {
final List<ChromeTab> tabs = <ChromeTab>[]; final List<ChromeTab> tabs = <ChromeTab>[];
@override @override
Future<ChromeTab> getTab(bool Function(ChromeTab tab) accept, Future<ChromeTab> getTab(bool Function(ChromeTab tab) accept, {Duration retryFor}) async {
{Duration retryFor}) async {
return tabs.firstWhere(accept); return tabs.firstWhere(accept);
} }
@ -1480,8 +1364,7 @@ class FakeFlutterDevice extends Fake implements FlutterDevice {
} }
@override @override
Future<void> exitApps( Future<void> exitApps({Duration timeoutDelay = const Duration(seconds: 10)}) async { }
{Duration timeoutDelay = const Duration(seconds: 10)}) async {}
@override @override
Future<void> connect({ Future<void> connect({
@ -1513,7 +1396,6 @@ class FakeFlutterDevice extends Fake implements FlutterDevice {
String dillOutputPath, String dillOutputPath,
List<Uri> invalidatedFiles, List<Uri> invalidatedFiles,
PackageConfig packageConfig, PackageConfig packageConfig,
File dartPluginRegistrant,
}) async { }) async {
if (reportError != null) { if (reportError != null) {
throw reportError; throw reportError;

View File

@ -200,7 +200,6 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
FileSystem? fs, FileSystem? fs,
bool suppressErrors = false, bool suppressErrors = false,
bool checkDartPluginRegistry = false, bool checkDartPluginRegistry = false,
File? dartPluginRegistrant,
}) async { }) async {
if (compilerOutput != null) { if (compilerOutput != null) {
fileSystem!.file(compilerOutput!.outputFilename).createSync(recursive: true); fileSystem!.file(compilerOutput!.outputFilename).createSync(recursive: true);

View File

@ -1120,7 +1120,6 @@ class FakeResidentCompiler extends Fake implements ResidentCompiler {
FileSystem fs, FileSystem fs,
bool suppressErrors = false, bool suppressErrors = false,
bool checkDartPluginRegistry = false, bool checkDartPluginRegistry = false,
File dartPluginRegistrant,
}) async { }) async {
return output; return output;
} }