mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add a hot reload test that modifies code and verifies it executes (#23725)
This commit is contained in:
parent
06cc1d9ec0
commit
a2c9dd8180
@ -2,19 +2,21 @@
|
||||
// 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:file/file.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:vm_service_client/vm_service_client.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import 'test_data/basic_project.dart';
|
||||
import 'test_data/hot_reload_project.dart';
|
||||
import 'test_driver.dart';
|
||||
import 'test_utils.dart';
|
||||
|
||||
void main() {
|
||||
group('hot', () {
|
||||
Directory tempDir;
|
||||
final BasicProject _project = BasicProject();
|
||||
final HotReloadProject _project = HotReloadProject();
|
||||
FlutterTestDriver _flutter;
|
||||
|
||||
setUp(() async {
|
||||
@ -33,6 +35,19 @@ void main() {
|
||||
await _flutter.hotReload();
|
||||
});
|
||||
|
||||
test('newly added code executes during reload', () async {
|
||||
await _flutter.run();
|
||||
_project.uncommentHotReloadPrint();
|
||||
final StringBuffer stdout = StringBuffer();
|
||||
final StreamSubscription<String> sub = _flutter.stdout.listen(stdout.writeln);
|
||||
try {
|
||||
await _flutter.hotReload();
|
||||
expect(stdout.toString(), contains('(((((RELOAD WORKED)))))'));
|
||||
} finally {
|
||||
await sub.cancel();
|
||||
}
|
||||
});
|
||||
|
||||
test('restart works without error', () async {
|
||||
await _flutter.run();
|
||||
await _flutter.hotRestart();
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
// Copyright 2018 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
|
||||
import '../test_utils.dart';
|
||||
import 'test_project.dart';
|
||||
|
||||
class HotReloadProject extends TestProject {
|
||||
@override
|
||||
final String pubspec = '''
|
||||
name: test
|
||||
environment:
|
||||
sdk: ">=2.0.0-dev.68.0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
''';
|
||||
|
||||
@override
|
||||
final String main = r'''
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
void main() => runApp(new MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Do not remove this line, it's uncommented by a test to verify that hot
|
||||
// reloading worked.
|
||||
// printHotReloadWorked();
|
||||
|
||||
return new MaterialApp( // BREAKPOINT
|
||||
title: 'Flutter Demo',
|
||||
home: new Container(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
printHotReloadWorked() {
|
||||
// The call to this function is uncommented by a test to verify that hot
|
||||
// reloading worked.
|
||||
print('(((((RELOAD WORKED)))))');
|
||||
}
|
||||
''';
|
||||
|
||||
void uncommentHotReloadPrint() {
|
||||
final String newMainContents = main.replaceAll(
|
||||
'// printHotReloadWorked();', 'printHotReloadWorked();');
|
||||
writeFile(fs.path.join(dir.path, 'lib', 'main.dart'), newMainContents);
|
||||
}
|
||||
}
|
||||
@ -42,6 +42,7 @@ class FlutterTestDriver {
|
||||
|
||||
VMServiceClient vmService;
|
||||
String get lastErrorInfo => _errorBuffer.toString();
|
||||
Stream<String> get stdout => _stdout.stream;
|
||||
int get vmServicePort => _vmServicePort;
|
||||
bool get hasExited => _hasExited;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user