Adding a setup function for hot restart (#18921)

* Adding a setup function for hot restart that can be overwritten to perform any necessary initialization before a restart is started.

* Adding a test for setupHotRestart

* Removing local pubspec change

* Fixing some type annotation errors

* Responding to comments
This commit is contained in:
abykov2
2018-07-06 15:18:57 -07:00
committed by Alexander Aprelev
parent d5d129803a
commit e5d9feb59d
2 changed files with 60 additions and 0 deletions

View File

@@ -2,7 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/resident_runner.dart';
import 'package:flutter_tools/src/run_hot.dart';
import 'package:meta/meta.dart';
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
import 'src/context.dart';
@@ -83,4 +89,49 @@ void main() {
}), true);
});
});
group('hotRestart', () {
final List<FlutterDevice> devices = <FlutterDevice>[];
setUp(() {
devices.add(new FlutterDevice(new MockDevice(),
previewDart2: false, trackWidgetCreation: false));
});
testUsingContext('no setup', () async {
expect((await new HotRunner(devices).restart(fullRestart: true)).isOk,
true);
});
testUsingContext('setup function succeeds', () async {
expect((await new HotRunner(devices).restart(fullRestart: true)).isOk,
true);
}, overrides: <Type, Generator>{
HotRunnerConfig: () => new TestHotRunnerConfig(successfulSetup: true),
});
testUsingContext('setup function fails', () async {
expect((await new HotRunner(devices).restart(fullRestart: true)).isOk,
false);
}, overrides: <Type, Generator>{
HotRunnerConfig: () => new TestHotRunnerConfig(successfulSetup: false),
});
});
}
class MockDevice extends Mock implements Device {
MockDevice() {
when(isSupported()).thenReturn(true);
}
}
class TestHotRunnerConfig extends HotRunnerConfig {
bool successfulSetup;
TestHotRunnerConfig({@required this.successfulSetup});
@override
Future<bool> setupHotRestart() async {
return successfulSetup;
}
}