Unverified Commit 59ca523b authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Support web-server/profile/release mode with incremental compiler support for web (#45713)

parent 598f2ab0
...@@ -48,7 +48,7 @@ class DwdsWebRunnerFactory extends WebRunnerFactory { ...@@ -48,7 +48,7 @@ class DwdsWebRunnerFactory extends WebRunnerFactory {
@required DebuggingOptions debuggingOptions, @required DebuggingOptions debuggingOptions,
@required List<String> dartDefines, @required List<String> dartDefines,
}) { }) {
if (featureFlags.isWebIncrementalCompilerEnabled) { if (featureFlags.isWebIncrementalCompilerEnabled && debuggingOptions.buildInfo.isDebug) {
return _ExperimentalResidentWebRunner( return _ExperimentalResidentWebRunner(
device, device,
target: target, target: target,
...@@ -448,10 +448,10 @@ class _ExperimentalResidentWebRunner extends ResidentWebRunner { ...@@ -448,10 +448,10 @@ class _ExperimentalResidentWebRunner extends ResidentWebRunner {
try { try {
if (fullRestart) { if (fullRestart) {
await _wipConnection.sendCommand('Page.reload'); await _wipConnection?.sendCommand('Page.reload');
} else { } else {
await _wipConnection.debugger await _wipConnection?.debugger
.sendCommand('Runtime.evaluate', params: <String, Object>{ ?.sendCommand('Runtime.evaluate', params: <String, Object>{
'expression': 'window.\$hotReloadHook([$modules])', 'expression': 'window.\$hotReloadHook([$modules])',
'awaitPromise': true, 'awaitPromise': true,
'returnByValue': true, 'returnByValue': true,
...@@ -523,12 +523,13 @@ class _ExperimentalResidentWebRunner extends ResidentWebRunner { ...@@ -523,12 +523,13 @@ class _ExperimentalResidentWebRunner extends ResidentWebRunner {
Completer<DebugConnectionInfo> connectionInfoCompleter, Completer<DebugConnectionInfo> connectionInfoCompleter,
Completer<void> appStartedCompleter, Completer<void> appStartedCompleter,
}) async { }) async {
if (device.device is ChromeDevice) {
final Chrome chrome = await ChromeLauncher.connectedInstance; final Chrome chrome = await ChromeLauncher.connectedInstance;
final ChromeTab chromeTab = final ChromeTab chromeTab = await chrome.chromeConnection.getTab((ChromeTab chromeTab) {
await chrome.chromeConnection.getTab((ChromeTab chromeTab) {
return chromeTab.url.contains(debuggingOptions.hostname); return chromeTab.url.contains(debuggingOptions.hostname);
}); });
_wipConnection = await chromeTab.connect(); _wipConnection = await chromeTab.connect();
}
appStartedCompleter?.complete(); appStartedCompleter?.complete();
connectionInfoCompleter?.complete(); connectionInfoCompleter?.complete();
if (stayResident) { if (stayResident) {
......
...@@ -49,6 +49,7 @@ void main() { ...@@ -49,6 +49,7 @@ void main() {
MockChromeTab mockChromeTab; MockChromeTab mockChromeTab;
MockWipConnection mockWipConnection; MockWipConnection mockWipConnection;
MockWipDebugger mockWipDebugger; MockWipDebugger mockWipDebugger;
MockWebServerDevice mockWebServerDevice;
bool didSkipDwds; bool didSkipDwds;
setUp(() { setUp(() {
...@@ -66,6 +67,7 @@ void main() { ...@@ -66,6 +67,7 @@ void main() {
mockChromeTab = MockChromeTab(); mockChromeTab = MockChromeTab();
mockWipConnection = MockWipConnection(); mockWipConnection = MockWipConnection();
mockWipDebugger = MockWipDebugger(); mockWipDebugger = MockWipDebugger();
mockWebServerDevice = MockWebServerDevice();
when(mockFlutterDevice.device).thenReturn(mockChromeDevice); when(mockFlutterDevice.device).thenReturn(mockChromeDevice);
testbed = Testbed( testbed = Testbed(
setup: () { setup: () {
...@@ -429,6 +431,49 @@ void main() { ...@@ -429,6 +431,49 @@ void main() {
FeatureFlags: () => TestFeatureFlags(isWebIncrementalCompilerEnabled: true), FeatureFlags: () => TestFeatureFlags(isWebIncrementalCompilerEnabled: true),
})); }));
test('Can hot restart after attaching - experimental with web-server device', () => testbed.run(() async {
_setupMocks();
when(mockFlutterDevice.device).thenReturn(mockWebServerDevice);
when(mockWebDevFS.update(
mainPath: anyNamed('mainPath'),
target: anyNamed('target'),
bundle: anyNamed('bundle'),
firstBuildTime: anyNamed('firstBuildTime'),
bundleFirstUpload: anyNamed('bundleFirstUpload'),
generator: anyNamed('generator'),
fullRestart: anyNamed('fullRestart'),
dillOutputPath: anyNamed('dillOutputPath'),
trackWidgetCreation: anyNamed('trackWidgetCreation'),
projectRootPath: anyNamed('projectRootPath'),
pathToReload: anyNamed('pathToReload'),
invalidatedFiles: anyNamed('invalidatedFiles'),
)).thenAnswer((Invocation invocation) async {
return UpdateFSReport(success: true)
..invalidatedModules = <String>['example'];
});
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
unawaited(residentWebRunner.run(
connectionInfoCompleter: connectionInfoCompleter,
));
await connectionInfoCompleter.future;
final OperationResult result = await residentWebRunner.restart(fullRestart: true);
expect(testLogger.statusText, contains('Restarted application in'));
expect(result.code, 0);
verify(mockResidentCompiler.accept()).called(2);
// ensure that analytics are sent.
verify(Usage.instance.sendEvent('hot', 'restart', parameters: <String, String>{
'cd27': 'web-javascript',
'cd28': null,
'cd29': 'false',
'cd30': 'true',
})).called(1);
verifyNever(Usage.instance.sendTiming('hot', 'web-incremental-restart', any));
}, overrides: <Type, Generator>{
Usage: () => MockFlutterUsage(),
FeatureFlags: () => TestFeatureFlags(isWebIncrementalCompilerEnabled: true),
}));
test('Can hot restart after attaching', () => testbed.run(() async { test('Can hot restart after attaching', () => testbed.run(() async {
_setupMocks(); _setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>(); final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
...@@ -460,6 +505,21 @@ void main() { ...@@ -460,6 +505,21 @@ void main() {
Usage: () => MockFlutterUsage(), Usage: () => MockFlutterUsage(),
})); }));
test('Selects Dwds runner in profile mode with incremental compiler enabled', () => testbed.run(() async {
final ResidentWebRunner residentWebRunner = DwdsWebRunnerFactory().createWebRunner(
mockFlutterDevice,
flutterProject: FlutterProject.current(),
debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile),
ipv6: true,
stayResident: true,
dartDefines: const <String>[],
) as ResidentWebRunner;
expect(residentWebRunner.runtimeType.toString(), '_DwdsResidentWebRunner');
}, overrides: <Type, Generator>{
FeatureFlags: () => TestFeatureFlags(isWebIncrementalCompilerEnabled: true),
}));
test('Fails on compilation errors in hot restart', () => testbed.run(() async { test('Fails on compilation errors in hot restart', () => testbed.run(() async {
_setupMocks(); _setupMocks();
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>(); final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
...@@ -1022,3 +1082,4 @@ class MockChromeTab extends Mock implements ChromeTab {} ...@@ -1022,3 +1082,4 @@ class MockChromeTab extends Mock implements ChromeTab {}
class MockWipConnection extends Mock implements WipConnection {} class MockWipConnection extends Mock implements WipConnection {}
class MockWipDebugger extends Mock implements WipDebugger {} class MockWipDebugger extends Mock implements WipDebugger {}
class MockLogger extends Mock implements Logger {} class MockLogger extends Mock implements Logger {}
class MockWebServerDevice extends Mock implements WebServerDevice {}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment